Map.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756
  1. /*
  2. Copyright (c) 2013 Daniele Bartolini, Michele Rossi
  3. Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
  4. Permission is hereby granted, free of charge, to any person
  5. obtaining a copy of this software and associated documentation
  6. files (the "Software"), to deal in the Software without
  7. restriction, including without limitation the rights to use,
  8. copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. copies of the Software, and to permit persons to whom the
  10. Software is furnished to do so, subject to the following
  11. conditions:
  12. The above copyright notice and this permission notice shall be
  13. included in all copies or substantial portions of the Software.
  14. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  15. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  16. OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  17. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  18. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  19. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  21. OTHER DEALINGS IN THE SOFTWARE.
  22. */
  23. #pragma once
  24. #include "ContainerTypes.h"
  25. #include "Vector.h"
  26. // #define RBTREE_VERIFY
  27. namespace crown
  28. {
  29. /// Functions to manipulate Map
  30. ///
  31. /// @ingroup Containers
  32. namespace map
  33. {
  34. /// Returns the number of items in the map @a m.
  35. template <typename TKey, typename TValue> uint32_t size(const Map<TKey, TValue>& m);
  36. /// Returns whether the given @a key exists in the map @a m.
  37. template <typename TKey, typename TValue> bool has(const Map<TKey, TValue>& m, const TKey key);
  38. /// Returns the value for the given @a key or @a deffault if
  39. /// the key does not exist in the map.
  40. template <typename TKey, typename TValue> const TValue& get(const Map<TKey, TValue>& m, const TKey key, const TValue& deffault);
  41. /// Sets the @a value for the @a key in the map.
  42. template <typename TKey, typename TValue> void set(Map<TKey, TValue>& m, const TKey& key, const TValue& value);
  43. /// Removes the @a key from the map if it exists.
  44. template <typename TKey, typename TValue> void remove(Map<TKey, TValue>& m, const TKey& key);
  45. /// Removes all the items in the map.
  46. /// @note Calls destructor on the items.
  47. template <typename TKey, typename TValue> void clear(Map<TKey, TValue>& m);
  48. /// Returns a pointer to the first item in the map, can be used to
  49. /// efficiently iterate over the elements (in random order).
  50. template <typename TKey, typename TValue> const typename Map<TKey, TValue>::Node* begin(const Map<TKey, TValue>& m);
  51. template <typename TKey, typename TValue> const typename Map<TKey, TValue>::Node* end(const Map<TKey, TValue>& m);
  52. } // namespace map
  53. namespace map_internal
  54. {
  55. const uint32_t BLACK = 0xB1B1B1B1u;
  56. const uint32_t RED = 0xEDEDEDEDu;
  57. const uint32_t NIL = 0xFFFFFFFFu;
  58. template <typename TKey, typename TValue>
  59. inline uint32_t root(const Map<TKey, TValue>& m)
  60. {
  61. return m.m_root;
  62. }
  63. template <typename TKey, typename TValue>
  64. inline uint32_t parent(const Map<TKey, TValue>& m, uint32_t n)
  65. {
  66. CE_ASSERT(n < vector::size(m.m_data), "Index out of bounds (size = %d, n = %d)", vector::size(m.m_data), n);
  67. return m.m_data[n].parent;
  68. }
  69. template <typename TKey, typename TValue>
  70. inline uint32_t left(const Map<TKey, TValue>& m, uint32_t n)
  71. {
  72. CE_ASSERT(n < vector::size(m.m_data), "Index out of bounds (size = %d, n = %d)", vector::size(m.m_data), n);
  73. return m.m_data[n].left;
  74. }
  75. template <typename TKey, typename TValue>
  76. inline uint32_t right(const Map<TKey, TValue>& m, uint32_t n)
  77. {
  78. CE_ASSERT(n < vector::size(m.m_data), "Index out of bounds (size = %d, n = %d)", vector::size(m.m_data), n);
  79. return m.m_data[n].right;
  80. }
  81. template <typename TKey, typename TValue>
  82. inline uint32_t color(const Map<TKey, TValue>& m, uint32_t n)
  83. {
  84. CE_ASSERT(n < vector::size(m.m_data), "Index out of bounds (size = %d, n = %d)", vector::size(m.m_data), n);
  85. return m.m_data[n].color;
  86. }
  87. #ifdef RBTREE_VERIFY
  88. template<typename TKey, typename TValue>
  89. inline int32_t dbg_verify(Map<TKey, TValue>& m, uint32_t n)
  90. {
  91. if (n == m.m_sentinel)
  92. {
  93. return 0;
  94. }
  95. if (left(m, n) != m.m_sentinel)
  96. {
  97. CE_ASSERT(parent(m, left(m, n)) == n, "Bad RBTree");
  98. CE_ASSERT(m.m_data[left(m, n)].key < m.m_data[n].key, "Bad RBTree");
  99. }
  100. if (right(m, n) != m.m_sentinel)
  101. {
  102. CE_ASSERT(parent(m, right(m, n)) == n, "Bad RBTree");
  103. CE_ASSERT(m.m_data[n].key < m.m_data[right(m, n)].key, "Bad RBTree");
  104. }
  105. int32_t bhL = dbg_verify(m, left(m, n));
  106. int32_t bhR = dbg_verify(m, right(m, n));
  107. CE_ASSERT(bhL == bhR, "Bad RBTree");
  108. if (color(m, n) == BLACK)
  109. {
  110. bhL += 1;
  111. }
  112. else
  113. {
  114. if (parent(m, n) != NIL && color(m, parent(m, n)) == RED)
  115. {
  116. CE_ASSERT(false, "Bad RBTree");
  117. }
  118. }
  119. return bhL;
  120. }
  121. template<typename TKey, typename TValue>
  122. inline int32_t dump(Map<TKey, TValue>& m)
  123. {
  124. for (uint32_t i = 0; i < vector::size(m.m_data); i++)
  125. {
  126. printf("%d = [%d, %d, %d] ", i, parent(m, i), left(m, i), right(m, i));
  127. }
  128. printf("\n");
  129. return 0;
  130. }
  131. #endif
  132. template <typename TKey, typename TValue>
  133. inline uint32_t min(const Map<TKey, TValue>& m, uint32_t x)
  134. {
  135. if (x == m.m_sentinel)
  136. {
  137. return x;
  138. }
  139. while (left(m, x) != m.m_sentinel)
  140. {
  141. x = left(m, x);
  142. }
  143. return x;
  144. }
  145. template <typename TKey, typename TValue>
  146. inline uint32_t max(const Map<TKey, TValue>& m, uint32_t x)
  147. {
  148. if (x == m.m_sentinel)
  149. {
  150. return x;
  151. }
  152. while (right(m, x) != m.m_sentinel)
  153. {
  154. x = right(m, x);
  155. }
  156. return x;
  157. }
  158. template <typename TKey, typename TValue>
  159. inline uint32_t successor(const Map<TKey, TValue>& m, uint32_t x)
  160. {
  161. if (right(m, x) != m.m_sentinel)
  162. {
  163. return min(m, right(m, x));
  164. }
  165. uint32_t y = parent(m, x);
  166. while (y != NIL && x == right(m, y))
  167. {
  168. x = y;
  169. y = parent(m, y);
  170. }
  171. return y;
  172. }
  173. template <typename TKey, typename TValue>
  174. inline uint32_t predecessor(const Map<TKey, TValue>& m, uint32_t x)
  175. {
  176. if (left(m, x) != m.m_sentinel)
  177. {
  178. return max(m, left(m, x));
  179. }
  180. uint32_t y = parent(m, x);
  181. while (y != NIL && x == left(m, y))
  182. {
  183. x = y;
  184. y = parent(m, y);
  185. }
  186. return y;
  187. }
  188. template <typename TKey, typename TValue>
  189. inline void rotate_left(Map<TKey, TValue>& m, uint32_t x)
  190. {
  191. CE_ASSERT(x < vector::size(m.m_data), "Index out of bounds (size = %d, n = %d)", vector::size(m.m_data), x);
  192. uint32_t y = right(m, x);
  193. m.m_data[x].right = left(m, y);
  194. if (left(m, y) != m.m_sentinel)
  195. {
  196. m.m_data[left(m, y)].parent = x;
  197. }
  198. m.m_data[y].parent = parent(m, x);
  199. if (parent(m, x) == NIL)
  200. {
  201. m.m_root = y;
  202. }
  203. else
  204. {
  205. if (x == left(m, parent(m, x)))
  206. {
  207. m.m_data[parent(m, x)].left = y;
  208. }
  209. else
  210. {
  211. m.m_data[parent(m, x)].right = y;
  212. }
  213. }
  214. m.m_data[y].left = x;
  215. m.m_data[x].parent = y;
  216. }
  217. template <typename TKey, typename TValue>
  218. inline void rotate_right(Map<TKey, TValue>& m, uint32_t x)
  219. {
  220. CE_ASSERT(x < vector::size(m.m_data), "Index out of bounds (size = %d, n = %d)", vector::size(m.m_data), x);
  221. uint32_t y = left(m, x);
  222. m.m_data[x].left = right(m, y);
  223. if (right(m, y) != m.m_sentinel)
  224. {
  225. m.m_data[right(m, y)].parent = x;
  226. }
  227. m.m_data[y].parent = parent(m, x);
  228. if (parent(m, x) == NIL)
  229. {
  230. m.m_root = y;
  231. }
  232. else
  233. {
  234. if (x == left(m, parent(m, x)))
  235. {
  236. m.m_data[parent(m, x)].left = y;
  237. }
  238. else
  239. {
  240. m.m_data[parent(m, x)].right = y;
  241. }
  242. }
  243. m.m_data[y].right = x;
  244. m.m_data[x].parent = y;
  245. }
  246. template <typename TKey, typename TValue>
  247. inline void destroy(Map<TKey, TValue>& m, uint32_t n)
  248. {
  249. CE_ASSERT(n < vector::size(m.m_data), "Index out of bounds (size = %d, n = %d)", vector::size(m.m_data), n);
  250. uint32_t x = vector::size(m.m_data) - 1;
  251. if (x == m.m_root)
  252. {
  253. m.m_root = n;
  254. if (left(m, x) != NIL)
  255. m.m_data[left(m, x)].parent = n;
  256. if (right(m, x) != NIL)
  257. m.m_data[right(m, x)].parent = n;
  258. m.m_data[n] = m.m_data[x];
  259. }
  260. else
  261. {
  262. if (x != n)
  263. {
  264. if (x == left(m, parent(m, x)))
  265. {
  266. m.m_data[parent(m, x)].left = n;
  267. }
  268. else if (x == right(m, parent(m, x)))
  269. {
  270. m.m_data[parent(m, x)].right = n;
  271. }
  272. if (left(m, x) != NIL)
  273. m.m_data[left(m, x)].parent = n;
  274. if (right(m, x) != NIL)
  275. m.m_data[right(m, x)].parent = n;
  276. m.m_data[n] = m.m_data[x];
  277. }
  278. }
  279. #ifdef RBTREE_VERIFY
  280. dbg_verify(m, m.m_root);
  281. #endif
  282. vector::pop_back(m.m_data);
  283. }
  284. template <typename TKey, typename TValue>
  285. inline void insert_fixup(Map<TKey, TValue>& m, uint32_t n)
  286. {
  287. CE_ASSERT(n < vector::size(m.m_data), "Index out of bounds (size = %d, n = %d)", vector::size(m.m_data), n);
  288. uint32_t x;
  289. uint32_t y;
  290. while (n != root(m) && color(m, parent(m, n)) == RED)
  291. {
  292. x = parent(m, n);
  293. if (x == left(m, parent(m, x)))
  294. {
  295. y = right(m, parent(m, x));
  296. if (color(m, y) == RED)
  297. {
  298. m.m_data[x].color = BLACK;
  299. m.m_data[y].color = BLACK;
  300. m.m_data[parent(m, x)].color = RED;
  301. n = parent(m, x);
  302. continue;
  303. }
  304. else
  305. {
  306. if (n == right(m, x))
  307. {
  308. n = x;
  309. rotate_left(m, n);
  310. x = parent(m, n);
  311. }
  312. m.m_data[x].color = BLACK;
  313. m.m_data[parent(m, x)].color = RED;
  314. rotate_right(m, parent(m, x));
  315. }
  316. }
  317. else
  318. {
  319. y = left(m, parent(m, x));
  320. if (color(m, y) == RED)
  321. {
  322. m.m_data[x].color = BLACK;
  323. m.m_data[y].color = BLACK;
  324. m.m_data[parent(m, x)].color = RED;
  325. n = parent(m, x);
  326. continue;
  327. }
  328. else
  329. {
  330. if (n == left(m, x))
  331. {
  332. n = x;
  333. rotate_right(m, n);
  334. x = parent(m, n);
  335. }
  336. m.m_data[x].color = BLACK;
  337. m.m_data[parent(m, x)].color = RED;
  338. rotate_left(m, parent(m, x));
  339. }
  340. }
  341. }
  342. }
  343. template <typename TKey, typename TValue>
  344. inline uint32_t inner_find(const Map<TKey, TValue>& m, const TKey key)
  345. {
  346. uint32_t x = m.m_root;
  347. while (x != m.m_sentinel)
  348. {
  349. if (m.m_data[x].key < key)
  350. {
  351. if (right(m, x) == m.m_sentinel)
  352. {
  353. return x;
  354. }
  355. x = right(m, x);
  356. }
  357. else if (key < m.m_data[x].key)
  358. {
  359. if (left(m, x) == m.m_sentinel)
  360. {
  361. return x;
  362. }
  363. x = left(m, x);
  364. }
  365. else
  366. {
  367. break;
  368. }
  369. }
  370. return x;
  371. }
  372. template <typename TKey, typename TValue>
  373. inline uint32_t find_or_fail(const Map<TKey, TValue>& m, const TKey key)
  374. {
  375. uint32_t p = inner_find(m, key);
  376. if (p != m.m_sentinel && m.m_data[p].key == key)
  377. return p;
  378. return NIL;
  379. }
  380. template <typename TKey, typename TValue>
  381. inline uint32_t find_or_add(Map<TKey, TValue>& m, const TKey key)
  382. {
  383. uint32_t p = inner_find(m, key);
  384. if (p != m.m_sentinel && m.m_data[p].key == key)
  385. {
  386. return p;
  387. }
  388. typename Map<TKey, TValue>::Node n;
  389. n.key = key;
  390. n.value = TValue();
  391. n.color = RED;
  392. n.left = m.m_sentinel;
  393. n.right = m.m_sentinel;
  394. n.parent = NIL;
  395. if (p == m.m_sentinel)
  396. {
  397. m.m_root = n;
  398. }
  399. else
  400. {
  401. if (key < m.m_data[p].key)
  402. {
  403. m.m_data[p].left = n;
  404. }
  405. else
  406. {
  407. m.m_data[p].right = n;
  408. }
  409. m.m_data[n].parent = p;
  410. }
  411. add_fixup(m, n);
  412. m.m_data[m.m_root].color = BLACK;
  413. #ifdef RBTREE_VERIFY
  414. dbg_verify(m, m.m_root);
  415. #endif
  416. return n;
  417. }
  418. } // namespace map_internal
  419. namespace map
  420. {
  421. template <typename TKey, typename TValue>
  422. uint32_t size(const Map<TKey, TValue>& m)
  423. {
  424. CE_ASSERT(vector::size(m.m_data) > 0, "Bad Map"); // There should be at least sentinel
  425. return vector::size(m.m_data) - 1;
  426. }
  427. template <typename TKey, typename TValue>
  428. inline bool has(const Map<TKey, TValue>& m, const TKey key)
  429. {
  430. return map_internal::find_or_fail(m, key) != map_internal::NIL;
  431. }
  432. template <typename TKey, typename TValue>
  433. inline const TValue& get(const Map<TKey, TValue>& m, const TKey key, const TValue& deffault)
  434. {
  435. uint32_t p = map_internal::inner_find(m, key);
  436. if (p != m.m_sentinel && m.m_data[p].key == key)
  437. {
  438. return m.m_data[p].value;
  439. }
  440. return deffault;
  441. }
  442. template <typename TKey, typename TValue>
  443. inline void set(Map<TKey, TValue>& m, const TKey& key, const TValue& value)
  444. {
  445. typename Map<TKey, TValue>::Node node;
  446. node.key = key;
  447. node.value = value;
  448. node.color = map_internal::RED;
  449. node.left = m.m_sentinel;
  450. node.right = m.m_sentinel;
  451. node.parent = map_internal::NIL;
  452. uint32_t n = vector::push_back(m.m_data, node);
  453. uint32_t x = m.m_root;
  454. uint32_t y = map_internal::NIL;
  455. if (x == m.m_sentinel)
  456. m.m_root = n;
  457. else
  458. {
  459. while (x != m.m_sentinel)
  460. {
  461. y = x;
  462. if (key < m.m_data[x].key)
  463. x = m.m_data[x].left;
  464. else
  465. x = m.m_data[x].right;
  466. }
  467. if (key < m.m_data[y].key)
  468. m.m_data[y].left = n;
  469. else
  470. m.m_data[y].right = n;
  471. m.m_data[n].parent = y;
  472. }
  473. map_internal::insert_fixup(m, n);
  474. m.m_data[m.m_root].color = map_internal::BLACK;
  475. #ifdef RBTREE_VERIFY
  476. map_internal::dbg_verify(m, m.m_root);
  477. #endif
  478. }
  479. template <typename TKey, typename TValue>
  480. inline void remove(Map<TKey, TValue>& m, const TKey& key)
  481. {
  482. using namespace map_internal;
  483. uint32_t n = inner_find(m, key);
  484. if (!(m.m_data[n].key == key))
  485. {
  486. return;
  487. }
  488. uint32_t x;
  489. uint32_t y;
  490. if (left(m, n) == m.m_sentinel || right(m, n) == m.m_sentinel)
  491. {
  492. y = n;
  493. }
  494. else
  495. {
  496. y = successor(m, n);
  497. }
  498. if (left(m, y) != m.m_sentinel)
  499. {
  500. x = left(m, y);
  501. }
  502. else
  503. {
  504. x = right(m, y);
  505. }
  506. m.m_data[x].parent = parent(m, y);
  507. if (parent(m, y) != map_internal::NIL)
  508. {
  509. if (y == left(m, parent(m, y)))
  510. {
  511. m.m_data[parent(m, y)].left = x;
  512. }
  513. else
  514. {
  515. m.m_data[parent(m, y)].right = x;
  516. }
  517. }
  518. else
  519. {
  520. m.m_root = x;
  521. }
  522. if (y != n)
  523. {
  524. m.m_data[n].key = m.m_data[y].key;
  525. m.m_data[n].value = m.m_data[y].value;
  526. }
  527. // Do the fixup
  528. if (color(m, y) == map_internal::BLACK)
  529. {
  530. uint32_t y;
  531. while (x != m.m_root && color(m, x) == map_internal::BLACK)
  532. {
  533. if (x == left(m, parent(m, x)))
  534. {
  535. y = right(m, parent(m, x));
  536. if (color(m, y) == map_internal::RED)
  537. {
  538. m.m_data[y].color = map_internal::BLACK;
  539. m.m_data[parent(m, x)].color = map_internal::RED;
  540. rotate_left(m, parent(m, x));
  541. y = right(m, parent(m, x));
  542. }
  543. if (color(m, left(m, y)) == map_internal::BLACK && color(m, right(m, y)) == map_internal::BLACK)
  544. {
  545. m.m_data[y].color = map_internal::RED;
  546. x = parent(m, x);
  547. }
  548. else
  549. {
  550. if (color(m, right(m, y)) == map_internal::BLACK)
  551. {
  552. m.m_data[left(m, y)].color = map_internal::BLACK;
  553. m.m_data[y].color = map_internal::RED;
  554. rotate_right(m, y);
  555. y = right(m, parent(m, x));
  556. }
  557. m.m_data[y].color = color(m, parent(m, x));
  558. m.m_data[parent(m, x)].color = map_internal::BLACK;
  559. m.m_data[right(m, y)].color = map_internal::BLACK;
  560. rotate_left(m, parent(m, x));
  561. x = m.m_root;
  562. }
  563. }
  564. else
  565. {
  566. y = left(m, parent(m, x));
  567. if (color(m, y) == map_internal::RED)
  568. {
  569. m.m_data[y].color = map_internal::BLACK;
  570. m.m_data[parent(m, x)].color = map_internal::RED;
  571. rotate_right(m, parent(m, x));
  572. y = left(m, parent(m, x));
  573. }
  574. if (color(m, right(m, y)) == map_internal::BLACK && color(m, left(m, y)) == map_internal::BLACK)
  575. {
  576. m.m_data[y].color = map_internal::RED;
  577. x = parent(m, x);
  578. }
  579. else
  580. {
  581. if (color(m, left(m, y)) == map_internal::BLACK)
  582. {
  583. m.m_data[right(m, y)].color = map_internal::BLACK;
  584. m.m_data[y].color = map_internal::RED;
  585. rotate_left(m, y);
  586. y = left(m, parent(m, x));
  587. }
  588. m.m_data[y].color = color(m, parent(m, x));
  589. m.m_data[parent(m, x)].color = map_internal::BLACK;
  590. m.m_data[left(m, y)].color = map_internal::BLACK;
  591. rotate_right(m, parent(m, x));
  592. x = m.m_root;
  593. }
  594. }
  595. }
  596. m.m_data[x].color = map_internal::BLACK;
  597. }
  598. destroy(m, y);
  599. #ifdef RBTREE_VERIFY
  600. map_internal::dbg_verify(m, m.m_root);
  601. #endif
  602. }
  603. template <typename TKey, typename TValue>
  604. void clear(Map<TKey, TValue>& m)
  605. {
  606. vector::clear(m.m_data);
  607. m.m_root = 0;
  608. m.m_sentinel = 0;
  609. typename Map<TKey, TValue>::Node r;
  610. r.key = TKey();
  611. r.value = TValue();
  612. r.left = map_internal::NIL;
  613. r.right = map_internal::NIL;
  614. r.parent = map_internal::NIL;
  615. r.color = map_internal::BLACK;
  616. vector::push_back(m.m_data, r);
  617. }
  618. template <typename TKey, typename TValue>
  619. const typename Map<TKey, TValue>::Node* begin(const Map<TKey, TValue>& m)
  620. {
  621. return vector::begin(m.m_data) + 1; // Skip sentinel at index 0
  622. }
  623. template <typename TKey, typename TValue>
  624. const typename Map<TKey, TValue>::Node* end(const Map<TKey, TValue>& m)
  625. {
  626. return vector::end(m.m_data);
  627. }
  628. } // namespace map
  629. template <typename TKey, typename TValue>
  630. inline Map<TKey, TValue>::Map(Allocator& a)
  631. : m_data(a)
  632. {
  633. map::clear(*this);
  634. }
  635. } // namespace crown