14 #ifndef STXXL_CONTAINERS_HASH_MAP_ITERATOR_MAP_HEADER
15 #define STXXL_CONTAINERS_HASH_MAP_ITERATOR_MAP_HEADER
27 template <
class HashMap>
28 class iterator_map :
private noncopyable
32 typedef typename hash_map_type::node_type
node_type;
34 typedef typename hash_map_type::key_type
key_type;
43 typedef std::multimap<internal_size_type, iterator_base*>
multimap_type;
64 typedef typename compat_hash_multimap<
70 typedef typename multimap_type::value_type
pair_type;
89 register_iterator(it, it.i_bucket_);
94 STXXL_VERBOSE2(
"hash_map::iterator_map register_iterator addr=" << &it <<
" bucket=" << i_bucket);
100 unregister_iterator(it, it.i_bucket_);
105 STXXL_VERBOSE2(
"hash_map::iterator_map unregister_iterator addr=" << &it <<
" bucket=" << i_bucket);
107 std::pair<mmiterator_type, mmiterator_type> range
108 = it_map_.equal_range(i_bucket);
110 assert(range.first != range.second);
114 if (i->second == &it)
121 throw std::runtime_error(
"unregister_iterator Panic in hash_map::iterator_map, can not find and unregister iterator");
130 STXXL_VERBOSE2(
"hash_map::iterator_map fix_iterators_2ext i_bucket=" << i_bucket_old <<
" new_i_ext=" << i_ext);
132 std::vector<iterator_base*> its2fix;
133 _find(i_bucket_old, its2fix);
135 for (
typename std::vector<iterator_base*>::iterator
136 it2fix = its2fix.begin(); it2fix != its2fix.end(); ++it2fix)
138 if (!map_->_eq(key, (**it2fix).key_))
141 if (i_bucket_old != i_bucket_new)
143 unregister_iterator(**it2fix);
144 register_iterator(**it2fix, i_bucket_new);
147 (**it2fix).i_bucket_ = i_bucket_new;
148 (**it2fix).node_ = NULL;
149 (**it2fix).i_external_ = i_ext;
150 (**it2fix).source_ = hash_map_type::src_external;
152 (**it2fix).ext_valid_ =
true;
153 (**it2fix).reset_reader();
154 (**it2fix).reader_ = NULL;
162 STXXL_VERBOSE2(
"hash_map::iterator_map fix_iterators_2int i_bucket=" << i_bucket <<
" node=" << node);
164 std::vector<iterator_base*> its2fix;
165 _find(i_bucket, its2fix);
167 for (
typename std::vector<iterator_base*>::iterator
168 it2fix = its2fix.begin(); it2fix != its2fix.end(); ++it2fix)
170 if (!map_->_eq((**it2fix).key_, key))
173 assert((**it2fix).source_ == hash_map_type::src_external);
175 (**it2fix).source_ = hash_map_type::src_internal;
176 (**it2fix).node_ = node;
177 (**it2fix).i_external_++;
178 if ((** it2fix).reader_)
179 (** it2fix).reader_->operator ++ ();
187 STXXL_VERBOSE2(
"hash_map::iterator_map fix_iterators_2end i_bucket=" << i_bucket);
189 std::vector<iterator_base*> its2fix;
190 _find(i_bucket, its2fix);
192 for (
typename std::vector<iterator_base*>::iterator
193 it2fix = its2fix.begin(); it2fix != its2fix.end(); ++it2fix)
195 if (!map_->_eq(key, (**it2fix).key_))
198 (**it2fix).end_ =
true;
199 (**it2fix).reset_reader();
200 unregister_iterator(**it2fix);
209 it2fix != it_map_.end(); ++it2fix)
211 (*it2fix).second->end_ =
true;
212 (*it2fix).second->reset_reader();
219 template <
class OutputContainer>
222 std::pair<mmiterator_type, mmiterator_type> range
223 = it_map_.equal_range(i_bucket);
226 outc.push_back((*i).second);
233 ((*it).second)->map_ = map;
239 std::swap(it_map_, obj.it_map_);
240 std::swap(map_, obj.map_);
242 change_hash_map_pointers(map_);
243 obj.change_hash_map_pointers(obj.map_);
248 o <<
"Registered iterators: " << it_map_.size() <<
"\n";
252 o <<
" Address=" << i->second
253 <<
", Bucket=" << i->second->i_bucket_
254 <<
", Node=" << i->second->node_
255 <<
", i_ext=" << i->second->i_external_
257 << ((i->second->source_ == hash_map_type::src_external)
258 ?
"external" :
"internal") << std::endl;
269 template <
class HashMapType>
279 #endif // !STXXL_CONTAINERS_HASH_MAP_ITERATOR_MAP_HEADER
multimap_type::iterator mmiterator_type
multimap_type::value_type pair_type
void fix_iterators_all2end()
Update all iterators and make them point to the end of the hash-map (used by clear()) ...
void print_statistics(std::ostream &o=std::cout) const
size_t longhash1(uint64 key_)
multimap_type::const_iterator const_mmiterator_type
compat_hash_multimap< internal_size_type, iterator_base *, hasher >::result multimap_type
hash_map_iterator_base< hash_map_type > iterator_base
void fix_iterators_2ext(internal_size_type i_bucket_old, const key_type &key, internal_size_type i_bucket_new, external_size_type i_ext)
Update iterators with given key and bucket and make them point to the specified location in external ...
#define STXXL_VERBOSE2(x)
iterator_map(hash_map_type *map)
void fix_iterators_2int(internal_size_type i_bucket, const key_type &key, node_type *node)
Update iterators with given key and bucket and make them point to the specified node in internal memo...
hash_map_type::external_size_type external_size_type
void _find(internal_size_type i_bucket, OutputContainer &outc)
Find all iterators registered with given bucket and add them to outc.
void change_hash_map_pointers(hash_map_type *map)
unsigned_type internal_size_type
multimap_type::iterator mmiterator_type
void unregister_iterator(iterator_base &it, internal_size_type i_bucket)
#define STXXL_BEGIN_NAMESPACE
void register_iterator(iterator_base &it)
std::multimap< Key, iterator_base *, KeyCmp > multimap_type
void unregister_iterator(iterator_base &it)
void swap(iterator_map< HashMap > &obj)
hash_map_type::internal_size_type internal_size_type
uint64 external_size_type
void register_iterator(iterator_base &it, internal_size_type i_bucket)
External associative container (map). Introduction to map container: see STXXL Map (B+-tree) tutor...
multimap_type::value_type pair_type
bucket-index and pointer to iterator_base
hash_map_type::key_type key_type
hash_map_type::node_type node_type
hash_map_type::source_type source_type
#define STXXL_END_NAMESPACE
void fix_iterators_2end(internal_size_type i_bucket, const key_type &key)
Update iterators with given key and bucket and make them point to the end of the hash-map (called by ...