HashMap.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800
  1. //
  2. // Copyright (c) 2008-2016 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. Clear();
  227. Insert(rhs);
  228. return *this;
  229. }
  230. /// Add-assign a pair.
  231. HashMap& operator +=(const Pair<T, U>& rhs)
  232. {
  233. Insert(rhs);
  234. return *this;
  235. }
  236. /// Add-assign a hash map.
  237. HashMap& operator +=(const HashMap<T, U>& rhs)
  238. {
  239. Insert(rhs);
  240. return *this;
  241. }
  242. /// Test for equality with another hash map.
  243. bool operator ==(const HashMap<T, U>& rhs) const
  244. {
  245. if (rhs.Size() != Size())
  246. return false;
  247. ConstIterator i = Begin();
  248. while (i != End())
  249. {
  250. ConstIterator j = rhs.Find(i->first_);
  251. if (j == rhs.End() || j->second_ != i->second_)
  252. return false;
  253. ++i;
  254. }
  255. return true;
  256. }
  257. /// Test for inequality with another hash map.
  258. bool operator !=(const HashMap<T, U>& rhs) const
  259. {
  260. if (rhs.Size() != Size())
  261. return true;
  262. ConstIterator i = Begin();
  263. while (i != End())
  264. {
  265. ConstIterator j = rhs.Find(i->first_);
  266. if (j == rhs.End() || j->second_ != i->second_)
  267. return true;
  268. ++i;
  269. }
  270. return false;
  271. }
  272. /// Index the map. Create a new pair if key not found.
  273. U& operator [](const T& key)
  274. {
  275. if (!ptrs_)
  276. return InsertNode(key, U(), false)->pair_.second_;
  277. unsigned hashKey = Hash(key);
  278. Node* node = FindNode(key, hashKey);
  279. return node ? node->pair_.second_ : InsertNode(key, U(), false)->pair_.second_;
  280. }
  281. /// Index the map. Return null if key is not found, does not create a new pair.
  282. U* operator [](const T& key) const
  283. {
  284. if (!ptrs_)
  285. return 0;
  286. unsigned hashKey = Hash(key);
  287. Node* node = FindNode(key, hashKey);
  288. return node ? &node->pair_.second_ : 0;
  289. }
  290. #if ATOMIC_CXX11
  291. /// Populate the map using variadic template. This handles the base case.
  292. HashMap& Populate(const T& key, const U& value)
  293. {
  294. this->operator [](key) = value;
  295. return *this;
  296. };
  297. /// Populate the map using variadic template.
  298. template <typename... Args> HashMap& Populate(const T& key, const U& value, Args... args)
  299. {
  300. this->operator [](key) = value;
  301. return Populate(args...);
  302. };
  303. #endif
  304. /// Insert a pair. Return an iterator to it.
  305. Iterator Insert(const Pair<T, U>& pair)
  306. {
  307. return Iterator(InsertNode(pair.first_, pair.second_));
  308. }
  309. /// Insert a pair. Return iterator and set exists flag according to whether the key already existed.
  310. Iterator Insert(const Pair<T, U>& pair, bool& exists)
  311. {
  312. unsigned oldSize = Size();
  313. Iterator ret(InsertNode(pair.first_, pair.second_));
  314. exists = (Size() == oldSize);
  315. return ret;
  316. }
  317. /// Insert a map.
  318. void Insert(const HashMap<T, U>& map)
  319. {
  320. ConstIterator it = map.Begin();
  321. ConstIterator end = map.End();
  322. while (it != end)
  323. {
  324. InsertNode(it->first_, it->second_);
  325. ++it;
  326. }
  327. }
  328. /// Insert a pair by iterator. Return iterator to the value.
  329. Iterator Insert(const ConstIterator& it) { return Iterator(InsertNode(it->first_, it->second_)); }
  330. /// Insert a range by iterators.
  331. void Insert(const ConstIterator& start, const ConstIterator& end)
  332. {
  333. ConstIterator it = start;
  334. while (it != end)
  335. InsertNode(*it++);
  336. }
  337. /// Erase a pair by key. Return true if was found.
  338. bool Erase(const T& key)
  339. {
  340. if (!ptrs_)
  341. return false;
  342. unsigned hashKey = Hash(key);
  343. Node* previous;
  344. Node* node = FindNode(key, hashKey, previous);
  345. if (!node)
  346. return false;
  347. if (previous)
  348. previous->down_ = node->down_;
  349. else
  350. Ptrs()[hashKey] = node->down_;
  351. EraseNode(node);
  352. return true;
  353. }
  354. /// Erase a pair by iterator. Return iterator to the next pair.
  355. Iterator Erase(const Iterator& it)
  356. {
  357. if (!ptrs_ || !it.ptr_)
  358. return End();
  359. Node* node = static_cast<Node*>(it.ptr_);
  360. Node* next = node->Next();
  361. unsigned hashKey = Hash(node->pair_.first_);
  362. Node* previous = 0;
  363. Node* current = static_cast<Node*>(Ptrs()[hashKey]);
  364. while (current && current != node)
  365. {
  366. previous = current;
  367. current = current->Down();
  368. }
  369. assert(current == node);
  370. if (previous)
  371. previous->down_ = node->down_;
  372. else
  373. Ptrs()[hashKey] = node->down_;
  374. EraseNode(node);
  375. return Iterator(next);
  376. }
  377. /// Clear the map.
  378. void Clear()
  379. {
  380. // Prevent Find() from returning anything while the map is being cleared
  381. ResetPtrs();
  382. if (Size())
  383. {
  384. for (Iterator i = Begin(); i != End();)
  385. {
  386. FreeNode(static_cast<Node*>(i++.ptr_));
  387. i.ptr_->prev_ = 0;
  388. }
  389. head_ = tail_;
  390. SetSize(0);
  391. }
  392. }
  393. /// Sort pairs. After sorting the map can be iterated in order until new elements are inserted.
  394. void Sort()
  395. {
  396. unsigned numKeys = Size();
  397. if (!numKeys)
  398. return;
  399. Node** ptrs = new Node* [numKeys];
  400. Node* ptr = Head();
  401. for (unsigned i = 0; i < numKeys; ++i)
  402. {
  403. ptrs[i] = ptr;
  404. ptr = ptr->Next();
  405. }
  406. Atomic::Sort(RandomAccessIterator<Node*>(ptrs), RandomAccessIterator<Node*>(ptrs + numKeys), CompareNodes);
  407. head_ = ptrs[0];
  408. ptrs[0]->prev_ = 0;
  409. for (unsigned i = 1; i < numKeys; ++i)
  410. {
  411. ptrs[i - 1]->next_ = ptrs[i];
  412. ptrs[i]->prev_ = ptrs[i - 1];
  413. }
  414. ptrs[numKeys - 1]->next_ = tail_;
  415. tail_->prev_ = ptrs[numKeys - 1];
  416. delete[] ptrs;
  417. }
  418. /// Rehash to a specific bucket count, which must be a power of two. Return true if successful.
  419. bool Rehash(unsigned numBuckets)
  420. {
  421. if (numBuckets == NumBuckets())
  422. return true;
  423. if (!numBuckets || numBuckets < Size() / MAX_LOAD_FACTOR)
  424. return false;
  425. // Check for being power of two
  426. unsigned check = numBuckets;
  427. while (!(check & 1))
  428. check >>= 1;
  429. if (check != 1)
  430. return false;
  431. AllocateBuckets(Size(), numBuckets);
  432. Rehash();
  433. return true;
  434. }
  435. /// Return iterator to the pair with key, or end iterator if not found.
  436. Iterator Find(const T& key)
  437. {
  438. if (!ptrs_)
  439. return End();
  440. unsigned hashKey = Hash(key);
  441. Node* node = FindNode(key, hashKey);
  442. if (node)
  443. return Iterator(node);
  444. else
  445. return End();
  446. }
  447. /// Return const iterator to the pair with key, or end iterator if not found.
  448. ConstIterator Find(const T& key) const
  449. {
  450. if (!ptrs_)
  451. return End();
  452. unsigned hashKey = Hash(key);
  453. Node* node = FindNode(key, hashKey);
  454. if (node)
  455. return ConstIterator(node);
  456. else
  457. return End();
  458. }
  459. /// Return whether contains a pair with key.
  460. bool Contains(const T& key) const
  461. {
  462. if (!ptrs_)
  463. return false;
  464. unsigned hashKey = Hash(key);
  465. return FindNode(key, hashKey) != 0;
  466. }
  467. /// Try to copy value to output. Return true if was found.
  468. bool TryGetValue(const T& key, U& out) const
  469. {
  470. if (!ptrs_)
  471. return false;
  472. unsigned hashKey = Hash(key);
  473. Node* node = FindNode(key, hashKey);
  474. if (node)
  475. {
  476. out = node->pair_.second_;
  477. return true;
  478. }
  479. else
  480. return false;
  481. }
  482. /// Return all the keys.
  483. Vector<T> Keys() const
  484. {
  485. Vector<T> result;
  486. result.Reserve(Size());
  487. for (ConstIterator i = Begin(); i != End(); ++i)
  488. result.Push(i->first_);
  489. return result;
  490. }
  491. /// Return all the values.
  492. Vector<U> Values() const
  493. {
  494. Vector<U> result;
  495. result.Reserve(Size());
  496. for (ConstIterator i = Begin(); i != End(); ++i)
  497. result.Push(i->second_);
  498. return result;
  499. }
  500. /// Return iterator to the beginning.
  501. Iterator Begin() { return Iterator(Head()); }
  502. /// Return iterator to the beginning.
  503. ConstIterator Begin() const { return ConstIterator(Head()); }
  504. /// Return iterator to the end.
  505. Iterator End() { return Iterator(Tail()); }
  506. /// Return iterator to the end.
  507. ConstIterator End() const { return ConstIterator(Tail()); }
  508. /// Return first pair.
  509. const KeyValue& Front() const { return *Begin(); }
  510. /// Return last pair.
  511. const KeyValue& Back() const { return *(--End()); }
  512. // ATOMIC BEGIN
  513. /// Insert a pair only if a corresponding key does not already exist.
  514. Iterator InsertNew(const T& key, const U& value)
  515. {
  516. unsigned hashKey = Hash(key);
  517. if (ptrs_)
  518. {
  519. Node* node = FindNode(key, hashKey);
  520. if (node)
  521. return Iterator(node);
  522. }
  523. return InsertNode(key, value, false);
  524. }
  525. // ATOMIC END
  526. private:
  527. /// Return the head node.
  528. Node* Head() const { return static_cast<Node*>(head_); }
  529. /// Return the tail node.
  530. Node* Tail() const { return static_cast<Node*>(tail_); }
  531. /// Find a node from the buckets. Do not call if the buckets have not been allocated.
  532. Node* FindNode(const T& key, unsigned hashKey) const
  533. {
  534. Node* node = static_cast<Node*>(Ptrs()[hashKey]);
  535. while (node)
  536. {
  537. if (node->pair_.first_ == key)
  538. return node;
  539. node = node->Down();
  540. }
  541. return 0;
  542. }
  543. /// Find a node and the previous node from the buckets. Do not call if the buckets have not been allocated.
  544. Node* FindNode(const T& key, unsigned hashKey, Node*& previous) const
  545. {
  546. previous = 0;
  547. Node* node = static_cast<Node*>(Ptrs()[hashKey]);
  548. while (node)
  549. {
  550. if (node->pair_.first_ == key)
  551. return node;
  552. previous = node;
  553. node = node->Down();
  554. }
  555. return 0;
  556. }
  557. /// Insert a key and value and return either the new or existing node.
  558. Node* InsertNode(const T& key, const U& value, bool findExisting = true)
  559. {
  560. // If no pointers yet, allocate with minimum bucket count
  561. if (!ptrs_)
  562. {
  563. AllocateBuckets(Size(), MIN_BUCKETS);
  564. Rehash();
  565. }
  566. unsigned hashKey = Hash(key);
  567. if (findExisting)
  568. {
  569. // If exists, just change the value
  570. Node* existing = FindNode(key, hashKey);
  571. if (existing)
  572. {
  573. existing->pair_.second_ = value;
  574. return existing;
  575. }
  576. }
  577. Node* newNode = InsertNode(Tail(), key, value);
  578. newNode->down_ = Ptrs()[hashKey];
  579. Ptrs()[hashKey] = newNode;
  580. // Rehash if the maximum load factor has been exceeded
  581. if (Size() > NumBuckets() * MAX_LOAD_FACTOR)
  582. {
  583. AllocateBuckets(Size(), NumBuckets() << 1);
  584. Rehash();
  585. }
  586. return newNode;
  587. }
  588. /// Insert a node into the list. Return the new node.
  589. Node* InsertNode(Node* dest, const T& key, const U& value)
  590. {
  591. if (!dest)
  592. return 0;
  593. Node* newNode = ReserveNode(key, value);
  594. Node* prev = dest->Prev();
  595. newNode->next_ = dest;
  596. newNode->prev_ = prev;
  597. if (prev)
  598. prev->next_ = newNode;
  599. dest->prev_ = newNode;
  600. // Reassign the head node if necessary
  601. if (dest == Head())
  602. head_ = newNode;
  603. SetSize(Size() + 1);
  604. return newNode;
  605. }
  606. /// Erase a node from the list. Return pointer to the next element, or to the end if could not erase.
  607. Node* EraseNode(Node* node)
  608. {
  609. // The tail node can not be removed
  610. if (!node || node == tail_)
  611. return Tail();
  612. Node* prev = node->Prev();
  613. Node* next = node->Next();
  614. if (prev)
  615. prev->next_ = next;
  616. next->prev_ = prev;
  617. // Reassign the head node if necessary
  618. if (node == Head())
  619. head_ = next;
  620. FreeNode(node);
  621. SetSize(Size() - 1);
  622. return next;
  623. }
  624. /// Reserve a node.
  625. Node* ReserveNode()
  626. {
  627. Node* newNode = static_cast<Node*>(AllocatorReserve(allocator_));
  628. new(newNode) Node();
  629. return newNode;
  630. }
  631. /// Reserve a node with specified key and value.
  632. Node* ReserveNode(const T& key, const U& value)
  633. {
  634. Node* newNode = static_cast<Node*>(AllocatorReserve(allocator_));
  635. new(newNode) Node(key, value);
  636. return newNode;
  637. }
  638. /// Free a node.
  639. void FreeNode(Node* node)
  640. {
  641. (node)->~Node();
  642. AllocatorFree(allocator_, node);
  643. }
  644. /// Rehash the buckets.
  645. void Rehash()
  646. {
  647. for (Iterator i = Begin(); i != End(); ++i)
  648. {
  649. Node* node = static_cast<Node*>(i.ptr_);
  650. unsigned hashKey = Hash(i->first_);
  651. node->down_ = Ptrs()[hashKey];
  652. Ptrs()[hashKey] = node;
  653. }
  654. }
  655. /// Compare two nodes.
  656. static bool CompareNodes(Node*& lhs, Node*& rhs) { return lhs->pair_.first_ < rhs->pair_.first_; }
  657. /// Compute a hash based on the key and the bucket size
  658. unsigned Hash(const T& key) const { return MakeHash(key) & (NumBuckets() - 1); }
  659. };
  660. template <class T, class U> typename Atomic::HashMap<T, U>::ConstIterator begin(const Atomic::HashMap<T, U>& v) { return v.Begin(); }
  661. template <class T, class U> typename Atomic::HashMap<T, U>::ConstIterator end(const Atomic::HashMap<T, U>& v) { return v.End(); }
  662. template <class T, class U> typename Atomic::HashMap<T, U>::Iterator begin(Atomic::HashMap<T, U>& v) { return v.Begin(); }
  663. template <class T, class U> typename Atomic::HashMap<T, U>::Iterator end(Atomic::HashMap<T, U>& v) { return v.End(); }
  664. }