_hashtable.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553
  1. /*
  2. * Copyright (c) 1994
  3. * Hewlett-Packard Company
  4. *
  5. * Copyright (c) 1996,1997
  6. * Silicon Graphics Computer Systems, Inc.
  7. *
  8. * Copyright (c) 1997
  9. * Moscow Center for SPARC Technology
  10. *
  11. * Copyright (c) 1999
  12. * Boris Fomitchev
  13. *
  14. * This material is provided "as is", with absolutely no warranty expressed
  15. * or implied. Any use is at your own risk.
  16. *
  17. * Permission to use or copy this software for any purpose is hereby granted
  18. * without fee, provided the above notices are retained on all copies.
  19. * Permission to modify the code and to distribute modified code is granted,
  20. * provided the above notices are retained, and a notice that the code was
  21. * modified is included with the above copyright notice.
  22. *
  23. */
  24. #ifndef _STLP_HASHTABLE_C
  25. #define _STLP_HASHTABLE_C
  26. #ifndef _STLP_INTERNAL_HASHTABLE_H
  27. # include <stl/_hashtable.h>
  28. #endif
  29. _STLP_BEGIN_NAMESPACE
  30. #if defined (_STLP_EXPOSE_GLOBALS_IMPLEMENTATION)
  31. _STLP_MOVE_TO_PRIV_NAMESPACE
  32. # define __PRIME_LIST_BODY { \
  33. 7ul, 23ul, \
  34. 53ul, 97ul, 193ul, 389ul, 769ul, \
  35. 1543ul, 3079ul, 6151ul, 12289ul, 24593ul, \
  36. 49157ul, 98317ul, 196613ul, 393241ul, 786433ul, \
  37. 1572869ul, 3145739ul, 6291469ul, 12582917ul, 25165843ul, \
  38. 50331653ul, 100663319ul, 201326611ul, 402653189ul, 805306457ul,\
  39. 1610612741ul, 3221225473ul, 4294967291ul \
  40. }
  41. template <class _Dummy>
  42. const size_t* _STLP_CALL
  43. _Stl_prime<_Dummy>::_S_primes(size_t &__size) {
  44. static const size_t _list[] = __PRIME_LIST_BODY;
  45. # ifndef __MWERKS__
  46. __size = sizeof(_list) / sizeof(_list[0]);
  47. # else
  48. __size = 30;
  49. # endif
  50. return _list;
  51. }
  52. template <class _Dummy>
  53. size_t _STLP_CALL
  54. _Stl_prime<_Dummy>::_S_max_nb_buckets() {
  55. size_t __size;
  56. const size_t* __first = _S_primes(__size);
  57. return *(__first + __size - 1);
  58. }
  59. template <class _Dummy>
  60. size_t _STLP_CALL
  61. _Stl_prime<_Dummy>::_S_next_size(size_t __n) {
  62. size_t __size;
  63. const size_t* __first = _S_primes(__size);
  64. const size_t* __last = __first + __size;
  65. const size_t* pos = __lower_bound(__first, __last, __n,
  66. __less((size_t*)0), __less((size_t*)0), (ptrdiff_t*)0);
  67. return (pos == __last ? *(__last - 1) : *pos);
  68. }
  69. template <class _Dummy>
  70. void _STLP_CALL
  71. _Stl_prime<_Dummy>::_S_prev_sizes(size_t __n, size_t const*&__begin, size_t const*&__pos) {
  72. size_t __size;
  73. __begin = _S_primes(__size);
  74. const size_t* __last = __begin + __size;
  75. __pos = __lower_bound(__begin, __last, __n,
  76. __less((size_t*)0), __less((size_t*)0), (ptrdiff_t*)0);
  77. if (__pos== __last)
  78. --__pos;
  79. else if (*__pos == __n) {
  80. if (__pos != __begin)
  81. --__pos;
  82. }
  83. }
  84. # undef __PRIME_LIST_BODY
  85. _STLP_MOVE_TO_STD_NAMESPACE
  86. #endif
  87. #if defined (_STLP_DEBUG)
  88. # define hashtable _STLP_NON_DBG_NAME(hashtable)
  89. _STLP_MOVE_TO_PRIV_NAMESPACE
  90. #endif
  91. // fbp: these defines are for outline methods definitions.
  92. // needed to definitions to be portable. Should not be used in method bodies.
  93. #if defined ( _STLP_NESTED_TYPE_PARAM_BUG )
  94. # define __size_type__ size_t
  95. # define size_type size_t
  96. # define value_type _Val
  97. # define key_type _Key
  98. # define __reference__ _Val&
  99. # define __iterator__ _Ht_iterator<_Val, _STLP_HEADER_TYPENAME _Traits::_NonConstTraits, \
  100. _Key, _HF, _ExK, _EqK, _All>
  101. # define __const_iterator__ _Ht_iterator<_Val, _STLP_HEADER_TYPENAME _Traits::_ConstTraits, \
  102. _Key, _HF, _ExK, _EqK, _All>
  103. #else
  104. # define __size_type__ _STLP_TYPENAME_ON_RETURN_TYPE hashtable<_Val, _Key, _HF, _Traits, _ExK, _EqK, _All>::size_type
  105. # define __reference__ _STLP_TYPENAME_ON_RETURN_TYPE hashtable<_Val, _Key, _HF, _Traits, _ExK, _EqK, _All>::reference
  106. # define __iterator__ _STLP_TYPENAME_ON_RETURN_TYPE hashtable<_Val, _Key, _HF, _Traits, _ExK, _EqK, _All>::iterator
  107. # define __const_iterator__ _STLP_TYPENAME_ON_RETURN_TYPE hashtable<_Val, _Key, _HF, _Traits, _ExK, _EqK, _All>::const_iterator
  108. #endif
  109. /*
  110. * This method is too difficult to implement for hashtable that do not
  111. * require a sorted operation on the stored type.
  112. template <class _Val, class _Key, class _HF,
  113. class _Traits, class _ExK, class _EqK, class _All>
  114. bool hashtable<_Val,_Key,_HF,_Traits,_ExK,_EqK,_All>::_M_equal(
  115. const hashtable<_Val,_Key,_HF,_Traits,_ExK,_EqK,_All>& __ht1,
  116. const hashtable<_Val,_Key,_HF,_Traits,_ExK,_EqK,_All>& __ht2) {
  117. return __ht1._M_buckets == __ht2._M_buckets &&
  118. __ht1._M_elems == __ht2._M_elems;
  119. }
  120. */
  121. /* Returns the iterator before the first iterator of the bucket __n and set
  122. * __n to the first previous bucket having the same first iterator as bucket
  123. * __n.
  124. */
  125. template <class _Val, class _Key, class _HF,
  126. class _Traits, class _ExK, class _EqK, class _All>
  127. __iterator__
  128. hashtable<_Val,_Key,_HF,_Traits,_ExK,_EqK,_All>
  129. ::_M_before_begin(size_type &__n) const {
  130. return _S_before_begin(_M_elems, _M_buckets, __n);
  131. }
  132. template <class _Val, class _Key, class _HF,
  133. class _Traits, class _ExK, class _EqK, class _All>
  134. __iterator__
  135. hashtable<_Val,_Key,_HF,_Traits,_ExK,_EqK,_All>
  136. ::_S_before_begin(const _ElemsCont& __elems, const _BucketVector& __buckets,
  137. size_type &__n) {
  138. _ElemsCont &__mutable_elems = __CONST_CAST(_ElemsCont&, __elems);
  139. typename _BucketVector::const_iterator __bpos(__buckets.begin() + __n);
  140. _ElemsIte __pos(*__bpos);
  141. if (__pos == __mutable_elems.begin()) {
  142. __n = 0;
  143. return __mutable_elems.before_begin();
  144. }
  145. typename _BucketVector::const_iterator __bcur(__bpos);
  146. _BucketType *__pos_node = __pos._M_node;
  147. for (--__bcur; __pos_node == *__bcur; --__bcur);
  148. __n = __bcur - __buckets.begin() + 1;
  149. _ElemsIte __cur(*__bcur);
  150. _ElemsIte __prev = __cur++;
  151. for (; __cur != __pos; ++__prev, ++__cur);
  152. return __prev;
  153. }
  154. template <class _Val, class _Key, class _HF,
  155. class _Traits, class _ExK, class _EqK, class _All>
  156. __iterator__
  157. hashtable<_Val,_Key,_HF,_Traits,_ExK,_EqK,_All>
  158. ::_M_insert_noresize(size_type __n, const value_type& __obj) {
  159. //We always insert this element as 1st in the bucket to not break
  160. //the elements order as equal elements must be kept next to each other.
  161. size_type __prev = __n;
  162. _ElemsIte __pos = _M_before_begin(__prev)._M_ite;
  163. fill(_M_buckets.begin() + __prev, _M_buckets.begin() + __n + 1,
  164. _M_elems.insert_after(__pos, __obj)._M_node);
  165. ++_M_num_elements;
  166. return iterator(_ElemsIte(_M_buckets[__n]));
  167. }
  168. template <class _Val, class _Key, class _HF,
  169. class _Traits, class _ExK, class _EqK, class _All>
  170. pair<__iterator__, bool>
  171. hashtable<_Val,_Key,_HF,_Traits,_ExK,_EqK,_All>
  172. ::insert_unique_noresize(const value_type& __obj) {
  173. const size_type __n = _M_bkt_num(__obj);
  174. _ElemsIte __cur(_M_buckets[__n]);
  175. _ElemsIte __last(_M_buckets[__n + 1]);
  176. if (__cur != __last) {
  177. for (; __cur != __last; ++__cur) {
  178. if (_M_equals(_M_get_key(*__cur), _M_get_key(__obj))) {
  179. //We check that equivalent keys have equals hash code as otherwise, on resize,
  180. //equivalent value might not be in the same bucket
  181. _STLP_ASSERT(_M_hash(_M_get_key(*__cur)) == _M_hash(_M_get_key(__obj)))
  182. return pair<iterator, bool>(iterator(__cur), false);
  183. }
  184. }
  185. /* Here we do not rely on the _M_insert_noresize method as we know
  186. * that we cannot break element orders, elements are unique, and
  187. * insertion after the first bucket element is faster than what is
  188. * done in _M_insert_noresize.
  189. */
  190. __cur = _M_elems.insert_after(_ElemsIte(_M_buckets[__n]), __obj);
  191. ++_M_num_elements;
  192. return pair<iterator, bool>(iterator(__cur), true);
  193. }
  194. return pair<iterator, bool>(_M_insert_noresize(__n, __obj), true);
  195. }
  196. template <class _Val, class _Key, class _HF,
  197. class _Traits, class _ExK, class _EqK, class _All>
  198. __iterator__
  199. hashtable<_Val,_Key,_HF,_Traits,_ExK,_EqK,_All>
  200. ::insert_equal_noresize(const value_type& __obj) {
  201. const size_type __n = _M_bkt_num(__obj);
  202. {
  203. _ElemsIte __cur(_M_buckets[__n]);
  204. _ElemsIte __last(_M_buckets[__n + 1]);
  205. for (; __cur != __last; ++__cur) {
  206. if (_M_equals(_M_get_key(*__cur), _M_get_key(__obj))) {
  207. //We check that equivalent keys have equals hash code as otherwise, on resize,
  208. //equivalent value might not be in the same bucket
  209. _STLP_ASSERT(_M_hash(_M_get_key(*__cur)) == _M_hash(_M_get_key(__obj)))
  210. ++_M_num_elements;
  211. return _M_elems.insert_after(__cur, __obj);
  212. }
  213. }
  214. }
  215. return _M_insert_noresize(__n, __obj);
  216. }
  217. template <class _Val, class _Key, class _HF,
  218. class _Traits, class _ExK, class _EqK, class _All>
  219. __reference__
  220. hashtable<_Val,_Key,_HF,_Traits,_ExK,_EqK,_All>
  221. ::_M_insert(const value_type& __obj) {
  222. _M_enlarge(_M_num_elements + 1);
  223. return *insert_unique_noresize(__obj).first;
  224. }
  225. template <class _Val, class _Key, class _HF,
  226. class _Traits, class _ExK, class _EqK, class _All>
  227. __size_type__
  228. hashtable<_Val,_Key,_HF,_Traits,_ExK,_EqK,_All>
  229. ::erase(const key_type& __key) {
  230. const size_type __n = _M_bkt_num_key(__key);
  231. _ElemsIte __cur(_M_buckets[__n]);
  232. _ElemsIte __last(_M_buckets[__n + 1]);
  233. if (__cur == __last)
  234. return 0;
  235. size_type __erased = 0;
  236. if (_M_equals(_M_get_key(*__cur), __key)) {
  237. //We look for the pos before __cur:
  238. size_type __prev_b = __n;
  239. _ElemsIte __prev = _M_before_begin(__prev_b)._M_ite;
  240. do {
  241. __cur = _M_elems.erase_after(__prev);
  242. ++__erased;
  243. } while ((__cur != __last) && _M_equals(_M_get_key(*__cur), __key));
  244. fill(_M_buckets.begin() + __prev_b, _M_buckets.begin() + __n + 1, __cur._M_node);
  245. }
  246. else {
  247. _ElemsIte __prev = __cur++;
  248. for (; __cur != __last; ++__prev, ++__cur) {
  249. if (_M_equals(_M_get_key(*__cur), __key)) {
  250. do {
  251. __cur = _M_elems.erase_after(__prev);
  252. ++__erased;
  253. } while ((__cur != __last) && _M_equals(_M_get_key(*__cur), __key));
  254. break;
  255. }
  256. }
  257. }
  258. _M_num_elements -= __erased;
  259. _M_reduce();
  260. return __erased;
  261. }
  262. template <class _Val, class _Key, class _HF,
  263. class _Traits, class _ExK, class _EqK, class _All>
  264. void hashtable<_Val,_Key,_HF,_Traits,_ExK,_EqK,_All>
  265. ::erase(const_iterator __it) {
  266. const size_type __n = _M_bkt_num(*__it);
  267. _ElemsIte __cur(_M_buckets[__n]);
  268. size_type __erased = 0;
  269. if (__cur == __it._M_ite) {
  270. size_type __prev_b = __n;
  271. _ElemsIte __prev = _M_before_begin(__prev_b)._M_ite;
  272. fill(_M_buckets.begin() + __prev_b, _M_buckets.begin() + __n + 1,
  273. _M_elems.erase_after(__prev)._M_node);
  274. ++__erased;
  275. }
  276. else {
  277. _ElemsIte __prev = __cur++;
  278. _ElemsIte __last(_M_buckets[__n + 1]);
  279. for (; __cur != __last; ++__prev, ++__cur) {
  280. if (__cur == __it._M_ite) {
  281. _M_elems.erase_after(__prev);
  282. ++__erased;
  283. break;
  284. }
  285. }
  286. }
  287. _M_num_elements -= __erased;
  288. _M_reduce();
  289. }
  290. template <class _Val, class _Key, class _HF,
  291. class _Traits, class _ExK, class _EqK, class _All>
  292. void hashtable<_Val,_Key,_HF,_Traits,_ExK,_EqK,_All>
  293. ::erase(const_iterator __first, const_iterator __last) {
  294. if (__first == __last)
  295. return;
  296. size_type __f_bucket = _M_bkt_num(*__first);
  297. size_type __l_bucket = __last != end() ? _M_bkt_num(*__last) : (_M_buckets.size() - 1);
  298. _ElemsIte __cur(_M_buckets[__f_bucket]);
  299. _ElemsIte __prev;
  300. if (__cur == __first._M_ite) {
  301. __prev = _M_before_begin(__f_bucket)._M_ite;
  302. }
  303. else {
  304. _ElemsIte __last(_M_buckets[++__f_bucket]);
  305. __prev = __cur++;
  306. for (; (__cur != __last) && (__cur != __first._M_ite); ++__prev, ++__cur);
  307. }
  308. size_type __erased = 0;
  309. //We do not use the slist::erase_after method taking a range to count the
  310. //number of erased elements:
  311. while (__cur != __last._M_ite) {
  312. __cur = _M_elems.erase_after(__prev);
  313. ++__erased;
  314. }
  315. fill(_M_buckets.begin() + __f_bucket, _M_buckets.begin() + __l_bucket + 1, __cur._M_node);
  316. _M_num_elements -= __erased;
  317. _M_reduce();
  318. }
  319. template <class _Val, class _Key, class _HF,
  320. class _Traits, class _ExK, class _EqK, class _All>
  321. void hashtable<_Val,_Key,_HF,_Traits,_ExK,_EqK,_All>
  322. ::rehash(size_type __num_buckets_hint) {
  323. if (bucket_count() >= __num_buckets_hint) {
  324. // We are trying to reduce number of buckets, we have to validate it:
  325. size_type __limit_num_buckets = (size_type)((float)size() / max_load_factor());
  326. if (__num_buckets_hint < __limit_num_buckets) {
  327. // Targetted number of buckets __num_buckets_hint would break
  328. // load_factor() <= max_load_factor() rule.
  329. return;
  330. }
  331. }
  332. _M_rehash(__num_buckets_hint);
  333. }
  334. template <class _Val, class _Key, class _HF,
  335. class _Traits, class _ExK, class _EqK, class _All>
  336. void hashtable<_Val,_Key,_HF,_Traits,_ExK,_EqK,_All>
  337. ::_M_enlarge(size_type __to_size) {
  338. size_type __num_buckets = bucket_count();
  339. size_type __num_buckets_hint = (size_type)((float)__to_size / max_load_factor());
  340. if (__num_buckets_hint <= __num_buckets) {
  341. return;
  342. }
  343. __num_buckets = _STLP_PRIV _Stl_prime_type::_S_next_size(__num_buckets_hint);
  344. _M_rehash(__num_buckets);
  345. }
  346. template <class _Val, class _Key, class _HF,
  347. class _Traits, class _ExK, class _EqK, class _All>
  348. void hashtable<_Val,_Key,_HF,_Traits,_ExK,_EqK,_All>
  349. ::_M_reduce() {
  350. size_type __num_buckets = bucket_count();
  351. // We only try to reduce the hashtable if the theorical load factor
  352. // is lower than a fraction of the max load factor:
  353. // 4 factor is coming from the fact that prime number list is almost a
  354. // geometrical suite with reason 2, as we try to jump 2 levels is means
  355. // a 4 factor.
  356. if ((float)size() / (float)__num_buckets > max_load_factor() / 4.0f)
  357. return;
  358. const size_type *__first;
  359. const size_type *__prev;
  360. _STLP_PRIV _Stl_prime_type::_S_prev_sizes(__num_buckets, __first, __prev);
  361. /* We are only going to reduce number of buckets if moving to yet the previous number
  362. * of buckets in the prime numbers would respect the load rule. Otherwise algorithm
  363. * successively removing and adding an element would each time perform an expensive
  364. * rehash operation. */
  365. const size_type *__prev_prev = __prev;
  366. if (__prev_prev != __first) {
  367. --__prev_prev;
  368. if ((float)size() / (float)*__prev_prev > max_load_factor())
  369. return;
  370. }
  371. else {
  372. if (*__prev >= __num_buckets)
  373. return;
  374. }
  375. // Can we reduce further:
  376. while (__prev_prev != __first) {
  377. --__prev_prev;
  378. if ((float)size() / (float)*__prev_prev > max_load_factor())
  379. // We cannot reduce further.
  380. break;
  381. --__prev;
  382. }
  383. _M_rehash(*__prev);
  384. }
  385. template <class _Val, class _Key, class _HF,
  386. class _Traits, class _ExK, class _EqK, class _All>
  387. void hashtable<_Val,_Key,_HF,_Traits,_ExK,_EqK,_All>
  388. ::_M_resize() {
  389. if (load_factor() > max_load_factor()) {
  390. // We have to enlarge
  391. _M_enlarge(size());
  392. }
  393. else {
  394. // We can try to reduce size:
  395. _M_reduce();
  396. }
  397. }
  398. template <class _Val, class _Key, class _HF,
  399. class _Traits, class _ExK, class _EqK, class _All>
  400. void hashtable<_Val,_Key,_HF,_Traits,_ExK,_EqK,_All>
  401. ::_M_rehash(size_type __num_buckets) {
  402. #if defined (_STLP_DEBUG)
  403. _M_check();
  404. #endif
  405. _ElemsCont __tmp_elems(_M_elems.get_allocator());
  406. _BucketVector __tmp(__num_buckets + 1, __STATIC_CAST(_BucketType*, 0), _M_buckets.get_allocator());
  407. _ElemsIte __cur, __last(_M_elems.end());
  408. while (!_M_elems.empty()) {
  409. __cur = _M_elems.begin();
  410. size_type __new_bucket = _M_bkt_num(*__cur, __num_buckets);
  411. _ElemsIte __ite(__cur), __before_ite(__cur);
  412. for (++__ite;
  413. __ite != __last && _M_equals(_M_get_key(*__cur), _M_get_key(*__ite));
  414. ++__ite, ++__before_ite);
  415. size_type __prev_bucket = __new_bucket;
  416. _ElemsIte __prev = _S_before_begin(__tmp_elems, __tmp, __prev_bucket)._M_ite;
  417. __tmp_elems.splice_after(__prev, _M_elems, _M_elems.before_begin(), __before_ite);
  418. fill(__tmp.begin() + __prev_bucket, __tmp.begin() + __new_bucket + 1, __cur._M_node);
  419. }
  420. _M_elems.swap(__tmp_elems);
  421. _M_buckets.swap(__tmp);
  422. }
  423. #if defined (_STLP_DEBUG)
  424. template <class _Val, class _Key, class _HF,
  425. class _Traits, class _ExK, class _EqK, class _All>
  426. void hashtable<_Val,_Key,_HF,_Traits,_ExK,_EqK,_All>::_M_check() const {
  427. //We check that hash code of stored keys haven't change and also that equivalent
  428. //relation hasn't been modified
  429. size_t __num_buckets = bucket_count();
  430. for (size_t __b = 0; __b < __num_buckets; ++__b) {
  431. _ElemsIte __cur(_M_buckets[__b]), __last(_M_buckets[__b + 1]);
  432. _ElemsIte __fst(__cur), __snd(__cur);
  433. for (; __cur != __last; ++__cur) {
  434. _STLP_ASSERT( _M_bkt_num(*__cur, __num_buckets) == __b )
  435. _STLP_ASSERT( !_M_equals(_M_get_key(*__fst), _M_get_key(*__cur)) || _M_equals(_M_get_key(*__snd), _M_get_key(*__cur)) )
  436. if (__fst != __snd)
  437. ++__fst;
  438. if (__snd != __cur)
  439. ++__snd;
  440. }
  441. }
  442. }
  443. #endif
  444. template <class _Val, class _Key, class _HF,
  445. class _Traits, class _ExK, class _EqK, class _All>
  446. void hashtable<_Val,_Key,_HF,_Traits,_ExK,_EqK,_All>::clear() {
  447. _M_elems.clear();
  448. _M_buckets.assign(_M_buckets.size(), __STATIC_CAST(_BucketType*, 0));
  449. _M_num_elements = 0;
  450. }
  451. template <class _Val, class _Key, class _HF,
  452. class _Traits, class _ExK, class _EqK, class _All>
  453. void hashtable<_Val,_Key,_HF,_Traits,_ExK,_EqK,_All>
  454. ::_M_copy_from(const hashtable<_Val,_Key,_HF,_Traits,_ExK,_EqK,_All>& __ht) {
  455. _M_elems.clear();
  456. _M_elems.insert(_M_elems.end(), __ht._M_elems.begin(), __ht._M_elems.end());
  457. _M_buckets.resize(__ht._M_buckets.size());
  458. _ElemsConstIte __src(__ht._M_elems.begin()), __src_end(__ht._M_elems.end());
  459. _ElemsIte __dst(_M_elems.begin());
  460. typename _BucketVector::const_iterator __src_b(__ht._M_buckets.begin()),
  461. __src_end_b(__ht._M_buckets.end());
  462. typename _BucketVector::iterator __dst_b(_M_buckets.begin()), __dst_end_b(_M_buckets.end());
  463. for (; __src != __src_end; ++__src, ++__dst) {
  464. for (; __src_b != __src_end_b; ++__src_b, ++__dst_b) {
  465. if (*__src_b == __src._M_node) {
  466. *__dst_b = __dst._M_node;
  467. }
  468. else
  469. break;
  470. }
  471. }
  472. fill(__dst_b, __dst_end_b, __STATIC_CAST(_BucketType*, 0));
  473. _M_num_elements = __ht._M_num_elements;
  474. _M_max_load_factor = __ht._M_max_load_factor;
  475. }
  476. #undef __iterator__
  477. #undef const_iterator
  478. #undef __size_type__
  479. #undef __reference__
  480. #undef size_type
  481. #undef value_type
  482. #undef key_type
  483. #undef __stl_num_primes
  484. #if defined (_STLP_DEBUG)
  485. # undef hashtable
  486. _STLP_MOVE_TO_STD_NAMESPACE
  487. #endif
  488. _STLP_END_NAMESPACE
  489. #endif /* _STLP_HASHTABLE_C */
  490. // Local Variables:
  491. // mode:C++
  492. // End: