HashMap.h 21 KB

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