struct entry **pE;
unsigned int newsize, i, index;
/* Check we're not hitting max capacity */
- if (h->primeindex == (PRIME_TABLE_LEN - 1)) return 0;
+ if (h->primeindex == (PRIME_TABLE_LEN - 1))
+ return ENOSPC;
newsize = primes[++(h->primeindex)];
newtable = talloc_realloc(h, h->table, struct entry *, newsize);
if (!newtable)
{
h->primeindex--;
- return 0;
+ return ENOMEM;
}
h->table = newtable;
h->tablelength = newsize;
h->loadlimit = loadlimit(h->primeindex);
- return -1;
+ return 0;
}
-int hashtable_insert(struct hashtable *h, void *k, void *v)
+int hashtable_add(struct hashtable *h, void *k, void *v)
{
/* This method allows duplicate keys - but they shouldn't be used */
unsigned int index;
hashtable_expand(h);
}
e = talloc_zero(h, struct entry);
- if (NULL == e) { --(h->entrycount); return 0; } /*oom*/
+ if (NULL == e)
+ {
+ --h->entrycount;
+ return ENOMEM;
+ }
e->h = hash(h,k);
index = indexFor(h->tablelength,e->h);
e->k = k;
talloc_steal(e, v);
e->next = h->table[index];
h->table[index] = e;
- return -1;
+ return 0;
}
void *hashtable_search(const struct hashtable *h, const void *k)
);
/*****************************************************************************
- * hashtable_insert
+ * hashtable_add
- * @name hashtable_insert
+ * @name hashtable_add
* @param h the hashtable to insert into
* @param k the key - hashtable claims ownership and will free on removal
* @param v the value - does not claim ownership
- * @return non-zero for successful insertion
+ * @return zero for successful insertion
*
* This function will cause the table to expand if the insertion would take
* the ratio of entries to table size over the maximum load factor.
*/
int
-hashtable_insert(struct hashtable *h, void *k, void *v);
+hashtable_add(struct hashtable *h, void *k, void *v);
/*****************************************************************************
* hashtable_search
char *k = talloc_strdup(NULL, str);
if (!k)
- return 0;
- return hashtable_insert(hash, k, (void *)1);
+ return ENOMEM;
+ return hashtable_add(hash, k, (void *)1);
}
/**
: WALK_TREE_SKIP_CHILDREN;
}
- if (!remember_string(data->reachable, node->name))
+ if (remember_string(data->reachable, node->name))
return WALK_TREE_ERROR_STOP;
domain_check_acc_add(node, data->domains);
domain->generation = generation;
domain->introduced = false;
- if (!hashtable_insert(domhash, &domain->domid, domain)) {
+ if (hashtable_add(domhash, &domain->domid, domain)) {
talloc_free(domain);
errno = ENOMEM;
return NULL;
*/
dom->nodes = -d->acc[ACC_NODES].val;
- if (!hashtable_insert(domains, &dom->domid, dom)) {
+ if (hashtable_add(domains, &dom->domid, dom)) {
talloc_free(dom);
return -1;
}
list_for_each_entry(trans, &conn->transaction_list, list) {
tname = talloc_asprintf(trans, "%"PRIu64,
trans->generation);
- if (!tname || !remember_string(hash, tname))
+ if (!tname || remember_string(hash, tname))
goto nomem;
list_for_each_entry(i, &trans->accessed, list) {
if (!i->ta_node)
continue;
- if (!remember_string(hash, i->trans_name))
+ if (remember_string(hash, i->trans_name))
goto nomem;
}