HashMap.h 21 KB

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