1 #ifndef TrackingTools_TrajectoryCleaning_src_OtherHashMaps 2 #define TrackingTools_TrajectoryCleaning_src_OtherHashMaps 10 #include <type_traits> 26 typename Hasher = std::hash<K>,
27 typename Equals = std::equal_to<K>,
28 typename Alloc = std::allocator<V> >
31 static_assert(std::conjunction<std::is_trivially_destructible<K>, std::is_trivially_destructible<V> >::
value);
43 void clear(
size_t newBucketSize = 0) {
44 if (newBucketSize != 0) {
85 template <
typename Item>
106 bool good()
const {
return (
it_ !=
nullptr); }
127 typename std::list<KeyItem *>::iterator
133 typename std::list<ValueItem *>::iterator
150 std::cout <<
"Dumping HASH MULTIMAP" << std::endl;
161 std::cout <<
" [" << row <<
"] " << *
p << std::endl;
170 std::cout <<
" @ " <<
p <<
" [" <<
p->key <<
", @" <<
p->value <<
"], next = " <<
p->next << std::endl;
172 std::cout <<
" ^^^ this was the last valid item." << std::endl;
181 std::cout <<
" Value Items " << std::endl;
187 std::cout <<
" @ " <<
p <<
" [" <<
p->value <<
"], next = " <<
p->next << std::endl;
189 std::cout <<
" ^^^ this was the last valid item." << std::endl;
197 std::cout <<
" End of dump" << std::endl;
201 template <
typename K,
typename V,
typename Hasher,
typename Equals,
typename Alloc>
206 : bucketSize_(buckets),
207 bucketCapacity_(bucketSize_),
208 keyRowSize_(keyRowSize),
209 valueRowSize_(valueRowSize),
216 template <
typename K,
typename V,
typename Hasher,
typename Equals,
typename Alloc>
218 for (
typename std::list<KeyItem *>::iterator
it = keyRows_.begin(),
last = keyRows_.end();
it !=
last; ++
it) {
219 keyAlloc_.deallocate(*
it, keyRowSize_);
221 for (
typename std::list<ValueItem *>::iterator
it = valueRows_.begin(),
last = valueRows_.end();
it !=
last; ++
it) {
222 valueAlloc_.deallocate(*
it, valueRowSize_);
224 ptrAlloc_.deallocate(buckets_, bucketCapacity_);
227 template <
typename K,
typename V,
typename Hasher,
typename Equals,
typename Alloc>
229 if (keyRows_.size() > maxRows_) {
231 typename std::list<KeyItem *>::iterator
it = keyRows_.begin(),
last = keyRows_.end();
232 for (std::advance(
it, maxRows_);
it !=
last; ++
it) {
233 keyAlloc_.deallocate(*
it, keyRowSize_);
235 keyRows_.resize(maxRows_);
237 if (valueRows_.size() > maxRows_) {
239 typename std::list<ValueItem *>::iterator
it = valueRows_.begin(),
last = valueRows_.end();
240 for (std::advance(
it, maxRows_);
it !=
last; ++
it) {
241 valueAlloc_.deallocate(*
it, valueRowSize_);
243 valueRows_.resize(maxRows_);
247 template <
typename K,
typename V,
typename Hasher,
typename Equals,
typename Alloc>
250 if (nextKeyItem_ == keyEndMarker_) {
252 if (currentKeyRow_ == keyRows_.end()) {
253 keyRows_.push_back(keyAlloc_.allocate(keyRowSize_));
254 currentKeyRow_ = keyRows_.end();
257 nextKeyItem_ = *currentKeyRow_;
258 keyEndMarker_ = nextKeyItem_ + keyRowSize_;
262 return (nextKeyItem_ - 1);
264 template <
typename K,
typename V,
typename Hasher,
typename Equals,
typename Alloc>
267 if (nextValueItem_ == valueEndMarker_) {
269 if (currentValueRow_ == valueRows_.end()) {
270 valueRows_.push_back(valueAlloc_.allocate(valueRowSize_));
271 currentValueRow_ = valueRows_.end();
274 nextValueItem_ = *currentValueRow_;
275 valueEndMarker_ = nextValueItem_ + valueRowSize_;
279 return (nextValueItem_ - 1);
282 template <
typename K,
typename V,
typename Hasher,
typename Equals,
typename Alloc>
290 if (eq_(curr->
key,
key)) {
296 buck = push_back_(
key, buck);
300 template <
typename K,
typename V,
typename Hasher,
typename Equals,
typename Alloc>
305 k.value = push_back_(
value,
k.value);
308 template <
typename K,
typename V,
typename Hasher,
typename Equals,
typename Alloc>
313 for (
KeyItem *curr = buckets_[
hash % bucketSize_]; curr; curr = curr->
next) {
314 if (eq_(curr->key,
key))
325 template <
typename K,
typename V>
330 typedef typename std::vector<value_type>::iterator
iterator;
340 for (
typename std::vector<value_type>::iterator
it =
data_.begin(), ed =
data_.end();
it != ed; ++
it) {
345 return data_.back().second;
~SimpleAllocHashMultiMap()
ValueItem * valueEndMarker_
ValueItem * nextValueItem_
typename AllocTraits::template rebind_alloc< KeyItem > KeyItemAllocator
item_iterator< ValueItem > value_iterator
std::conditional< std::is_pointer< V >::value, V, V const & >::type value_ref
std::list< ValueItem * > valueRows_
std::pair< K, V > value_type
std::allocator_traits< Alloc > AllocTraits
KeyItem & find_or_insert_(K const &key)
const_iterator end() const
const value_type & operator*() const
KeyItemPtrAllocator ptrAlloc_
const Item::value_type value_type
const value_type * pointer
Container::value_type value_type
uint32_t T const *__restrict__ uint32_t const *__restrict__ int32_t int Histo::index_type cudaStream_t V
bool operator!=(const self_type &other) const
SimpleAllocHashMultiMap< K, V, Hasher, Equals, Alloc > map_type
typename AllocTraits::template rebind_alloc< KeyItem * > KeyItemPtrAllocator
::std::forward_iterator_tag iterator_category
const value_type & reference
std::list< ValueItem * >::iterator currentValueRow_
KeyItem * push_back_(K const &key, KeyItem *next)
ValueItem(ValueItem *next1, value_ref val)
key
prepare the HTCondor submission files and eventually submit them
def template(fileName, svg, replaceme="REPLACEME")
bool operator==(const self_type &other) const
void insert(K const &key, value_ref value)
const value_type & operator()() const
V & operator[](const K &k)
value_iterator values(K const &key)
std::vector< value_type >::const_iterator const_iterator
ValueItemAllocator valueAlloc_
std::vector< value_type > data_
std::vector< value_type >::iterator iterator
const value_type * operator->() const
KeyItemAllocator keyAlloc_
const value_type & operator()() const
item_iterator< Item > self_type
const_iterator begin() const
void clear(size_t newBucketSize=0)
item_iterator(const Item *it)
std::unique_ptr< GeometricDet > construct(DDCompactView const &cpv, std::vector< int > const &detidShifts)
std::list< KeyItem * > keyRows_
ptrdiff_t difference_type
KeyItem(KeyItem *next1, K const &key1, ValueItem *val1)
SimpleAllocHashMultiMap(size_t buckets, size_t keyRowSize, size_t valueRowSize, size_t maxRows=50)
typename AllocTraits::template rebind_alloc< ValueItem > ValueItemAllocator
std::list< KeyItem * >::iterator currentKeyRow_