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