mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
remove unnecessary variable
* st.c (do_hash): remove unnecessary variable and cast. * hash.c, numeric.c, st.c: adjust style and indent. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56991 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
1816e39351
commit
1e95f9da88
3 changed files with 101 additions and 58 deletions
16
hash.c
16
hash.c
|
@ -217,22 +217,26 @@ obj_any_hash(VALUE obj)
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline st_index_t
|
static inline st_index_t
|
||||||
any_hash_weak(VALUE a, st_index_t (*other_func)(VALUE)) {
|
any_hash_weak(VALUE a, st_index_t (*other_func)(VALUE))
|
||||||
|
{
|
||||||
return any_hash_general(a, FALSE, other_func);
|
return any_hash_general(a, FALSE, other_func);
|
||||||
}
|
}
|
||||||
|
|
||||||
static st_index_t
|
static st_index_t
|
||||||
rb_any_hash_weak(VALUE a) {
|
rb_any_hash_weak(VALUE a)
|
||||||
|
{
|
||||||
return any_hash_weak(a, obj_any_hash);
|
return any_hash_weak(a, obj_any_hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline st_index_t
|
static inline st_index_t
|
||||||
any_hash(VALUE a, st_index_t (*other_func)(VALUE)) {
|
any_hash(VALUE a, st_index_t (*other_func)(VALUE))
|
||||||
|
{
|
||||||
return any_hash_general(a, TRUE, other_func);
|
return any_hash_general(a, TRUE, other_func);
|
||||||
}
|
}
|
||||||
|
|
||||||
static st_index_t
|
static st_index_t
|
||||||
rb_any_hash(VALUE a) {
|
rb_any_hash(VALUE a)
|
||||||
|
{
|
||||||
return any_hash(a, obj_any_hash);
|
return any_hash(a, obj_any_hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -246,7 +250,7 @@ static const uint64_t prime2 = 0xcdb32970830fcaa1ULL;
|
||||||
|
|
||||||
|
|
||||||
static inline uint64_t
|
static inline uint64_t
|
||||||
mult_and_mix (uint64_t m1, uint64_t m2)
|
mult_and_mix(uint64_t m1, uint64_t m2)
|
||||||
{
|
{
|
||||||
#if defined(__GNUC__) && UINT_MAX != ULONG_MAX
|
#if defined(__GNUC__) && UINT_MAX != ULONG_MAX
|
||||||
__uint128_t r = (__uint128_t) m1 * (__uint128_t) m2;
|
__uint128_t r = (__uint128_t) m1 * (__uint128_t) m2;
|
||||||
|
@ -263,7 +267,7 @@ mult_and_mix (uint64_t m1, uint64_t m2)
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline uint64_t
|
static inline uint64_t
|
||||||
key64_hash (uint64_t key, uint32_t seed)
|
key64_hash(uint64_t key, uint32_t seed)
|
||||||
{
|
{
|
||||||
return mult_and_mix(key + seed, prime1);
|
return mult_and_mix(key + seed, prime1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1453,7 +1453,7 @@ flo_hash(VALUE num)
|
||||||
VALUE
|
VALUE
|
||||||
rb_dbl_hash(double d)
|
rb_dbl_hash(double d)
|
||||||
{
|
{
|
||||||
return LONG2FIX(rb_dbl_long_hash (d));
|
return LONG2FIX(rb_dbl_long_hash(d));
|
||||||
}
|
}
|
||||||
|
|
||||||
VALUE
|
VALUE
|
||||||
|
|
141
st.c
141
st.c
|
@ -303,13 +303,9 @@ struct st_features features[] = {
|
||||||
|
|
||||||
/* Return hash value of KEY for table TAB. */
|
/* Return hash value of KEY for table TAB. */
|
||||||
static inline st_hash_t
|
static inline st_hash_t
|
||||||
do_hash(st_data_t key, st_table *tab) {
|
do_hash(st_data_t key, st_table *tab)
|
||||||
st_index_t h = (st_index_t)(tab->curr_hash)(key);
|
{
|
||||||
#if SIZEOF_INT == SIZEOF_VOIDP
|
st_hash_t hash = (st_hash_t)(tab->type->hash)(key);
|
||||||
st_hash_t hash = h;
|
|
||||||
#else
|
|
||||||
st_hash_t hash = h;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* RESERVED_HASH_VAL is used for a deleted entry. Map it into
|
/* RESERVED_HASH_VAL is used for a deleted entry. Map it into
|
||||||
another value. Such mapping should be extremely rare. */
|
another value. Such mapping should be extremely rare. */
|
||||||
|
@ -329,7 +325,8 @@ do_hash(st_data_t key, st_table *tab) {
|
||||||
|
|
||||||
/* Return smallest n >= MINIMAL_POWER2 such 2^n > SIZE. */
|
/* Return smallest n >= MINIMAL_POWER2 such 2^n > SIZE. */
|
||||||
static int
|
static int
|
||||||
get_power2(st_index_t size) {
|
get_power2(st_index_t size)
|
||||||
|
{
|
||||||
unsigned int n;
|
unsigned int n;
|
||||||
|
|
||||||
for (n = 0; size != 0; n++)
|
for (n = 0; size != 0; n++)
|
||||||
|
@ -347,7 +344,8 @@ get_power2(st_index_t size) {
|
||||||
/* Return value of N-th bin in array BINS of table with bins size
|
/* Return value of N-th bin in array BINS of table with bins size
|
||||||
index S. */
|
index S. */
|
||||||
static inline st_index_t
|
static inline st_index_t
|
||||||
get_bin(st_index_t *bins, int s, st_index_t n) {
|
get_bin(st_index_t *bins, int s, st_index_t n)
|
||||||
|
{
|
||||||
return (s == 0 ? ((unsigned char *) bins)[n]
|
return (s == 0 ? ((unsigned char *) bins)[n]
|
||||||
: s == 1 ? ((unsigned short *) bins)[n]
|
: s == 1 ? ((unsigned short *) bins)[n]
|
||||||
: s == 2 ? ((unsigned int *) bins)[n]
|
: s == 2 ? ((unsigned int *) bins)[n]
|
||||||
|
@ -357,7 +355,8 @@ get_bin(st_index_t *bins, int s, st_index_t n) {
|
||||||
/* Set up N-th bin in array BINS of table with bins size index S to
|
/* Set up N-th bin in array BINS of table with bins size index S to
|
||||||
value V. */
|
value V. */
|
||||||
static inline void
|
static inline void
|
||||||
set_bin(st_index_t *bins, int s, st_index_t n, st_index_t v) {
|
set_bin(st_index_t *bins, int s, st_index_t n, st_index_t v)
|
||||||
|
{
|
||||||
if (s == 0) ((unsigned char *) bins)[n] = (unsigned char) v;
|
if (s == 0) ((unsigned char *) bins)[n] = (unsigned char) v;
|
||||||
else if (s == 1) ((unsigned short *) bins)[n] = (unsigned short) v;
|
else if (s == 1) ((unsigned short *) bins)[n] = (unsigned short) v;
|
||||||
else if (s == 2) ((unsigned int *) bins)[n] = (unsigned int) v;
|
else if (s == 2) ((unsigned int *) bins)[n] = (unsigned int) v;
|
||||||
|
@ -410,44 +409,51 @@ set_bin(st_index_t *bins, int s, st_index_t n, st_index_t v) {
|
||||||
|
|
||||||
/* Return bin size index of table TAB. */
|
/* Return bin size index of table TAB. */
|
||||||
static inline unsigned int
|
static inline unsigned int
|
||||||
get_size_ind(const st_table *tab) {
|
get_size_ind(const st_table *tab)
|
||||||
|
{
|
||||||
return tab->size_ind;
|
return tab->size_ind;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return the number of allocated bins of table TAB. */
|
/* Return the number of allocated bins of table TAB. */
|
||||||
static inline st_index_t
|
static inline st_index_t
|
||||||
get_bins_num(const st_table *tab) {
|
get_bins_num(const st_table *tab)
|
||||||
|
{
|
||||||
return ((st_index_t) 1)<<tab->bin_power;
|
return ((st_index_t) 1)<<tab->bin_power;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return mask for a bin index in table TAB. */
|
/* Return mask for a bin index in table TAB. */
|
||||||
static inline st_index_t
|
static inline st_index_t
|
||||||
bins_mask(const st_table *tab) {
|
bins_mask(const st_table *tab)
|
||||||
|
{
|
||||||
return get_bins_num(tab) - 1;
|
return get_bins_num(tab) - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return the index of table TAB bin corresponding to
|
/* Return the index of table TAB bin corresponding to
|
||||||
HASH_VALUE. */
|
HASH_VALUE. */
|
||||||
static inline st_index_t
|
static inline st_index_t
|
||||||
hash_bin(st_hash_t hash_value, st_table *tab) {
|
hash_bin(st_hash_t hash_value, st_table *tab)
|
||||||
|
{
|
||||||
return hash_value & bins_mask(tab);
|
return hash_value & bins_mask(tab);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return the number of allocated entries of table TAB. */
|
/* Return the number of allocated entries of table TAB. */
|
||||||
static inline st_index_t
|
static inline st_index_t
|
||||||
get_allocated_entries(const st_table *tab) {
|
get_allocated_entries(const st_table *tab)
|
||||||
|
{
|
||||||
return ((st_index_t) 1)<<tab->entry_power;
|
return ((st_index_t) 1)<<tab->entry_power;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return size of the allocated bins of table TAB. */
|
/* Return size of the allocated bins of table TAB. */
|
||||||
static inline st_index_t
|
static inline st_index_t
|
||||||
bins_size(const st_table *tab) {
|
bins_size(const st_table *tab)
|
||||||
|
{
|
||||||
return features[tab->entry_power].bins_words * sizeof (st_index_t);
|
return features[tab->entry_power].bins_words * sizeof (st_index_t);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Mark all bins of table TAB as empty. */
|
/* Mark all bins of table TAB as empty. */
|
||||||
static void
|
static void
|
||||||
initialize_bins(st_table *tab) {
|
initialize_bins(st_table *tab)
|
||||||
|
{
|
||||||
memset(tab->bins, 0, bins_size(tab));
|
memset(tab->bins, 0, bins_size(tab));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -466,7 +472,8 @@ make_tab_empty(st_table *tab)
|
||||||
/* Check the table T consistency. It can be extremely slow. So use
|
/* Check the table T consistency. It can be extremely slow. So use
|
||||||
it only for debugging. */
|
it only for debugging. */
|
||||||
static void
|
static void
|
||||||
st_check(st_table *tab) {
|
st_check(st_table *tab)
|
||||||
|
{
|
||||||
st_index_t d, e, i, n, p;
|
st_index_t d, e, i, n, p;
|
||||||
|
|
||||||
for (p = get_allocated_entries(tab), i = 0; p > 1; i++, p>>=1)
|
for (p = get_allocated_entries(tab), i = 0; p > 1; i++, p>>=1)
|
||||||
|
@ -544,7 +551,8 @@ stat_col(void)
|
||||||
entries. The real number of entries which the table can hold is
|
entries. The real number of entries which the table can hold is
|
||||||
the nearest power of two for SIZE. */
|
the nearest power of two for SIZE. */
|
||||||
st_table *
|
st_table *
|
||||||
st_init_table_with_size(const struct st_hash_type *type, st_index_t size) {
|
st_init_table_with_size(const struct st_hash_type *type, st_index_t size)
|
||||||
|
{
|
||||||
st_table *tab;
|
st_table *tab;
|
||||||
int n;
|
int n;
|
||||||
|
|
||||||
|
@ -591,53 +599,61 @@ st_init_table_with_size(const struct st_hash_type *type, st_index_t size) {
|
||||||
/* Create and return table with TYPE which can hold a minimal number
|
/* Create and return table with TYPE which can hold a minimal number
|
||||||
of entries (see comments for get_power2). */
|
of entries (see comments for get_power2). */
|
||||||
st_table *
|
st_table *
|
||||||
st_init_table(const struct st_hash_type *type) {
|
st_init_table(const struct st_hash_type *type)
|
||||||
|
{
|
||||||
return st_init_table_with_size(type, 0);
|
return st_init_table_with_size(type, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create and return table which can hold a minimal number of
|
/* Create and return table which can hold a minimal number of
|
||||||
numbers. */
|
numbers. */
|
||||||
st_table *
|
st_table *
|
||||||
st_init_numtable(void) {
|
st_init_numtable(void)
|
||||||
|
{
|
||||||
return st_init_table(&type_numhash);
|
return st_init_table(&type_numhash);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create and return table which can hold SIZE numbers. */
|
/* Create and return table which can hold SIZE numbers. */
|
||||||
st_table *
|
st_table *
|
||||||
st_init_numtable_with_size(st_index_t size) {
|
st_init_numtable_with_size(st_index_t size)
|
||||||
|
{
|
||||||
return st_init_table_with_size(&type_numhash, size);
|
return st_init_table_with_size(&type_numhash, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create and return table which can hold a minimal number of
|
/* Create and return table which can hold a minimal number of
|
||||||
strings. */
|
strings. */
|
||||||
st_table *
|
st_table *
|
||||||
st_init_strtable(void) {
|
st_init_strtable(void)
|
||||||
|
{
|
||||||
return st_init_table(&type_strhash);
|
return st_init_table(&type_strhash);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create and return table which can hold SIZE strings. */
|
/* Create and return table which can hold SIZE strings. */
|
||||||
st_table *
|
st_table *
|
||||||
st_init_strtable_with_size(st_index_t size) {
|
st_init_strtable_with_size(st_index_t size)
|
||||||
|
{
|
||||||
return st_init_table_with_size(&type_strhash, size);
|
return st_init_table_with_size(&type_strhash, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create and return table which can hold a minimal number of strings
|
/* Create and return table which can hold a minimal number of strings
|
||||||
whose character case is ignored. */
|
whose character case is ignored. */
|
||||||
st_table *
|
st_table *
|
||||||
st_init_strcasetable(void) {
|
st_init_strcasetable(void)
|
||||||
|
{
|
||||||
return st_init_table(&type_strcasehash);
|
return st_init_table(&type_strcasehash);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create and return table which can hold SIZE strings whose character
|
/* Create and return table which can hold SIZE strings whose character
|
||||||
case is ignored. */
|
case is ignored. */
|
||||||
st_table *
|
st_table *
|
||||||
st_init_strcasetable_with_size(st_index_t size) {
|
st_init_strcasetable_with_size(st_index_t size)
|
||||||
|
{
|
||||||
return st_init_table_with_size(&type_strcasehash, size);
|
return st_init_table_with_size(&type_strcasehash, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Make table TAB empty. */
|
/* Make table TAB empty. */
|
||||||
void
|
void
|
||||||
st_clear(st_table *tab) {
|
st_clear(st_table *tab)
|
||||||
|
{
|
||||||
make_tab_empty(tab);
|
make_tab_empty(tab);
|
||||||
tab->rebuilds_num++;
|
tab->rebuilds_num++;
|
||||||
#ifdef ST_DEBUG
|
#ifdef ST_DEBUG
|
||||||
|
@ -647,7 +663,8 @@ st_clear(st_table *tab) {
|
||||||
|
|
||||||
/* Free table TAB space. */
|
/* Free table TAB space. */
|
||||||
void
|
void
|
||||||
st_free_table(st_table *tab) {
|
st_free_table(st_table *tab)
|
||||||
|
{
|
||||||
if (tab->bins != NULL)
|
if (tab->bins != NULL)
|
||||||
free(tab->bins);
|
free(tab->bins);
|
||||||
free(tab->entries);
|
free(tab->entries);
|
||||||
|
@ -656,7 +673,8 @@ st_free_table(st_table *tab) {
|
||||||
|
|
||||||
/* Return byte size of memory allocted for table TAB. */
|
/* Return byte size of memory allocted for table TAB. */
|
||||||
size_t
|
size_t
|
||||||
st_memsize(const st_table *tab) {
|
st_memsize(const st_table *tab)
|
||||||
|
{
|
||||||
return(sizeof(st_table)
|
return(sizeof(st_table)
|
||||||
+ (tab->bins == NULL ? 0 : bins_size(tab))
|
+ (tab->bins == NULL ? 0 : bins_size(tab))
|
||||||
+ get_allocated_entries(tab) * sizeof(st_table_entry));
|
+ get_allocated_entries(tab) * sizeof(st_table_entry));
|
||||||
|
@ -677,7 +695,8 @@ find_table_bin_ptr_and_reserve(st_table *tab, st_hash_t *hash_value,
|
||||||
|
|
||||||
#ifdef HASH_LOG
|
#ifdef HASH_LOG
|
||||||
static void
|
static void
|
||||||
count_collision(const struct st_hash_type *type) {
|
count_collision(const struct st_hash_type *type)
|
||||||
|
{
|
||||||
collision.all++;
|
collision.all++;
|
||||||
if (type == &type_numhash) {
|
if (type == &type_numhash) {
|
||||||
collision.num++;
|
collision.num++;
|
||||||
|
@ -712,7 +731,8 @@ count_collision(const struct st_hash_type *type) {
|
||||||
Rebuilding is implemented by creation of a new table or by
|
Rebuilding is implemented by creation of a new table or by
|
||||||
compaction of the existing one. */
|
compaction of the existing one. */
|
||||||
static void
|
static void
|
||||||
rebuild_table(st_table *tab) {
|
rebuild_table(st_table *tab)
|
||||||
|
{
|
||||||
st_index_t i, ni, bound;
|
st_index_t i, ni, bound;
|
||||||
unsigned int size_ind;
|
unsigned int size_ind;
|
||||||
st_table *new_tab;
|
st_table *new_tab;
|
||||||
|
@ -797,7 +817,8 @@ rebuild_table(st_table *tab) {
|
||||||
|
|
||||||
For our case a is 5, c is 1, and m is a power of two. */
|
For our case a is 5, c is 1, and m is a power of two. */
|
||||||
static inline st_index_t
|
static inline st_index_t
|
||||||
secondary_hash(st_index_t ind, st_table *tab, st_index_t *perterb) {
|
secondary_hash(st_index_t ind, st_table *tab, st_index_t *perterb)
|
||||||
|
{
|
||||||
*perterb >>= 11;
|
*perterb >>= 11;
|
||||||
ind = (ind << 2) + ind + *perterb + 1;
|
ind = (ind << 2) + ind + *perterb + 1;
|
||||||
return hash_bin(ind, tab);
|
return hash_bin(ind, tab);
|
||||||
|
@ -807,8 +828,9 @@ secondary_hash(st_index_t ind, st_table *tab, st_index_t *perterb) {
|
||||||
search. Return the index of the found entry in array `entries`.
|
search. Return the index of the found entry in array `entries`.
|
||||||
If it is not found, return UNDEFINED_ENTRY_IND. */
|
If it is not found, return UNDEFINED_ENTRY_IND. */
|
||||||
static inline st_index_t
|
static inline st_index_t
|
||||||
find_entry(st_table *tab, st_hash_t hash_value, st_data_t key) {
|
find_entry(st_table *tab, st_hash_t hash_value, st_data_t key)
|
||||||
st_index_t i, bound;
|
{
|
||||||
|
st_index_t i, bound;
|
||||||
st_table_entry *entries;
|
st_table_entry *entries;
|
||||||
|
|
||||||
bound = tab->entries_bound;
|
bound = tab->entries_bound;
|
||||||
|
@ -828,7 +850,8 @@ find_entry(st_table *tab, st_hash_t hash_value, st_data_t key) {
|
||||||
/* Return index of entry with HASH_VALUE and KEY in table TAB. If
|
/* Return index of entry with HASH_VALUE and KEY in table TAB. If
|
||||||
there is no such entry, return UNDEFINED_ENTRY_IND. */
|
there is no such entry, return UNDEFINED_ENTRY_IND. */
|
||||||
static st_index_t
|
static st_index_t
|
||||||
find_table_entry_ind(st_table *tab, st_hash_t hash_value, st_data_t key) {
|
find_table_entry_ind(st_table *tab, st_hash_t hash_value, st_data_t key)
|
||||||
|
{
|
||||||
st_index_t ind;
|
st_index_t ind;
|
||||||
#ifdef QUADRATIC_PROBE
|
#ifdef QUADRATIC_PROBE
|
||||||
st_index_t d;
|
st_index_t d;
|
||||||
|
@ -868,7 +891,8 @@ find_table_entry_ind(st_table *tab, st_hash_t hash_value, st_data_t key) {
|
||||||
with HASH_VALUE and KEY. If there is no such bin, return
|
with HASH_VALUE and KEY. If there is no such bin, return
|
||||||
UNDEFINED_BIN_IND. */
|
UNDEFINED_BIN_IND. */
|
||||||
static st_index_t
|
static st_index_t
|
||||||
find_table_bin_ind(st_table *tab, st_hash_t hash_value, st_data_t key) {
|
find_table_bin_ind(st_table *tab, st_hash_t hash_value, st_data_t key)
|
||||||
|
{
|
||||||
st_index_t ind;
|
st_index_t ind;
|
||||||
#ifdef QUADRATIC_PROBE
|
#ifdef QUADRATIC_PROBE
|
||||||
st_index_t d;
|
st_index_t d;
|
||||||
|
@ -908,7 +932,8 @@ find_table_bin_ind(st_table *tab, st_hash_t hash_value, st_data_t key) {
|
||||||
with HASH_VALUE and KEY. The entry should be in the table
|
with HASH_VALUE and KEY. The entry should be in the table
|
||||||
already. */
|
already. */
|
||||||
static st_index_t
|
static st_index_t
|
||||||
find_table_bin_ind_direct(st_table *tab, st_hash_t hash_value, st_data_t key) {
|
find_table_bin_ind_direct(st_table *tab, st_hash_t hash_value, st_data_t key)
|
||||||
|
{
|
||||||
st_index_t ind;
|
st_index_t ind;
|
||||||
#ifdef QUADRATIC_PROBE
|
#ifdef QUADRATIC_PROBE
|
||||||
st_index_t d;
|
st_index_t d;
|
||||||
|
@ -1044,7 +1069,8 @@ find_table_bin_ptr_and_reserve(st_table *tab, st_hash_t *hash_value,
|
||||||
/* Find an entry with KEY in table TAB. Return non-zero if we found
|
/* Find an entry with KEY in table TAB. Return non-zero if we found
|
||||||
it. Set up *RECORD to the found entry record. */
|
it. Set up *RECORD to the found entry record. */
|
||||||
int
|
int
|
||||||
st_lookup(st_table *tab, st_data_t key, st_data_t *value) {
|
st_lookup(st_table *tab, st_data_t key, st_data_t *value)
|
||||||
|
{
|
||||||
st_index_t bin;
|
st_index_t bin;
|
||||||
st_hash_t hash = do_hash(key, tab);
|
st_hash_t hash = do_hash(key, tab);
|
||||||
|
|
||||||
|
@ -1066,7 +1092,8 @@ st_lookup(st_table *tab, st_data_t key, st_data_t *value) {
|
||||||
/* Find an entry with KEY in table TAB. Return non-zero if we found
|
/* Find an entry with KEY in table TAB. Return non-zero if we found
|
||||||
it. Set up *RESULT to the found table entry key. */
|
it. Set up *RESULT to the found table entry key. */
|
||||||
int
|
int
|
||||||
st_get_key(st_table *tab, st_data_t key, st_data_t *result) {
|
st_get_key(st_table *tab, st_data_t key, st_data_t *result)
|
||||||
|
{
|
||||||
st_index_t bin;
|
st_index_t bin;
|
||||||
st_hash_t hash = do_hash(key, tab);
|
st_hash_t hash = do_hash(key, tab);
|
||||||
|
|
||||||
|
@ -1087,7 +1114,8 @@ st_get_key(st_table *tab, st_data_t key, st_data_t *result) {
|
||||||
|
|
||||||
/* Check the table and rebuild it if it is necessary. */
|
/* Check the table and rebuild it if it is necessary. */
|
||||||
static inline void
|
static inline void
|
||||||
rebuild_table_if_necessary (st_table *tab) {
|
rebuild_table_if_necessary (st_table *tab)
|
||||||
|
{
|
||||||
st_index_t bound = tab->entries_bound;
|
st_index_t bound = tab->entries_bound;
|
||||||
|
|
||||||
if (bound == get_allocated_entries(tab))
|
if (bound == get_allocated_entries(tab))
|
||||||
|
@ -1099,7 +1127,8 @@ rebuild_table_if_necessary (st_table *tab) {
|
||||||
already entry with KEY in the table, return nonzero and and update
|
already entry with KEY in the table, return nonzero and and update
|
||||||
the value of the found entry. */
|
the value of the found entry. */
|
||||||
int
|
int
|
||||||
st_insert(st_table *tab, st_data_t key, st_data_t value) {
|
st_insert(st_table *tab, st_data_t key, st_data_t value)
|
||||||
|
{
|
||||||
st_table_entry *entry;
|
st_table_entry *entry;
|
||||||
st_index_t bin;
|
st_index_t bin;
|
||||||
st_index_t ind;
|
st_index_t ind;
|
||||||
|
@ -1171,7 +1200,8 @@ st_add_direct_with_hash(st_table *tab,
|
||||||
/* Insert (KEY, VALUE) into table TAB. The table should not have
|
/* Insert (KEY, VALUE) into table TAB. The table should not have
|
||||||
entry with KEY before the insertion. */
|
entry with KEY before the insertion. */
|
||||||
void
|
void
|
||||||
st_add_direct(st_table *tab, st_data_t key, st_data_t value) {
|
st_add_direct(st_table *tab, st_data_t key, st_data_t value)
|
||||||
|
{
|
||||||
st_hash_t hash_value;
|
st_hash_t hash_value;
|
||||||
|
|
||||||
hash_value = do_hash(key, tab);
|
hash_value = do_hash(key, tab);
|
||||||
|
@ -1230,7 +1260,8 @@ st_insert2(st_table *tab, st_data_t key, st_data_t value,
|
||||||
|
|
||||||
/* Create and return a copy of table OLD_TAB. */
|
/* Create and return a copy of table OLD_TAB. */
|
||||||
st_table *
|
st_table *
|
||||||
st_copy(st_table *old_tab) {
|
st_copy(st_table *old_tab)
|
||||||
|
{
|
||||||
st_table *new_tab;
|
st_table *new_tab;
|
||||||
|
|
||||||
new_tab = (st_table *) malloc(sizeof(st_table));
|
new_tab = (st_table *) malloc(sizeof(st_table));
|
||||||
|
@ -1254,7 +1285,8 @@ st_copy(st_table *old_tab) {
|
||||||
/* Update the entries start of table TAB after removing an entry
|
/* Update the entries start of table TAB after removing an entry
|
||||||
with index N in the array entries. */
|
with index N in the array entries. */
|
||||||
static inline void
|
static inline void
|
||||||
update_range_for_deleted(st_table *tab, st_index_t n) {
|
update_range_for_deleted(st_table *tab, st_index_t n)
|
||||||
|
{
|
||||||
/* Do not update entries_bound here. Otherwise, we can fill all
|
/* Do not update entries_bound here. Otherwise, we can fill all
|
||||||
bins by deleted entry value before rebuilding the table. */
|
bins by deleted entry value before rebuilding the table. */
|
||||||
if (tab->entries_start == n)
|
if (tab->entries_start == n)
|
||||||
|
@ -1303,7 +1335,8 @@ st_general_delete(st_table *tab, st_data_t *key, st_data_t *value)
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
st_delete(st_table *tab, st_data_t *key, st_data_t *value) {
|
st_delete(st_table *tab, st_data_t *key, st_data_t *value)
|
||||||
|
{
|
||||||
return st_general_delete(tab, key, value);
|
return st_general_delete(tab, key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1323,7 +1356,8 @@ st_delete_safe(st_table *tab, st_data_t *key, st_data_t *value,
|
||||||
Return its key through KEY and its record through VALUE (unless
|
Return its key through KEY and its record through VALUE (unless
|
||||||
VALUE is zero). */
|
VALUE is zero). */
|
||||||
int
|
int
|
||||||
st_shift(st_table *tab, st_data_t *key, st_data_t *value) {
|
st_shift(st_table *tab, st_data_t *key, st_data_t *value)
|
||||||
|
{
|
||||||
st_index_t i, bound;
|
st_index_t i, bound;
|
||||||
st_index_t bin;
|
st_index_t bin;
|
||||||
st_table_entry *entries, *curr_entry_ptr;
|
st_table_entry *entries, *curr_entry_ptr;
|
||||||
|
@ -1534,7 +1568,8 @@ st_general_foreach(st_table *tab, int (*func)(ANYARGS), st_data_t arg,
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
st_foreach(st_table *tab, int (*func)(ANYARGS), st_data_t arg) {
|
st_foreach(st_table *tab, int (*func)(ANYARGS), st_data_t arg)
|
||||||
|
{
|
||||||
return st_general_foreach(tab, func, arg, FALSE);
|
return st_general_foreach(tab, func, arg, FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1548,7 +1583,8 @@ st_foreach_check(st_table *tab, int (*func)(ANYARGS), st_data_t arg,
|
||||||
/* Set up array KEYS by at most SIZE keys of head table TAB entries.
|
/* Set up array KEYS by at most SIZE keys of head table TAB entries.
|
||||||
Return the number of keys set up in array KEYS. */
|
Return the number of keys set up in array KEYS. */
|
||||||
static inline st_index_t
|
static inline st_index_t
|
||||||
st_general_keys(st_table *tab, st_data_t *keys, st_index_t size) {
|
st_general_keys(st_table *tab, st_data_t *keys, st_index_t size)
|
||||||
|
{
|
||||||
st_index_t i, bound;
|
st_index_t i, bound;
|
||||||
st_data_t key, *keys_start, *keys_end;
|
st_data_t key, *keys_start, *keys_end;
|
||||||
st_table_entry *curr_entry_ptr, *entries = tab->entries;
|
st_table_entry *curr_entry_ptr, *entries = tab->entries;
|
||||||
|
@ -1569,7 +1605,8 @@ st_general_keys(st_table *tab, st_data_t *keys, st_index_t size) {
|
||||||
}
|
}
|
||||||
|
|
||||||
st_index_t
|
st_index_t
|
||||||
st_keys(st_table *tab, st_data_t *keys, st_index_t size) {
|
st_keys(st_table *tab, st_data_t *keys, st_index_t size)
|
||||||
|
{
|
||||||
return st_general_keys(tab, keys, size);
|
return st_general_keys(tab, keys, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1583,7 +1620,8 @@ st_keys_check(st_table *tab, st_data_t *keys, st_index_t size,
|
||||||
/* Set up array VALUES by at most SIZE values of head table TAB
|
/* Set up array VALUES by at most SIZE values of head table TAB
|
||||||
entries. Return the number of values set up in array VALUES. */
|
entries. Return the number of values set up in array VALUES. */
|
||||||
static inline st_index_t
|
static inline st_index_t
|
||||||
st_general_values(st_table *tab, st_data_t *values, st_index_t size) {
|
st_general_values(st_table *tab, st_data_t *values, st_index_t size)
|
||||||
|
{
|
||||||
st_index_t i, bound;
|
st_index_t i, bound;
|
||||||
st_data_t *values_start, *values_end;
|
st_data_t *values_start, *values_end;
|
||||||
st_table_entry *curr_entry_ptr, *entries = tab->entries;
|
st_table_entry *curr_entry_ptr, *entries = tab->entries;
|
||||||
|
@ -1604,7 +1642,8 @@ st_general_values(st_table *tab, st_data_t *values, st_index_t size) {
|
||||||
}
|
}
|
||||||
|
|
||||||
st_index_t
|
st_index_t
|
||||||
st_values(st_table *tab, st_data_t *values, st_index_t size) {
|
st_values(st_table *tab, st_data_t *values, st_index_t size)
|
||||||
|
{
|
||||||
return st_general_values(tab, values, size);
|
return st_general_values(tab, values, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue