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); }
126 typename std::list<KeyItem *>::iterator
132 typename std::list<ValueItem *>::iterator
149 std::cout <<
"Dumping HASH MULTIMAP" << std::endl;
160 std::cout <<
" [" << row <<
"] " << *
p << std::endl;
167 std::cout <<
" Key Row " << row <<
" (of size " << keyRowSize_ <<
")" << std::endl;
169 std::cout <<
" @ " <<
p <<
" [" <<
p->key <<
", @" <<
p->value <<
"], next = " <<
p->next << std::endl;
171 std::cout <<
" ^^^ this was the last valid item." << std::endl;
180 std::cout <<
" Value Items " << std::endl;
184 std::cout <<
" Value Row " << row <<
" (of size " << valueRowSize_ <<
")" << std::endl;
186 std::cout <<
" @ " <<
p <<
" [" <<
p->value <<
"], next = " <<
p->next << std::endl;
188 std::cout <<
" ^^^ this was the last valid item." << std::endl;
196 std::cout <<
" End of dump" << std::endl;
200 template <
typename K,
typename V,
typename Hasher,
typename Equals,
typename Alloc>
205 : bucketSize_(buckets),
206 bucketCapacity_(bucketSize_),
207 keyRowSize_(keyRowSize),
208 valueRowSize_(valueRowSize),
215 template <
typename K,
typename V,
typename Hasher,
typename Equals,
typename Alloc>
217 for (
typename std::list<KeyItem *>::iterator it = keyRows_.begin(),
last = keyRows_.end(); it !=
last; ++it) {
218 keyAlloc_.deallocate(*it, keyRowSize_);
220 for (
typename std::list<ValueItem *>::iterator it = valueRows_.begin(),
last = valueRows_.end(); it !=
last; ++it) {
221 valueAlloc_.deallocate(*it, valueRowSize_);
223 ptrAlloc_.deallocate(buckets_, bucketCapacity_);
226 template <
typename K,
typename V,
typename Hasher,
typename Equals,
typename Alloc>
228 if (keyRows_.size() > maxRows_) {
230 typename std::list<KeyItem *>::iterator it = keyRows_.begin(),
last = keyRows_.end();
231 for (std::advance(it, maxRows_); it !=
last; ++it) {
232 keyAlloc_.deallocate(*it, keyRowSize_);
234 keyRows_.resize(maxRows_);
236 if (valueRows_.size() > maxRows_) {
238 typename std::list<ValueItem *>::iterator it = valueRows_.begin(),
last = valueRows_.end();
239 for (std::advance(it, maxRows_); it !=
last; ++it) {
240 valueAlloc_.deallocate(*it, valueRowSize_);
242 valueRows_.resize(maxRows_);
246 template <
typename K,
typename V,
typename Hasher,
typename Equals,
typename Alloc>
249 if (nextKeyItem_ == keyEndMarker_) {
251 if (currentKeyRow_ == keyRows_.end()) {
252 keyRows_.push_back(keyAlloc_.allocate(keyRowSize_));
253 currentKeyRow_ = keyRows_.end();
256 nextKeyItem_ = *currentKeyRow_;
257 keyEndMarker_ = nextKeyItem_ + keyRowSize_;
259 keyAlloc_.construct(nextKeyItem_,
KeyItem(next, key,
nullptr));
261 return (nextKeyItem_ - 1);
263 template <
typename K,
typename V,
typename Hasher,
typename Equals,
typename Alloc>
266 if (nextValueItem_ == valueEndMarker_) {
268 if (currentValueRow_ == valueRows_.end()) {
269 valueRows_.push_back(valueAlloc_.allocate(valueRowSize_));
270 currentValueRow_ = valueRows_.end();
273 nextValueItem_ = *currentValueRow_;
274 valueEndMarker_ = nextValueItem_ + valueRowSize_;
276 valueAlloc_.construct(nextValueItem_,
ValueItem(next, value));
278 return (nextValueItem_ - 1);
281 template <
typename K,
typename V,
typename Hasher,
typename Equals,
typename Alloc>
285 size_t hash = hasher_(key);
286 KeyItem *&buck = buckets_[hash % bucketSize_];
289 if (eq_(curr->
key, key)) {
295 buck = push_back_(key, buck);
299 template <
typename K,
typename V,
typename Hasher,
typename Equals,
typename Alloc>
307 template <
typename K,
typename V,
typename Hasher,
typename Equals,
typename Alloc>
311 size_t hash = hasher_(key);
312 for (
KeyItem *curr = buckets_[hash % bucketSize_]; curr; curr = curr->
next) {
313 if (eq_(curr->key, key))
324 template <
typename K,
typename V>
329 typedef typename std::vector<value_type>::iterator
iterator;
339 for (
typename std::vector<value_type>::iterator it =
data_.begin(), ed =
data_.end(); it != ed; ++it) {
344 return data_.back().second;
~SimpleAllocHashMultiMap()
ValueItem * valueEndMarker_
ValueItem * nextValueItem_
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
KeyItem & find_or_insert_(K const &key)
const_iterator begin() const
KeyItemPtrAllocator ptrAlloc_
const_iterator end() const
const Item::value_type value_type
Alloc::template rebind< KeyItem >::other KeyItemAllocator
bool operator!=(const self_type &other) const
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
SimpleAllocHashMultiMap< K, V, Hasher, Equals, Alloc > map_type
::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)
tuple key
prepare the HTCondor submission files and eventually submit them
void insert(K const &key, value_ref value)
V & operator[](const K &k)
value_iterator values(K const &key)
Alloc::template rebind< ValueItem >::other ValueItemAllocator
std::vector< value_type >::const_iterator const_iterator
ValueItemAllocator valueAlloc_
const value_type & operator()() const
const value_type & operator()() const
std::vector< value_type > data_
std::vector< value_type >::iterator iterator
KeyItemAllocator keyAlloc_
const value_type & operator*() const
item_iterator< Item > self_type
Alloc::template rebind< KeyItem * >::other KeyItemPtrAllocator
bool operator==(const self_type &other) const
void clear(size_t newBucketSize=0)
item_iterator(const Item *it)
std::list< KeyItem * > keyRows_
const value_type * operator->() const
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)
std::list< KeyItem * >::iterator currentKeyRow_