HashMap.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804
  1. //
  2. // Copyright (c) 2008-2017 the Urho3D project.
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #pragma once
  23. #include "../Container/HashBase.h"
  24. #include "../Container/Pair.h"
  25. #include "../Container/Sort.h"
  26. #include "../Container/Vector.h"
  27. #include <cassert>
  28. #if ATOMIC_CXX11
  29. #include <initializer_list>
  30. #endif
  31. namespace Atomic
  32. {
  33. /// Hash map template class.
  34. template <class T, class U> class HashMap : public HashBase
  35. {
  36. public:
  37. typedef T KeyType;
  38. typedef U ValueType;
  39. /// Hash map key-value pair with const key.
  40. class KeyValue
  41. {
  42. public:
  43. /// Construct with default key.
  44. KeyValue() :
  45. first_(T())
  46. {
  47. }
  48. /// Construct with key and value.
  49. KeyValue(const T& first, const U& second) :
  50. first_(first),
  51. second_(second)
  52. {
  53. }
  54. /// Copy-construct.
  55. KeyValue(const KeyValue& value) :
  56. first_(value.first_),
  57. second_(value.second_)
  58. {
  59. }
  60. /// Test for equality with another pair.
  61. bool operator ==(const KeyValue& rhs) const { return first_ == rhs.first_ && second_ == rhs.second_; }
  62. /// Test for inequality with another pair.
  63. bool operator !=(const KeyValue& rhs) const { return first_ != rhs.first_ || second_ != rhs.second_; }
  64. /// Key.
  65. const T first_;
  66. /// Value.
  67. U second_;
  68. private:
  69. /// Prevent assignment.
  70. KeyValue& operator =(const KeyValue& rhs);
  71. };
  72. /// Hash map node.
  73. struct Node : public HashNodeBase
  74. {
  75. /// Construct undefined.
  76. Node()
  77. {
  78. }
  79. /// Construct with key and value.
  80. Node(const T& key, const U& value) :
  81. pair_(key, value)
  82. {
  83. }
  84. /// Key-value pair.
  85. KeyValue pair_;
  86. /// Return next node.
  87. Node* Next() const { return static_cast<Node*>(next_); }
  88. /// Return previous node.
  89. Node* Prev() const { return static_cast<Node*>(prev_); }
  90. /// Return next node in the bucket.
  91. Node* Down() const { return static_cast<Node*>(down_); }
  92. };
  93. /// Hash map node iterator.
  94. struct Iterator : public HashIteratorBase
  95. {
  96. /// Construct.
  97. Iterator()
  98. {
  99. }
  100. /// Construct with a node pointer.
  101. Iterator(Node* ptr) :
  102. HashIteratorBase(ptr)
  103. {
  104. }
  105. /// Preincrement the pointer.
  106. Iterator& operator ++()
  107. {
  108. GotoNext();
  109. return *this;
  110. }
  111. /// Postincrement the pointer.
  112. Iterator operator ++(int)
  113. {
  114. Iterator it = *this;
  115. GotoNext();
  116. return it;
  117. }
  118. /// Predecrement the pointer.
  119. Iterator& operator --()
  120. {
  121. GotoPrev();
  122. return *this;
  123. }
  124. /// Postdecrement the pointer.
  125. Iterator operator --(int)
  126. {
  127. Iterator it = *this;
  128. GotoPrev();
  129. return it;
  130. }
  131. /// Point to the pair.
  132. KeyValue* operator ->() const { return &(static_cast<Node*>(ptr_))->pair_; }
  133. /// Dereference the pair.
  134. KeyValue& operator *() const { return (static_cast<Node*>(ptr_))->pair_; }
  135. };
  136. /// Hash map node const iterator.
  137. struct ConstIterator : public HashIteratorBase
  138. {
  139. /// Construct.
  140. ConstIterator()
  141. {
  142. }
  143. /// Construct with a node pointer.
  144. ConstIterator(Node* ptr) :
  145. HashIteratorBase(ptr)
  146. {
  147. }
  148. /// Construct from a non-const iterator.
  149. ConstIterator(const Iterator& rhs) :
  150. HashIteratorBase(rhs.ptr_)
  151. {
  152. }
  153. /// Assign from a non-const iterator.
  154. ConstIterator& operator =(const Iterator& rhs)
  155. {
  156. ptr_ = rhs.ptr_;
  157. return *this;
  158. }
  159. /// Preincrement the pointer.
  160. ConstIterator& operator ++()
  161. {
  162. GotoNext();
  163. return *this;
  164. }
  165. /// Postincrement the pointer.
  166. ConstIterator operator ++(int)
  167. {
  168. ConstIterator it = *this;
  169. GotoNext();
  170. return it;
  171. }
  172. /// Predecrement the pointer.
  173. ConstIterator& operator --()
  174. {
  175. GotoPrev();
  176. return *this;
  177. }
  178. /// Postdecrement the pointer.
  179. ConstIterator operator --(int)
  180. {
  181. ConstIterator it = *this;
  182. GotoPrev();
  183. return it;
  184. }
  185. /// Point to the pair.
  186. const KeyValue* operator ->() const { return &(static_cast<Node*>(ptr_))->pair_; }
  187. /// Dereference the pair.
  188. const KeyValue& operator *() const { return (static_cast<Node*>(ptr_))->pair_; }
  189. };
  190. /// Construct empty.
  191. HashMap()
  192. {
  193. // Reserve the tail node
  194. allocator_ = AllocatorInitialize((unsigned)sizeof(Node));
  195. head_ = tail_ = ReserveNode();
  196. }
  197. /// Construct from another hash map.
  198. HashMap(const HashMap<T, U>& map)
  199. {
  200. // Reserve the tail node + initial capacity according to the map's size
  201. allocator_ = AllocatorInitialize((unsigned)sizeof(Node), map.Size() + 1);
  202. head_ = tail_ = ReserveNode();
  203. *this = map;
  204. }
  205. #if ATOMIC_CXX11
  206. /// Aggregate initialization constructor.
  207. HashMap(const std::initializer_list<Pair<T, U>>& list) : HashMap()
  208. {
  209. for (auto it = list.begin(); it != list.end(); it++)
  210. {
  211. Insert(*it);
  212. }
  213. }
  214. #endif
  215. /// Destruct.
  216. ~HashMap()
  217. {
  218. Clear();
  219. FreeNode(Tail());
  220. AllocatorUninitialize(allocator_);
  221. delete[] ptrs_;
  222. }
  223. /// Assign a hash map.
  224. HashMap& operator =(const HashMap<T, U>& rhs)
  225. {
  226. // In case of self-assignment do nothing
  227. if (&rhs != this)
  228. {
  229. Clear();
  230. Insert(rhs);
  231. }
  232. return *this;
  233. }
  234. /// Add-assign a pair.
  235. HashMap& operator +=(const Pair<T, U>& rhs)
  236. {
  237. Insert(rhs);
  238. return *this;
  239. }
  240. /// Add-assign a hash map.
  241. HashMap& operator +=(const HashMap<T, U>& rhs)
  242. {
  243. Insert(rhs);
  244. return *this;
  245. }
  246. /// Test for equality with another hash map.
  247. bool operator ==(const HashMap<T, U>& rhs) const
  248. {
  249. if (rhs.Size() != Size())
  250. return false;
  251. ConstIterator i = Begin();
  252. while (i != End())
  253. {
  254. ConstIterator j = rhs.Find(i->first_);
  255. if (j == rhs.End() || j->second_ != i->second_)
  256. return false;
  257. ++i;
  258. }
  259. return true;
  260. }
  261. /// Test for inequality with another hash map.
  262. bool operator !=(const HashMap<T, U>& rhs) const
  263. {
  264. if (rhs.Size() != Size())
  265. return true;
  266. ConstIterator i = Begin();
  267. while (i != End())
  268. {
  269. ConstIterator j = rhs.Find(i->first_);
  270. if (j == rhs.End() || j->second_ != i->second_)
  271. return true;
  272. ++i;
  273. }
  274. return false;
  275. }
  276. /// Index the map. Create a new pair if key not found.
  277. U& operator [](const T& key)
  278. {
  279. if (!ptrs_)
  280. return InsertNode(key, U(), false)->pair_.second_;
  281. unsigned hashKey = Hash(key);
  282. Node* node = FindNode(key, hashKey);
  283. return node ? node->pair_.second_ : InsertNode(key, U(), false)->pair_.second_;
  284. }
  285. /// Index the map. Return null if key is not found, does not create a new pair.
  286. U* operator [](const T& key) const
  287. {
  288. if (!ptrs_)
  289. return 0;
  290. unsigned hashKey = Hash(key);
  291. Node* node = FindNode(key, hashKey);
  292. return node ? &node->pair_.second_ : 0;
  293. }
  294. #if ATOMIC_CXX11
  295. /// Populate the map using variadic template. This handles the base case.
  296. HashMap& Populate(const T& key, const U& value)
  297. {
  298. this->operator [](key) = value;
  299. return *this;
  300. };
  301. /// Populate the map using variadic template.
  302. template <typename... Args> HashMap& Populate(const T& key, const U& value, Args... args)
  303. {
  304. this->operator [](key) = value;
  305. return Populate(args...);
  306. };
  307. #endif
  308. /// Insert a pair. Return an iterator to it.
  309. Iterator Insert(const Pair<T, U>& pair)
  310. {
  311. return Iterator(InsertNode(pair.first_, pair.second_));
  312. }
  313. /// Insert a pair. Return iterator and set exists flag according to whether the key already existed.
  314. Iterator Insert(const Pair<T, U>& pair, bool& exists)
  315. {
  316. unsigned oldSize = Size();
  317. Iterator ret(InsertNode(pair.first_, pair.second_));
  318. exists = (Size() == oldSize);
  319. return ret;
  320. }
  321. /// Insert a map.
  322. void Insert(const HashMap<T, U>& map)
  323. {
  324. ConstIterator it = map.Begin();
  325. ConstIterator end = map.End();
  326. while (it != end)
  327. {
  328. InsertNode(it->first_, it->second_);
  329. ++it;
  330. }
  331. }
  332. /// Insert a pair by iterator. Return iterator to the value.
  333. Iterator Insert(const ConstIterator& it) { return Iterator(InsertNode(it->first_, it->second_)); }
  334. /// Insert a range by iterators.
  335. void Insert(const ConstIterator& start, const ConstIterator& end)
  336. {
  337. ConstIterator it = start;
  338. while (it != end)
  339. InsertNode(*it++);
  340. }
  341. /// Erase a pair by key. Return true if was found.
  342. bool Erase(const T& key)
  343. {
  344. if (!ptrs_)
  345. return false;
  346. unsigned hashKey = Hash(key);
  347. Node* previous;
  348. Node* node = FindNode(key, hashKey, previous);
  349. if (!node)
  350. return false;
  351. if (previous)
  352. previous->down_ = node->down_;
  353. else
  354. Ptrs()[hashKey] = node->down_;
  355. EraseNode(node);
  356. return true;
  357. }
  358. /// Erase a pair by iterator. Return iterator to the next pair.
  359. Iterator Erase(const Iterator& it)
  360. {
  361. if (!ptrs_ || !it.ptr_)
  362. return End();
  363. Node* node = static_cast<Node*>(it.ptr_);
  364. Node* next = node->Next();
  365. unsigned hashKey = Hash(node->pair_.first_);
  366. Node* previous = 0;
  367. Node* current = static_cast<Node*>(Ptrs()[hashKey]);
  368. while (current && current != node)
  369. {
  370. previous = current;
  371. current = current->Down();
  372. }
  373. assert(current == node);
  374. if (previous)
  375. previous->down_ = node->down_;
  376. else
  377. Ptrs()[hashKey] = node->down_;
  378. EraseNode(node);
  379. return Iterator(next);
  380. }
  381. /// Clear the map.
  382. void Clear()
  383. {
  384. // Prevent Find() from returning anything while the map is being cleared
  385. ResetPtrs();
  386. if (Size())
  387. {
  388. for (Iterator i = Begin(); i != End();)
  389. {
  390. FreeNode(static_cast<Node*>(i++.ptr_));
  391. i.ptr_->prev_ = 0;
  392. }
  393. head_ = tail_;
  394. SetSize(0);
  395. }
  396. }
  397. /// Sort pairs. After sorting the map can be iterated in order until new elements are inserted.
  398. void Sort()
  399. {
  400. unsigned numKeys = Size();
  401. if (!numKeys)
  402. return;
  403. Node** ptrs = new Node* [numKeys];
  404. Node* ptr = Head();
  405. for (unsigned i = 0; i < numKeys; ++i)
  406. {
  407. ptrs[i] = ptr;
  408. ptr = ptr->Next();
  409. }
  410. Atomic::Sort(RandomAccessIterator<Node*>(ptrs), RandomAccessIterator<Node*>(ptrs + numKeys), CompareNodes);
  411. head_ = ptrs[0];
  412. ptrs[0]->prev_ = 0;
  413. for (unsigned i = 1; i < numKeys; ++i)
  414. {
  415. ptrs[i - 1]->next_ = ptrs[i];
  416. ptrs[i]->prev_ = ptrs[i - 1];
  417. }
  418. ptrs[numKeys - 1]->next_ = tail_;
  419. tail_->prev_ = ptrs[numKeys - 1];
  420. delete[] ptrs;
  421. }
  422. /// Rehash to a specific bucket count, which must be a power of two. Return true if successful.
  423. bool Rehash(unsigned numBuckets)
  424. {
  425. if (numBuckets == NumBuckets())
  426. return true;
  427. if (!numBuckets || numBuckets < Size() / MAX_LOAD_FACTOR)
  428. return false;
  429. // Check for being power of two
  430. unsigned check = numBuckets;
  431. while (!(check & 1))
  432. check >>= 1;
  433. if (check != 1)
  434. return false;
  435. AllocateBuckets(Size(), numBuckets);
  436. Rehash();
  437. return true;
  438. }
  439. /// Return iterator to the pair with key, or end iterator if not found.
  440. Iterator Find(const T& key)
  441. {
  442. if (!ptrs_)
  443. return End();
  444. unsigned hashKey = Hash(key);
  445. Node* node = FindNode(key, hashKey);
  446. if (node)
  447. return Iterator(node);
  448. else
  449. return End();
  450. }
  451. /// Return const iterator to the pair with key, or end iterator if not found.
  452. ConstIterator Find(const T& key) const
  453. {
  454. if (!ptrs_)
  455. return End();
  456. unsigned hashKey = Hash(key);
  457. Node* node = FindNode(key, hashKey);
  458. if (node)
  459. return ConstIterator(node);
  460. else
  461. return End();
  462. }
  463. /// Return whether contains a pair with key.
  464. bool Contains(const T& key) const
  465. {
  466. if (!ptrs_)
  467. return false;
  468. unsigned hashKey = Hash(key);
  469. return FindNode(key, hashKey) != 0;
  470. }
  471. /// Try to copy value to output. Return true if was found.
  472. bool TryGetValue(const T& key, U& out) const
  473. {
  474. if (!ptrs_)
  475. return false;
  476. unsigned hashKey = Hash(key);
  477. Node* node = FindNode(key, hashKey);
  478. if (node)
  479. {
  480. out = node->pair_.second_;
  481. return true;
  482. }
  483. else
  484. return false;
  485. }
  486. /// Return all the keys.
  487. Vector<T> Keys() const
  488. {
  489. Vector<T> result;
  490. result.Reserve(Size());
  491. for (ConstIterator i = Begin(); i != End(); ++i)
  492. result.Push(i->first_);
  493. return result;
  494. }
  495. /// Return all the values.
  496. Vector<U> Values() const
  497. {
  498. Vector<U> result;
  499. result.Reserve(Size());
  500. for (ConstIterator i = Begin(); i != End(); ++i)
  501. result.Push(i->second_);
  502. return result;
  503. }
  504. /// Return iterator to the beginning.
  505. Iterator Begin() { return Iterator(Head()); }
  506. /// Return iterator to the beginning.
  507. ConstIterator Begin() const { return ConstIterator(Head()); }
  508. /// Return iterator to the end.
  509. Iterator End() { return Iterator(Tail()); }
  510. /// Return iterator to the end.
  511. ConstIterator End() const { return ConstIterator(Tail()); }
  512. /// Return first pair.
  513. const KeyValue& Front() const { return *Begin(); }
  514. /// Return last pair.
  515. const KeyValue& Back() const { return *(--End()); }
  516. // ATOMIC BEGIN
  517. /// Insert a pair only if a corresponding key does not already exist.
  518. Iterator InsertNew(const T& key, const U& value)
  519. {
  520. unsigned hashKey = Hash(key);
  521. if (ptrs_)
  522. {
  523. Node* node = FindNode(key, hashKey);
  524. if (node)
  525. return Iterator(node);
  526. }
  527. return InsertNode(key, value, false);
  528. }
  529. // ATOMIC END
  530. private:
  531. /// Return the head node.
  532. Node* Head() const { return static_cast<Node*>(head_); }
  533. /// Return the tail node.
  534. Node* Tail() const { return static_cast<Node*>(tail_); }
  535. /// Find a node from the buckets. Do not call if the buckets have not been allocated.
  536. Node* FindNode(const T& key, unsigned hashKey) const
  537. {
  538. Node* node = static_cast<Node*>(Ptrs()[hashKey]);
  539. while (node)
  540. {
  541. if (node->pair_.first_ == key)
  542. return node;
  543. node = node->Down();
  544. }
  545. return 0;
  546. }
  547. /// Find a node and the previous node from the buckets. Do not call if the buckets have not been allocated.
  548. Node* FindNode(const T& key, unsigned hashKey, Node*& previous) const
  549. {
  550. previous = 0;
  551. Node* node = static_cast<Node*>(Ptrs()[hashKey]);
  552. while (node)
  553. {
  554. if (node->pair_.first_ == key)
  555. return node;
  556. previous = node;
  557. node = node->Down();
  558. }
  559. return 0;
  560. }
  561. /// Insert a key and value and return either the new or existing node.
  562. Node* InsertNode(const T& key, const U& value, bool findExisting = true)
  563. {
  564. // If no pointers yet, allocate with minimum bucket count
  565. if (!ptrs_)
  566. {
  567. AllocateBuckets(Size(), MIN_BUCKETS);
  568. Rehash();
  569. }
  570. unsigned hashKey = Hash(key);
  571. if (findExisting)
  572. {
  573. // If exists, just change the value
  574. Node* existing = FindNode(key, hashKey);
  575. if (existing)
  576. {
  577. existing->pair_.second_ = value;
  578. return existing;
  579. }
  580. }
  581. Node* newNode = InsertNode(Tail(), key, value);
  582. newNode->down_ = Ptrs()[hashKey];
  583. Ptrs()[hashKey] = newNode;
  584. // Rehash if the maximum load factor has been exceeded
  585. if (Size() > NumBuckets() * MAX_LOAD_FACTOR)
  586. {
  587. AllocateBuckets(Size(), NumBuckets() << 1);
  588. Rehash();
  589. }
  590. return newNode;
  591. }
  592. /// Insert a node into the list. Return the new node.
  593. Node* InsertNode(Node* dest, const T& key, const U& value)
  594. {
  595. if (!dest)
  596. return 0;
  597. Node* newNode = ReserveNode(key, value);
  598. Node* prev = dest->Prev();
  599. newNode->next_ = dest;
  600. newNode->prev_ = prev;
  601. if (prev)
  602. prev->next_ = newNode;
  603. dest->prev_ = newNode;
  604. // Reassign the head node if necessary
  605. if (dest == Head())
  606. head_ = newNode;
  607. SetSize(Size() + 1);
  608. return newNode;
  609. }
  610. /// Erase a node from the list. Return pointer to the next element, or to the end if could not erase.
  611. Node* EraseNode(Node* node)
  612. {
  613. // The tail node can not be removed
  614. if (!node || node == tail_)
  615. return Tail();
  616. Node* prev = node->Prev();
  617. Node* next = node->Next();
  618. if (prev)
  619. prev->next_ = next;
  620. next->prev_ = prev;
  621. // Reassign the head node if necessary
  622. if (node == Head())
  623. head_ = next;
  624. FreeNode(node);
  625. SetSize(Size() - 1);
  626. return next;
  627. }
  628. /// Reserve a node.
  629. Node* ReserveNode()
  630. {
  631. Node* newNode = static_cast<Node*>(AllocatorReserve(allocator_));
  632. new(newNode) Node();
  633. return newNode;
  634. }
  635. /// Reserve a node with specified key and value.
  636. Node* ReserveNode(const T& key, const U& value)
  637. {
  638. Node* newNode = static_cast<Node*>(AllocatorReserve(allocator_));
  639. new(newNode) Node(key, value);
  640. return newNode;
  641. }
  642. /// Free a node.
  643. void FreeNode(Node* node)
  644. {
  645. (node)->~Node();
  646. AllocatorFree(allocator_, node);
  647. }
  648. /// Rehash the buckets.
  649. void Rehash()
  650. {
  651. for (Iterator i = Begin(); i != End(); ++i)
  652. {
  653. Node* node = static_cast<Node*>(i.ptr_);
  654. unsigned hashKey = Hash(i->first_);
  655. node->down_ = Ptrs()[hashKey];
  656. Ptrs()[hashKey] = node;
  657. }
  658. }
  659. /// Compare two nodes.
  660. static bool CompareNodes(Node*& lhs, Node*& rhs) { return lhs->pair_.first_ < rhs->pair_.first_; }
  661. /// Compute a hash based on the key and the bucket size
  662. unsigned Hash(const T& key) const { return MakeHash(key) & (NumBuckets() - 1); }
  663. };
  664. template <class T, class U> typename Atomic::HashMap<T, U>::ConstIterator begin(const Atomic::HashMap<T, U>& v) { return v.Begin(); }
  665. template <class T, class U> typename Atomic::HashMap<T, U>::ConstIterator end(const Atomic::HashMap<T, U>& v) { return v.End(); }
  666. template <class T, class U> typename Atomic::HashMap<T, U>::Iterator begin(Atomic::HashMap<T, U>& v) { return v.Begin(); }
  667. template <class T, class U> typename Atomic::HashMap<T, U>::Iterator end(Atomic::HashMap<T, U>& v) { return v.End(); }
  668. }