Computer Science Department
Western Washington University
Bellingham, WA 98226
-
+
*************************************************************************/
key_size = dbf->bucket->h_table[elem_loc].key_size;
data_size = dbf->bucket->h_table[elem_loc].data_size;
data_ca = &dbf->cache_entry->ca_data;
-
+
/* Set up the cache. */
if (data_ca->dptr != NULL) free (data_ca->dptr);
data_ca->key_size = key_size;
_gdbm_fatal (dbf, "lseek error");
num_bytes = read (dbf->desc, data_ca->dptr, key_size+data_size);
if (num_bytes != key_size+data_size) _gdbm_fatal (dbf, "read error");
-
+
return data_ca->dptr;
}
entry. If it is found, a pointer to the data and the key are returned
in DPTR. If it is not found, the value -1 is returned. Since find
key computes the hash value of key, that value */
+__attribute__((no_sanitize_undefined))
int
_gdbm_findkey (dbf, key, dptr, new_hash_val)
gdbm_file_info *dbf;
_gdbm_get_bucket (dbf, *new_hash_val>> (31-dbf->header->dir_bits));
/* Is the element the last one found for this bucket? */
- if (dbf->cache_entry->ca_data.elem_loc != -1
+ if (dbf->cache_entry->ca_data.elem_loc != -1
&& *new_hash_val == dbf->cache_entry->ca_data.hash_val
&& dbf->cache_entry->ca_data.key_size == key.dsize
&& dbf->cache_entry->ca_data.dptr != NULL
*dptr = dbf->cache_entry->ca_data.dptr+key.dsize;
return dbf->cache_entry->ca_data.elem_loc;
}
-
+
/* 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;
if (bucket_hash_val != *new_hash_val
|| key_size != key.dsize
|| bcmp (dbf->bucket->h_table[elem_loc].key_start, key.dptr,
- (SMALL < key_size ? SMALL : key_size)) != 0)
+ (SMALL < key_size ? SMALL : key_size)) != 0)
{
/* Current elem_loc is not the item, go to next item. */
elem_loc = (elem_loc + 1) % dbf->header->bucket_elems;
Computer Science Department
Western Washington University
Bellingham, WA 98226
-
+
*************************************************************************/
because the argument FLAGS was GDBM_INSERT and the KEY was already in
the database. */
+__attribute__((no_sanitize_undefined))
int
gdbm_store (dbf, key, content, flags)
gdbm_file_info *dbf;
/* Split the current bucket. */
_gdbm_split_bucket (dbf, new_hash_val);
}
-
+
/* Find space to insert into bucket and set elem_loc to that place. */
elem_loc = new_hash_val % dbf->header->bucket_elems;
while (dbf->bucket->h_table[elem_loc].hash_value != -1)
/* Write everything that is needed to the disk. */
_gdbm_end_update (dbf);
return 0;
-
+
}
Computer Science Department
Western Washington University
Bellingham, WA 98226
-
+
*************************************************************************/
to find the home position of the element by taking the value modulo the
bucket hash table size. */
+__attribute__((no_sanitize_undefined))
int
_gdbm_hash (key)
datum key;
for (index = 0; index < key.dsize; index++)
value = (value + (key.dptr[index] << (index*5 % 24))) & 0x7FFFFFFF;
- value = (1103515243 * value + 12345) & 0x7FFFFFFF;
+ value = (1103515243 * value + 12345) & 0x7FFFFFFF;
/* Return the value. */
return((int) value);