aboutsummaryrefslogtreecommitdiff
path: root/src/findkey.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2016-07-14 21:02:05 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2016-07-14 21:02:05 +0300
commit5580c3248794803a8e45dd58b45933a32637954d (patch)
tree3067db40ccf49fab472d7fe3df31bae17d24df5b /src/findkey.c
parent66eb071ce6202a33dbf53dfc46e52b25d683290c (diff)
downloadgdbm-5580c3248794803a8e45dd58b45933a32637954d.tar.gz
gdbm-5580c3248794803a8e45dd58b45933a32637954d.tar.bz2
Don't use hardcoded constant
* src/gdbmconst.h (GDBM_HASH_BITS): New constant. * src/bucket.c: Use GDBM_HASH_BITS instead of the hardcoded value. * src/findkey.c (_gdbm_findkey): Use _gdbm_hash_key. * src/gdbmtool.c (hash_handler): Use _gdbm_hash_key if the database is open. * src/hash.c (_gdbm_bucket_dir, _gdbm_hash_key): New functions. * src/proto.h (_gdbm_bucket_dir, _gdbm_hash_key): New protos. * src/systems.h (STATBLKSIZE): Take a struct stat as argument. * src/gdbmopen.c (STATBLKSIZE): Takes argument now.
Diffstat (limited to 'src/findkey.c')
-rw-r--r--src/findkey.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/findkey.c b/src/findkey.c
index 34091e1..3cd90ce 100644
--- a/src/findkey.c
+++ b/src/findkey.c
@@ -97,15 +97,16 @@ _gdbm_findkey (GDBM_FILE dbf, datum key, char **ret_dptr, int *ret_hash_val)
int bucket_hash_val; /* The hash value from the bucket. */
int new_hash_val; /* Computed hash value for the key */
char *file_key; /* The complete key as stored in the file. */
+ int bucket_dir; /* Number of the bucket in directory. */
int elem_loc; /* The location in the bucket. */
int home_loc; /* The home location in the bucket. */
int key_size; /* Size of the key on the file. */
/* Compute hash value and load proper bucket. */
- new_hash_val = _gdbm_hash (key);
+ _gdbm_hash_key (dbf, key, &new_hash_val, &bucket_dir, &elem_loc);
if (ret_hash_val)
*ret_hash_val = new_hash_val;
- if (_gdbm_get_bucket (dbf, new_hash_val >> (31 - dbf->header->dir_bits)))
+ if (_gdbm_get_bucket (dbf, bucket_dir))
return -1;
/* Is the element the last one found for this bucket? */
@@ -122,7 +123,6 @@ _gdbm_findkey (GDBM_FILE dbf, datum key, char **ret_dptr, int *ret_hash_val)
}
/* It is not the cached value, search for element in the bucket. */
- elem_loc = new_hash_val % dbf->header->bucket_elems;
home_loc = elem_loc;
bucket_hash_val = dbf->bucket->h_table[elem_loc].hash_value;
while (bucket_hash_val != -1)

Return to:

Send suggestions and report system problems to the System administrator.