ht.c revision 567aab801d6db09bae86914007066c88c08a6252
e20788e1216ed720aefa84f3295f7899d9f28c22Mark Andrews/*
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * Copyright (C) 2016, 2018 Internet Systems Consortium, Inc. ("ISC")
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews *
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * This Source Code Form is subject to the terms of the Mozilla Public
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * License, v. 2.0. If a copy of the MPL was not distributed with this
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * file, You can obtain one at http://mozilla.org/MPL/2.0/.
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews */
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews#include <config.h>
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews#include <string.h>
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews#include <isc/hash.h>
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#include <isc/ht.h>
28a8f5b0de57d269cf2845c69cb6abe18cbd3b3aMark Andrews#include <isc/types.h>
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#include <isc/magic.h>
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#include <isc/mem.h>
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#include <isc/result.h>
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#include <isc/util.h>
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunttypedef struct isc_ht_node isc_ht_node_t;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#define ISC_HT_MAGIC ISC_MAGIC('H', 'T', 'a', 'b')
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#define ISC_HT_VALID(ht) ISC_MAGIC_VALID(ht, ISC_HT_MAGIC)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntstruct isc_ht_node {
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt void *value;
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt isc_ht_node_t *next;
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Hunt size_t keysize;
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt unsigned char key[FLEXIBLE_ARRAY_MEMBER];
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt};
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntstruct isc_ht {
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt unsigned int magic;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt isc_mem_t *mctx;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt size_t size;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt size_t mask;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt unsigned int count;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt isc_ht_node_t **table;
a2ca594252024a7b26d2f6b1984cb6da6f5bd09cMark Andrews};
a2ca594252024a7b26d2f6b1984cb6da6f5bd09cMark Andrews
a2ca594252024a7b26d2f6b1984cb6da6f5bd09cMark Andrewsstruct isc_ht_iter {
a2ca594252024a7b26d2f6b1984cb6da6f5bd09cMark Andrews isc_ht_t *ht;
a2ca594252024a7b26d2f6b1984cb6da6f5bd09cMark Andrews size_t i;
a2ca594252024a7b26d2f6b1984cb6da6f5bd09cMark Andrews isc_ht_node_t *cur;
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt};
0cfb24736841b3e98bb25853229a0efabab88bddEvan Hunt
a2ca594252024a7b26d2f6b1984cb6da6f5bd09cMark Andrewsisc_result_t
a2ca594252024a7b26d2f6b1984cb6da6f5bd09cMark Andrewsisc_ht_init(isc_ht_t **htp, isc_mem_t *mctx, isc_uint8_t bits) {
a2ca594252024a7b26d2f6b1984cb6da6f5bd09cMark Andrews isc_ht_t *ht = NULL;
a2ca594252024a7b26d2f6b1984cb6da6f5bd09cMark Andrews size_t i;
ce376a81fa674d240197628ceb6113a4fa5a1ab3Mukund Sivaraman
a2ca594252024a7b26d2f6b1984cb6da6f5bd09cMark Andrews REQUIRE(htp != NULL && *htp == NULL);
a2ca594252024a7b26d2f6b1984cb6da6f5bd09cMark Andrews REQUIRE(mctx != NULL);
a2ca594252024a7b26d2f6b1984cb6da6f5bd09cMark Andrews REQUIRE(bits >= 1 && bits <= (sizeof(size_t)*8 - 1));
a2ca594252024a7b26d2f6b1984cb6da6f5bd09cMark Andrews
a2ca594252024a7b26d2f6b1984cb6da6f5bd09cMark Andrews ht = isc_mem_get(mctx, sizeof(struct isc_ht));
a2ca594252024a7b26d2f6b1984cb6da6f5bd09cMark Andrews if (ht == NULL) {
a2ca594252024a7b26d2f6b1984cb6da6f5bd09cMark Andrews return (ISC_R_NOMEMORY);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt }
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
a2ca594252024a7b26d2f6b1984cb6da6f5bd09cMark Andrews ht->mctx = NULL;
a2ca594252024a7b26d2f6b1984cb6da6f5bd09cMark Andrews isc_mem_attach(mctx, &ht->mctx);
a2ca594252024a7b26d2f6b1984cb6da6f5bd09cMark Andrews
a2ca594252024a7b26d2f6b1984cb6da6f5bd09cMark Andrews ht->size = ((size_t)1<<bits);
a2ca594252024a7b26d2f6b1984cb6da6f5bd09cMark Andrews ht->mask = ((size_t)1<<bits)-1;
a2ca594252024a7b26d2f6b1984cb6da6f5bd09cMark Andrews ht->count = 0;
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt
0cfb24736841b3e98bb25853229a0efabab88bddEvan Hunt ht->table = isc_mem_get(ht->mctx, ht->size * sizeof(isc_ht_node_t*));
a2ca594252024a7b26d2f6b1984cb6da6f5bd09cMark Andrews if (ht->table == NULL) {
a2ca594252024a7b26d2f6b1984cb6da6f5bd09cMark Andrews isc_mem_putanddetach(&ht->mctx, ht, sizeof(struct isc_ht));
a2ca594252024a7b26d2f6b1984cb6da6f5bd09cMark Andrews return (ISC_R_NOMEMORY);
a2ca594252024a7b26d2f6b1984cb6da6f5bd09cMark Andrews }
ce376a81fa674d240197628ceb6113a4fa5a1ab3Mukund Sivaraman
a2ca594252024a7b26d2f6b1984cb6da6f5bd09cMark Andrews for (i = 0; i < ht->size; i++) {
a2ca594252024a7b26d2f6b1984cb6da6f5bd09cMark Andrews ht->table[i] = NULL;
a2ca594252024a7b26d2f6b1984cb6da6f5bd09cMark Andrews }
a2ca594252024a7b26d2f6b1984cb6da6f5bd09cMark Andrews
a2ca594252024a7b26d2f6b1984cb6da6f5bd09cMark Andrews ht->magic = ISC_HT_MAGIC;
a2ca594252024a7b26d2f6b1984cb6da6f5bd09cMark Andrews
a2ca594252024a7b26d2f6b1984cb6da6f5bd09cMark Andrews *htp = ht;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt return (ISC_R_SUCCESS);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Huntvoid
c3b9fad5e3be639c9b36ff0ac921c30133da395cMar Andrewsisc_ht_destroy(isc_ht_t **htp) {
c3b9fad5e3be639c9b36ff0ac921c30133da395cMar Andrews isc_ht_t *ht;
c3b9fad5e3be639c9b36ff0ac921c30133da395cMar Andrews size_t i;
b4d8192d210290112e07b0e22b491c45c50ba696Evan Hunt
c3b9fad5e3be639c9b36ff0ac921c30133da395cMar Andrews REQUIRE(htp != NULL);
b4d8192d210290112e07b0e22b491c45c50ba696Evan Hunt
c3b9fad5e3be639c9b36ff0ac921c30133da395cMar Andrews ht = *htp;
b4d8192d210290112e07b0e22b491c45c50ba696Evan Hunt REQUIRE(ISC_HT_VALID(ht));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ht->magic = 0;
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt for (i = 0; i < ht->size; i++) {
0cfb24736841b3e98bb25853229a0efabab88bddEvan Hunt isc_ht_node_t *node = ht->table[i];
0cfb24736841b3e98bb25853229a0efabab88bddEvan Hunt while (node != NULL) {
0cfb24736841b3e98bb25853229a0efabab88bddEvan Hunt isc_ht_node_t *next = node->next;
0cfb24736841b3e98bb25853229a0efabab88bddEvan Hunt ht->count--;
0cfb24736841b3e98bb25853229a0efabab88bddEvan Hunt isc_mem_put(ht->mctx, node,
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Hunt offsetof(isc_ht_node_t, key) +
215ef83bbed20727813a52ddcdbcd1455856638bMark Andrews node->keysize);
215ef83bbed20727813a52ddcdbcd1455856638bMark Andrews node = next;
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Hunt }
a69070d8fab55dbc63ba9f96c9d3e34f0ea9119aMark Andrews }
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Hunt
9c03f13e18c1b0c32f62391a17300378605bbc7bEvan Hunt INSIST(ht->count == 0);
9c03f13e18c1b0c32f62391a17300378605bbc7bEvan Hunt
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Hunt isc_mem_put(ht->mctx, ht->table, ht->size * sizeof(isc_ht_node_t*));
9c03f13e18c1b0c32f62391a17300378605bbc7bEvan Hunt isc_mem_putanddetach(&ht->mctx, ht, sizeof(struct isc_ht));
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Hunt
a69070d8fab55dbc63ba9f96c9d3e34f0ea9119aMark Andrews *htp = NULL;
a69070d8fab55dbc63ba9f96c9d3e34f0ea9119aMark Andrews}
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Hunt
a69070d8fab55dbc63ba9f96c9d3e34f0ea9119aMark Andrewsisc_result_t
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Huntisc_ht_add(isc_ht_t *ht, const unsigned char *key,
42cf2ff7bad81c5a1f5d3be29d06e12504c3af24Evan Hunt isc_uint32_t keysize, void *value)
42cf2ff7bad81c5a1f5d3be29d06e12504c3af24Evan Hunt{
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Hunt isc_ht_node_t *node;
42cf2ff7bad81c5a1f5d3be29d06e12504c3af24Evan Hunt isc_uint32_t hash;
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Hunt
5a75f61dd413720c16d229b24ebba6bd6ecdb738Evan Hunt REQUIRE(ISC_HT_VALID(ht));
5a75f61dd413720c16d229b24ebba6bd6ecdb738Evan Hunt REQUIRE(key != NULL && keysize > 0);
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Hunt
5a75f61dd413720c16d229b24ebba6bd6ecdb738Evan Hunt hash = isc_hash_function(key, keysize, ISC_TRUE, NULL);
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Hunt node = ht->table[hash & ht->mask];
de52784e45e3a7a92c0d8ad843eb4db313bbfd97Mark Andrews while (node != NULL) {
de52784e45e3a7a92c0d8ad843eb4db313bbfd97Mark Andrews if (keysize == node->keysize &&
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Hunt memcmp(key, node->key, keysize) == 0) {
de52784e45e3a7a92c0d8ad843eb4db313bbfd97Mark Andrews return (ISC_R_EXISTS);
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Hunt }
af850c4120c5bee9462de4def85d0b4c1b583963Mark Andrews node = node->next;
af850c4120c5bee9462de4def85d0b4c1b583963Mark Andrews }
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Hunt
af850c4120c5bee9462de4def85d0b4c1b583963Mark Andrews node = isc_mem_get(ht->mctx, offsetof(isc_ht_node_t, key) + keysize);
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt if (node == NULL)
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Hunt return (ISC_R_NOMEMORY);
8a2ab2b9203120c3e2a883a5ee8c0b5d60c1808cEvan Hunt
8a2ab2b9203120c3e2a883a5ee8c0b5d60c1808cEvan Hunt memmove(node->key, key, keysize);
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Hunt node->keysize = keysize;
8a2ab2b9203120c3e2a883a5ee8c0b5d60c1808cEvan Hunt node->next = ht->table[hash & ht->mask];
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Hunt node->value = value;
ef9f4d097794609e018963087fab10a8b51d8ad1Mark Andrews
ef9f4d097794609e018963087fab10a8b51d8ad1Mark Andrews ht->count++;
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Hunt ht->table[hash & ht->mask] = node;
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt return (ISC_R_SUCCESS);
e7857b5ee05414961bb11f9e57f654163fae6acbckb}
e7857b5ee05414961bb11f9e57f654163fae6acbckb
e7857b5ee05414961bb11f9e57f654163fae6acbckbisc_result_t
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Huntisc_ht_find(const isc_ht_t *ht, const unsigned char *key,
ef9f4d097794609e018963087fab10a8b51d8ad1Mark Andrews isc_uint32_t keysize, void **valuep)
4e8fe357a619ae2b789b15df7e3d6abf782b4a71Evan Hunt{
4e8fe357a619ae2b789b15df7e3d6abf782b4a71Evan Hunt isc_ht_node_t *node;
4e8fe357a619ae2b789b15df7e3d6abf782b4a71Evan Hunt isc_uint32_t hash;
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Hunt
4e8fe357a619ae2b789b15df7e3d6abf782b4a71Evan Hunt REQUIRE(ISC_HT_VALID(ht));
80fa3ef8517ff046a72c4cb1e785f30c9ef9ee75Mark Andrews REQUIRE(key != NULL && keysize > 0);
80fa3ef8517ff046a72c4cb1e785f30c9ef9ee75Mark Andrews REQUIRE(valuep != NULL);
80fa3ef8517ff046a72c4cb1e785f30c9ef9ee75Mark Andrews
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Hunt hash = isc_hash_function(key, keysize, ISC_TRUE, NULL);
80fa3ef8517ff046a72c4cb1e785f30c9ef9ee75Mark Andrews node = ht->table[hash & ht->mask];
7829fad4093f2c1985b1efb7cea00287ff015d2bckb while (node != NULL) {
7829fad4093f2c1985b1efb7cea00287ff015d2bckb if (keysize == node->keysize &&
7829fad4093f2c1985b1efb7cea00287ff015d2bckb memcmp(key, node->key, keysize) == 0) {
ce376a81fa674d240197628ceb6113a4fa5a1ab3Mukund Sivaraman *valuep = node->value;
ce376a81fa674d240197628ceb6113a4fa5a1ab3Mukund Sivaraman return (ISC_R_SUCCESS);
ce376a81fa674d240197628ceb6113a4fa5a1ab3Mukund Sivaraman }
ce376a81fa674d240197628ceb6113a4fa5a1ab3Mukund Sivaraman node = node->next;
ce376a81fa674d240197628ceb6113a4fa5a1ab3Mukund Sivaraman }
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Hunt
7829fad4093f2c1985b1efb7cea00287ff015d2bckb return (ISC_R_NOTFOUND);
1bbd36c4db2c86762b582db4b0504e6e68a183f6Mark Andrews}
1bbd36c4db2c86762b582db4b0504e6e68a183f6Mark Andrews
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Huntisc_result_t
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Huntisc_ht_delete(isc_ht_t *ht, const unsigned char *key, isc_uint32_t keysize) {
1bbd36c4db2c86762b582db4b0504e6e68a183f6Mark Andrews isc_ht_node_t *node, *prev;
501941f0b6cce74c2ff75b10aff3f230d5d37e4cEvan Hunt isc_uint32_t hash;
501941f0b6cce74c2ff75b10aff3f230d5d37e4cEvan Hunt
501941f0b6cce74c2ff75b10aff3f230d5d37e4cEvan Hunt REQUIRE(ISC_HT_VALID(ht));
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Hunt REQUIRE(key != NULL && keysize > 0);
501941f0b6cce74c2ff75b10aff3f230d5d37e4cEvan Hunt
161e803a5608956271d8120be37a1b383d14b647Mark Andrews prev = NULL;
161e803a5608956271d8120be37a1b383d14b647Mark Andrews hash = isc_hash_function(key, keysize, ISC_TRUE, NULL);
161e803a5608956271d8120be37a1b383d14b647Mark Andrews node = ht->table[hash & ht->mask];
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Hunt while (node != NULL) {
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt if (keysize == node->keysize &&
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt memcmp(key, node->key, keysize) == 0) {
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt if (prev == NULL)
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt ht->table[hash & ht->mask] = node->next;
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Hunt else
161e803a5608956271d8120be37a1b383d14b647Mark Andrews prev->next = node->next;
5a75f61dd413720c16d229b24ebba6bd6ecdb738Evan Hunt isc_mem_put(ht->mctx, node,
5a75f61dd413720c16d229b24ebba6bd6ecdb738Evan Hunt offsetof(isc_ht_node_t, key) +
5a75f61dd413720c16d229b24ebba6bd6ecdb738Evan Hunt node->keysize);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ht->count--;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
99cbc3d3a4dcbd203146f62e37478aee1c8ee673Evan Hunt return (ISC_R_SUCCESS);
b4d8192d210290112e07b0e22b491c45c50ba696Evan Hunt }
b4d8192d210290112e07b0e22b491c45c50ba696Evan Hunt
7829fad4093f2c1985b1efb7cea00287ff015d2bckb prev = node;
node = node->next;
}
return (ISC_R_NOTFOUND);
}
isc_result_t
isc_ht_iter_create(isc_ht_t *ht, isc_ht_iter_t **itp) {
isc_ht_iter_t *it;
REQUIRE(ISC_HT_VALID(ht));
REQUIRE(itp != NULL && *itp == NULL);
it = isc_mem_get(ht->mctx, sizeof(isc_ht_iter_t));
if (it == NULL)
return (ISC_R_NOMEMORY);
it->ht = ht;
it->i = 0;
it->cur = NULL;
*itp = it;
return (ISC_R_SUCCESS);
}
void
isc_ht_iter_destroy(isc_ht_iter_t **itp) {
isc_ht_iter_t *it;
isc_ht_t *ht;
REQUIRE(itp != NULL && *itp != NULL);
it = *itp;
ht = it->ht;
isc_mem_put(ht->mctx, it, sizeof(isc_ht_iter_t));
*itp = NULL;
}
isc_result_t
isc_ht_iter_first(isc_ht_iter_t *it) {
REQUIRE(it != NULL);
it->i = 0;
while (it->i < it->ht->size && it->ht->table[it->i] == NULL)
it->i++;
if (it->i == it->ht->size)
return (ISC_R_NOMORE);
it->cur = it->ht->table[it->i];
return (ISC_R_SUCCESS);
}
isc_result_t
isc_ht_iter_next(isc_ht_iter_t *it) {
REQUIRE(it != NULL);
REQUIRE(it->cur != NULL);
it->cur = it->cur->next;
if (it->cur == NULL) {
do {
it->i++;
} while (it->i < it->ht->size && it->ht->table[it->i] == NULL);
if (it->i >= it->ht->size)
return (ISC_R_NOMORE);
it->cur = it->ht->table[it->i];
}
return (ISC_R_SUCCESS);
}
isc_result_t
isc_ht_iter_delcurrent_next(isc_ht_iter_t *it) {
isc_result_t result = ISC_R_SUCCESS;
isc_ht_node_t *to_delete = NULL;
isc_ht_node_t *prev = NULL;
isc_ht_node_t *node = NULL;
isc_uint32_t hash;
isc_ht_t *ht;
REQUIRE(it != NULL);
REQUIRE(it->cur != NULL);
to_delete = it->cur;
ht = it->ht;
it->cur = it->cur->next;
if (it->cur == NULL) {
do {
it->i++;
} while (it->i < ht->size && ht->table[it->i] == NULL);
if (it->i >= ht->size)
result = ISC_R_NOMORE;
else
it->cur = ht->table[it->i];
}
hash = isc_hash_function(to_delete->key, to_delete->keysize, ISC_TRUE,
NULL);
node = ht->table[hash & ht->mask];
while (node != to_delete) {
prev = node;
node = node->next;
INSIST(node != NULL);
}
if (prev == NULL)
ht->table[hash & ht->mask] = node->next;
else
prev->next = node->next;
isc_mem_put(ht->mctx, node,
offsetof(isc_ht_node_t, key) + node->keysize);
ht->count--;
return (result);
}
void
isc_ht_iter_current(isc_ht_iter_t *it, void **valuep) {
REQUIRE(it != NULL);
REQUIRE(it->cur != NULL);
*valuep = it->cur->value;
}
void
isc_ht_iter_currentkey(isc_ht_iter_t *it, unsigned char **key, size_t *keysize)
{
REQUIRE(it != NULL);
REQUIRE(it->cur != NULL);
*key = it->cur->key;
*keysize = it->cur->keysize;
}
unsigned int
isc_ht_count(isc_ht_t *ht) {
REQUIRE(ISC_HT_VALID(ht));
return(ht->count);
}