Project

General

Profile

Feature #15331 » 0001-Add-st_update_with_hash.patch

v6 - alanwu (Alan Wu), 11/26/2018 04:24 PM

View differences:

st.c
{
}
ALWAYS_INLINE(static inline int
st_update_with_hash_inlined(st_table *tab, st_data_t key, st_data_t hash,
st_update_callback_func *func, st_data_t arg));
/* Find entry with KEY in table TAB, call FUNC with the key and the
value of the found entry, and non-zero as the 3rd argument. If the
entry is not found, call FUNC with KEY, and 2 zero arguments. If
the call returns ST_CONTINUE, the table will have an entry with key
and value returned by FUNC through the 1st and 2nd parameters. If
the call of FUNC returns ST_DELETE, the table will not have entry
with KEY. The function returns flag of that the entry with KEY was
value of the found entry, and non-zero as the 3rd argument. If the
entry is not found, call FUNC with KEY, and zero as the 3rd argument.
If the call returns ST_CONTINUE, the table will have an entry with key
and value returned by FUNC through the 1st and 2nd parameter.
If the call of FUNC returns ST_DELETE, the table will not have entry
with KEY. The function returns flag of that the entry with KEY was
in the table before the call. */
int
st_update(st_table *tab, st_data_t key,
st_update_callback_func *func, st_data_t arg)
{
st_hash_t hash = do_hash(key, tab);
return st_update_with_hash_inlined(tab, key, hash, func, arg);
}
/* st_update, but with caller-provided hash code for KEY. */
int
st_update_with_hash(st_table *tab, st_data_t key, st_index_t hash,
st_update_callback_func *func, st_data_t arg)
{
/* This remapping is also done in do_hash() */
st_hash_t remapped_hash = (hash == RESERVED_HASH_VAL) ? RESERVED_HASH_SUBSTITUTION_VAL : hash;
return st_update_with_hash_inlined(tab, key, remapped_hash, func, arg);
}
static inline int
st_update_with_hash_inlined(st_table *tab, st_data_t key, st_hash_t hash,
st_update_callback_func *func, st_data_t arg)
{
st_table_entry *entry = NULL; /* to avoid uninitialized value warning */
st_index_t bin = 0; /* Ditto */
......
st_data_t value = 0, old_key;
st_index_t check;
int retval, existing;
st_hash_t hash = do_hash(key, tab);
retry:
entries = tab->entries;
(7-7/8)