Logo Search packages:      
Sourcecode: maq version File versions

template<class valtype_t>
bool hash_map_char< valtype_t >::resize ( hashint_t  new_capacity  )  [inline]

resize the hash table and perform rehashing

Reimplemented from __lh3_hash_base_class< char * >.

Definition at line 601 of file stdhash.hh.

Referenced by hash_map_char< unsigned long long >::rehash().

                                                 {
            __lh3_flag_t *new_flags;
            if (!resize_aux1(&new_capacity, &new_flags)) return false;
            vals = (valtype_t*)realloc(vals, sizeof(valtype_t) * new_capacity);
            if (vals == 0) { // insufficient enough memory?
			::free(new_flags);
                  return false;
            }
            for (hashint_t j = 0; j != this->n_capacity; ++j) {
                  if (__lh3_isboth(this->flags, j) == 0) {
                        char *key = this->keys[j]; // take out the key
                        valtype_t val = vals[j];
                        __lh3_set_isdel_true(this->flags, j); // mark "deleted"
                        while (1) {
                              hashint_t inc, k, i;
                              k = __lh3_hash_fun(key);
                              i = k % new_capacity; // calculate the new position
                              inc = 1 + k % (new_capacity - 1);
                              while (!__lh3_isempty(new_flags, i)) {
                                    if (i + inc >= new_capacity) i = i + inc - new_capacity;
                                    else i += inc;
                              }
                              __lh3_set_isempty_false(new_flags, i);
                              if (i < this->n_capacity && __lh3_isboth(this->flags, i) == 0) { // something is here
                                    { char* tmp = this->keys[i]; this->keys[i] = key; key = tmp; } // take it out
                                    { valtype_t tmp = vals[i]; vals[i] = val; val = tmp; } // take it out
                                    __lh3_set_isdel_true(this->flags, i);
                              } else { // clear
                                    this->keys[i] = key;
                                    vals[i] = val;
                                    break;
                              }
                        }
                  }
            }
            resize_aux2(new_capacity, new_flags);
            return true;
      }


Generated by  Doxygen 1.6.0   Back to index