* which describes the current status.
*/
typedef struct _ENTRY {
- unsigned int used;
+ int used;
ENTRY entry;
} _ENTRY;
/* free used memory */
for (i = 1; i <= htab->size; ++i) {
- if (htab->table[i].used) {
+ if (htab->table[i].used > 0) {
ENTRY *ep = &htab->table[i].entry;
free(ep->key);
size_t key_len = strlen(match);
for (idx = last_idx + 1; idx < htab->size; ++idx) {
- if (!htab->table[idx].used)
+ if (htab->table[idx].used > 0)
continue;
if (!strncmp(match, htab->table[idx].entry.key, key_len)) {
*retval = &htab->table[idx].entry;
unsigned int count;
unsigned int len = strlen(item.key);
unsigned int idx;
+ unsigned int first_deleted = 0;
/* Compute an value for the given string. Perhaps use a better method. */
hval = len;
*/
unsigned hval2;
+ if (htab->table[idx].used == -1
+ && !first_deleted)
+ first_deleted = idx;
+
if (htab->table[idx].used == hval
&& strcmp(item.key, htab->table[idx].entry.key) == 0) {
/* Overwrite existing value? */
* Create new entry;
* create copies of item.key and item.data
*/
+ if (first_deleted)
+ idx = first_deleted;
+
htab->table[idx].used = hval;
htab->table[idx].entry.key = strdup(item.key);
htab->table[idx].entry.data = strdup(item.data);
free(ep->key);
free(ep->data);
- htab->table[idx].used = 0;
+ htab->table[idx].used = -1;
--htab->filled;
*/
for (i = 1, n = 0, totlen = 0; i <= htab->size; ++i) {
- if (htab->table[i].used) {
+ if (htab->table[i].used > 0) {
ENTRY *ep = &htab->table[i].entry;
list[n++] = ep;