*
* Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd.
* Michael Clark <michael@metaparadigm.com>
+ * Copyright (c) 2009 Hewlett-Packard Development Company, L.P.
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the MIT license. See COPYING for details.
unsigned long h, n;
t->inserts++;
- if(t->count > t->size * 0.66) lh_table_resize(t, t->size * 2);
+ if(t->count >= t->size * LH_LOAD_FACTOR) lh_table_resize(t, t->size * 2);
h = t->hash_fn(k);
n = h % t->size;
{
unsigned long h = t->hash_fn(k);
unsigned long n = h % t->size;
+ int count = 0;
t->lookups++;
- while( 1 ) {
+ while( count < t->size ) {
if(t->table[n].k == LH_EMPTY) return NULL;
if(t->table[n].k != LH_FREED &&
t->equal_fn(t->table[n].k, k)) return &t->table[n];
if(++n == t->size) n = 0;
+ count++;
}
return NULL;
}
const void* lh_table_lookup(struct lh_table *t, const void *k)
{
- struct lh_entry *e = lh_table_lookup_entry(t, k);
- if(e) return e->v;
- return NULL;
+ void *result;
+ lh_table_lookup_ex(t, k, &result);
+ return result;
}
+json_bool lh_table_lookup_ex(struct lh_table* t, const void* k, void **v)
+{
+ struct lh_entry *e = lh_table_lookup_entry(t, k);
+ if (e != NULL) {
+ if (v != NULL) *v = (void *)e->v;
+ return TRUE; /* key found */
+ }
+ if (v != NULL) *v = NULL;
+ return FALSE; /* key not found */
+}
int lh_table_delete_entry(struct lh_table *t, struct lh_entry *e)
{