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