int lookup (K s, unsigned int initial_hash)
{
int sz =dict_arr_.size ();
- int i = initial_hash % sz;
+ initial_hash = initial_hash % sz;
+ int i;
int j = 0;
while (j <= sz/2) {
+ i = (initial_hash + j*j) % sz;
+
if (dict_arr_[i].free_b_)
return i;
return i;
j++;
- i = (i + j*j) % sz;
}
}
/**
- Find and return element. If #s# is not in the table, create an entry in the table, and init
- */
+ Find and return element. If #s# is not in the table, create an
+ entry in the table, and init */
V& elem (K s)
{
int l;
fixed_p_->dict_arr_[l].key_ = s;
return fixed_p_->dict_arr_[l].value_;
}
+ bool try_retrieve (K k, V *v)
+ {
+ int l = fixed_p_->lookup (k, (*hash_func_)(k));
+ if (l < 0 || fixed_p_->dict_arr_[l].free_b_)
+ return false;
+ else
+ {
+ *v = fixed_p_->dict_arr_[l].value_;
+ return true;
+ }
+ }
V elem (K s) const
{
return const_elem (s);