serialize_nodes(FILE *file, dns_rbtnode_t *node, uintptr_t parent,
dns_rbtdatawriter_t datawriter, void *writer_arg,
uintptr_t *where, isc_uint64_t *crc);
+
/*
* The following functions allow you to get the actual address of a pointer
* without having to use an if statement to check to see if that address is
#define LEFT(node) ((node)->left)
#define RIGHT(node) ((node)->right)
#define DOWN(node) ((node)->down)
-#ifdef DNS_RBT_USEHASH
#define UPPERNODE(node) ((node)->uppernode)
-#endif /* DNS_RBT_USEHASH */
#define DATA(node) ((node)->data)
#define IS_EMPTY(node) ((node)->data == NULL)
#define HASHNEXT(node) ((node)->hashnext)
* <name_data>{1..255}<oldoffsetlen>{1}<offsets>{1..128}
*
* <name_data> contains the name of the node when it was created.
- * <oldoffsetlen> contains the length of <offsets> when the node was created.
- * <offsets> contains the offets into name for each label when the node was
- * created.
+ * <oldoffsetlen> contains the length of <offsets> when the node
+ * was created.
+ * <offsets> contains the offets into name for each label when the node
+ * was created.
*/
#define NAME(node) ((unsigned char *)((node) + 1))
dns_rbtnode_t *
dns_rbt_root(dns_rbt_t *rbt) {
- return rbt->root;
+ return (rbt->root);
}
-#ifdef DNS_RBT_USEHASH
-static isc_result_t
-inithash(dns_rbt_t *rbt);
-#endif
-
#ifdef DEBUG
#define inline
/*
}
#endif /* DEBUG */
-#ifdef DNS_RBT_USEHASH
-
/*
* Upper node is the parent of the root of the passed node's
* subtree. The passed node must not be NULL.
fixup_uppernodes_helper(rbt->root, NULL);
}
-#else
-
-/* The passed node must not be NULL. */
-static inline dns_rbtnode_t *
-get_subtree_root(dns_rbtnode_t *node) {
- while (!IS_ROOT(node)) {
- node = PARENT(node);
- }
-
- return (node);
-}
-
-/* Upper node is the parent of the root of the passed node's
- * subtree. The passed node must not be NULL.
- */
-static inline dns_rbtnode_t *
-get_upper_node(dns_rbtnode_t *node) {
- dns_rbtnode_t *root = get_subtree_root(node);
-
- /*
- * Return the node in the level above the argument node that points
- * to the level the argument node is in. If the argument node is in
- * the top level, the return value is NULL.
- */
- return (PARENT(root));
-}
-
-#endif /* DNS_RBT_USEHASH */
-
size_t
dns__rbtnode_getdistance(dns_rbtnode_t *node) {
size_t nodes = 1;
static isc_result_t
create_node(isc_mem_t *mctx, const dns_name_t *name, dns_rbtnode_t **nodep);
-#ifdef DNS_RBT_USEHASH
+static isc_result_t
+inithash(dns_rbt_t *rbt);
+
static inline void
hash_node(dns_rbt_t *rbt, dns_rbtnode_t *node, const dns_name_t *name);
+
static inline void
unhash_node(dns_rbt_t *rbt, dns_rbtnode_t *node);
+
static void
rehash(dns_rbt_t *rbt, unsigned int newcount);
-#else
-#define hash_node(rbt, node, name)
-#define unhash_node(rbt, node)
-#define rehash(rbt, newcount)
-#endif
static inline void
rotate_left(dns_rbtnode_t *node, dns_rbtnode_t **rootp);
goto cleanup;
}
-#ifdef DNS_RBT_USEHASH
fixup_uppernodes(rbt);
-#endif /* DNS_RBT_USEHASH */
*rbtp = rbt;
if (originp != NULL)
dns_rbt_create(isc_mem_t *mctx, dns_rbtdeleter_t deleter,
void *deleter_arg, dns_rbt_t **rbtp)
{
-#ifdef DNS_RBT_USEHASH
isc_result_t result;
-#endif
dns_rbt_t *rbt;
REQUIRE(mctx != NULL);
rbt->hashsize = 0;
rbt->mmap_location = NULL;
-#ifdef DNS_RBT_USEHASH
result = inithash(rbt);
if (result != ISC_R_SUCCESS) {
isc_mem_putanddetach(&rbt->mctx, rbt, sizeof(*rbt));
return (result);
}
-#endif
rbt->magic = RBT_MAGIC;
if (result == ISC_R_SUCCESS) {
rbt->nodecount++;
new_current->is_root = 1;
-#ifdef DNS_RBT_USEHASH
+
UPPERNODE(new_current) = NULL;
-#endif /* DNS_RBT_USEHASH */
+
rbt->root = new_current;
*nodep = new_current;
hash_node(rbt, new_current, name);
PARENT(current) = new_current;
DOWN(new_current) = current;
root = &DOWN(new_current);
-#ifdef DNS_RBT_USEHASH
+
UPPERNODE(new_current) = UPPERNODE(current);
UPPERNODE(current) = new_current;
-#endif /* DNS_RBT_USEHASH */
INSIST(level_count < DNS_RBT_LEVELBLOCK);
level_count++;
result = create_node(rbt->mctx, add_name, &new_current);
if (ISC_LIKELY(result == ISC_R_SUCCESS)) {
-#ifdef DNS_RBT_USEHASH
- if (*root == NULL)
+ if (*root == NULL) {
UPPERNODE(new_current) = current;
- else
+ } else {
UPPERNODE(new_current) = PARENT(*root);
-#endif /* DNS_RBT_USEHASH */
+ }
+
addonlevel(new_current, current, order, root);
rbt->nodecount++;
*nodep = new_current;
break;
if (compared == dns_namereln_none) {
-#ifdef DNS_RBT_USEHASH
/*
* Here, current is pointing at a subtree root
* node. We try to find a matching node using
* match a labelsequence from some other
* subdomain.
*/
- if (ISC_LIKELY(get_upper_node(hnode) != up_current))
+ if (ISC_LIKELY(get_upper_node(hnode) !=
+ up_current))
+ {
continue;
+ }
dns_name_init(&hnode_name, NULL);
NODENAME(hnode, &hnode_name);
- if (ISC_LIKELY(dns_name_equal(&hnode_name, &hash_name)))
+ if (ISC_LIKELY(dns_name_equal(&hnode_name,
+ &hash_name)))
+ {
break;
+ }
}
if (hnode != NULL) {
*/
current = NULL;
continue;
-
-#else /* DNS_RBT_USEHASH */
-
- /*
- * Standard binary search tree movement.
- */
- if (order < 0)
- current = LEFT(current);
- else
- current = RIGHT(current);
-
-#endif /* DNS_RBT_USEHASH */
-
} else {
/*
* The names have some common suffix labels.
* down pointer and search in the new tree.
*/
if (compared == dns_namereln_subdomain) {
-#ifdef DNS_RBT_USEHASH
- subdomain:
-#endif
+ subdomain:
/*
* Whack off the current node's common parts
* for the name to search in the next level.
node->data_is_relative = 0;
node->rpz = 0;
-#ifdef DNS_RBT_USEHASH
HASHNEXT(node) = NULL;
HASHVAL(node) = 0;
-#endif
ISC_LINK_INIT(node, deadlink);
return (ISC_R_SUCCESS);
}
-#ifdef DNS_RBT_USEHASH
+/*
+ * Add a node to the hash table
+ */
static inline void
hash_add_node(dns_rbt_t *rbt, dns_rbtnode_t *node, const dns_name_t *name) {
unsigned int hash;
rbt->hashtable[hash] = node;
}
+/*
+ * Initialize hash table
+ */
static isc_result_t
inithash(dns_rbt_t *rbt) {
unsigned int bytes;
return (ISC_R_SUCCESS);
}
+/*
+ * Rebuild the hashtable to reduce the load factor
+ */
static void
rehash(dns_rbt_t *rbt, unsigned int newcount) {
unsigned int oldsize;
isc_mem_put(rbt->mctx, oldtable, oldsize * sizeof(dns_rbtnode_t *));
}
+/*
+ * Add a node to the hash table. Rehash the hashtable if the node count
+ * rises above a critical level.
+ */
static inline void
hash_node(dns_rbt_t *rbt, dns_rbtnode_t *node, const dns_name_t *name) {
REQUIRE(DNS_RBTNODE_VALID(node));
hash_add_node(rbt, node, name);
}
+/*
+ * Remove a node from the hash table
+ */
static inline void
unhash_node(dns_rbt_t *rbt, dns_rbtnode_t *node) {
unsigned int bucket;
HASHNEXT(bucket_node) = HASHNEXT(node);
}
}
-#endif /* DNS_RBT_USEHASH */
static inline void
rotate_left(dns_rbtnode_t *node, dns_rbtnode_t **rootp) {
result = dns_rbt_addnode(tree, name, &node);
if (result == ISC_R_SUCCESS) {
dns_rbt_namefromnode(node, &nodename);
-#ifdef DNS_RBT_USEHASH
node->locknum = node->hashval % rbtdb->node_lock_count;
-#else
- node->locknum = dns_name_hash(&nodename, ISC_TRUE) %
- rbtdb->node_lock_count;
-#endif
if (tree == rbtdb->tree) {
add_empty_wildcards(rbtdb, name);
if (dns_name_iswildcard(name)) {
- result = add_wildcard_magic(rbtdb, name);
+ result = add_wildcard_magic(rbtdb,
+ name);
if (result != ISC_R_SUCCESS) {
- RWUNLOCK(&rbtdb->tree_lock, locktype);
+ RWUNLOCK(&rbtdb->tree_lock,
+ locktype);
return (result);
}
}
dns_name_t foundname;
dns_name_init(&foundname, NULL);
dns_rbt_namefromnode(node, &foundname);
-#ifdef DNS_RBT_USEHASH
node->locknum = node->hashval % rbtdb->node_lock_count;
-#else
- node->locknum = dns_name_hash(&foundname, ISC_TRUE) %
- rbtdb->node_lock_count;
-#endif
}
result = dns_rdataslab_fromrdataset(rdataset, rbtdb->common.mctx,
*/
dns_name_init(&name, NULL);
dns_rbt_namefromnode(rbtdb->origin_node, &name);
-#ifdef DNS_RBT_USEHASH
rbtdb->origin_node->locknum =
rbtdb->origin_node->hashval %
rbtdb->node_lock_count;
-#else
- rbtdb->origin_node->locknum =
- dns_name_hash(&name, ISC_TRUE) %
- rbtdb->node_lock_count;
-#endif
/*
* Add an apex node to the NSEC3 tree so that NSEC3 searches
* return partial matches when there is only a single NSEC3
*/
dns_name_init(&name, NULL);
dns_rbt_namefromnode(rbtdb->nsec3_origin_node, &name);
-#ifdef DNS_RBT_USEHASH
rbtdb->nsec3_origin_node->locknum =
rbtdb->nsec3_origin_node->hashval %
rbtdb->node_lock_count;
-#else
- rbtdb->nsec3_origin_node->locknum =
- dns_name_hash(&name, ISC_TRUE) %
- rbtdb->node_lock_count;
-#endif
}
/*