Commit 83e6eb0d authored by Brian Wellington's avatar Brian Wellington
Browse files

Add routines to count the number of nodes in a database and an rbt.

parent 95b6b97a
......@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: db.c,v 1.49 2000/08/01 01:22:15 tale Exp $ */
/* $Id: db.c,v 1.50 2000/08/03 19:46:31 bwelling Exp $ */
/***
*** Imports
......@@ -646,3 +646,10 @@ dns_db_getsoaserial(dns_db_t *db, dns_dbversion_t *ver, isc_uint32_t *serialp)
dns_db_detachnode(db, &node);
return (result);
}
unsigned int
dns_db_nodecount(dns_db_t *db) {
REQUIRE(DNS_DB_VALID(db));
return ((db->methods->nodecount)(db));
}
......@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: db.h,v 1.53 2000/08/01 01:24:04 tale Exp $ */
/* $Id: db.h,v 1.54 2000/08/03 19:46:36 bwelling Exp $ */
#ifndef DNS_DB_H
#define DNS_DB_H 1
......@@ -140,6 +140,7 @@ typedef struct dns_dbmethods {
dns_rdatatype_t type,
dns_rdatatype_t covers);
isc_boolean_t (*issecure)(dns_db_t *db);
unsigned int (*nodecount)(dns_db_t *db);
} dns_dbmethods_t;
#define DNS_DB_MAGIC 0x444E5344U /* DNSD. */
......@@ -1129,6 +1130,19 @@ dns_db_getsoaserial(dns_db_t *db, dns_dbversion_t *ver, isc_uint32_t *serialp);
* 'ver' is a valid version.
*/
unsigned int
dns_db_nodecount(dns_db_t *db);
/*
* Count the number of nodes in 'db'.
*
* Requires:
*
* 'db' is a valid database.
*
* Returns:
* The number of nodes in the database
*/
ISC_LANG_ENDDECLS
#endif /* DNS_DB_H */
......@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: rbt.h,v 1.46 2000/08/01 01:24:28 tale Exp $ */
/* $Id: rbt.h,v 1.47 2000/08/03 19:46:37 bwelling Exp $ */
#ifndef DNS_RBT_H
#define DNS_RBT_H 1
......@@ -570,6 +570,15 @@ dns_rbt_namefromnode(dns_rbtnode_t *node, dns_name_t *name);
* as part of the node.
*/
unsigned int
dns_rbt_nodecount(dns_rbt_t *rbt);
/*
* Obtain the number of nodes tree of trees.
*
* Requires:
* rbt is a valid rbt manager.
*/
void
dns_rbt_destroy(dns_rbt_t **rbtp);
/*
......
......@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: rbt.c,v 1.90 2000/08/01 01:22:38 tale Exp $ */
/* $Id: rbt.c,v 1.91 2000/08/03 19:46:32 bwelling Exp $ */
/* Principal Authors: DCL */
......@@ -52,6 +52,7 @@ struct dns_rbt {
dns_rbtnode_t * root;
void (*data_deleter)(void *, void *);
void * deleter_arg;
unsigned int nodecount;
};
#define RED 0
......@@ -205,6 +206,7 @@ dns_rbt_create(isc_mem_t *mctx, void (*deleter)(void *, void *),
rbt->data_deleter = deleter;
rbt->deleter_arg = deleter_arg;
rbt->root = NULL;
rbt->nodecount = 0;
rbt->magic = RBT_MAGIC;
*rbtp = rbt;
......@@ -225,6 +227,8 @@ dns_rbt_destroy(dns_rbt_t **rbtp) {
dns_rbt_deletetree(rbt, rbt->root);
INSIST(rbt->nodecount == 0);
rbt->magic = 0;
isc_mem_put(rbt->mctx, rbt, sizeof(*rbt));
......@@ -232,6 +236,12 @@ dns_rbt_destroy(dns_rbt_t **rbtp) {
*rbtp = NULL;
}
unsigned int
dns_rbt_nodecount(dns_rbt_t *rbt) {
REQUIRE(VALID_RBT(rbt));
return (rbt->nodecount);
}
/*
* The next three functions for chains, get_ancestor_mem, put_ancestor_mem
* and chain_name, appear early in this file so they can be effectively
......@@ -368,6 +378,7 @@ dns_rbt_addnode(dns_rbt_t *rbt, dns_name_t *name, dns_rbtnode_t **nodep) {
if (rbt->root == NULL) {
result = create_node(rbt->mctx, add_name, &new_current);
if (result == ISC_R_SUCCESS) {
rbt->nodecount++;
IS_ROOT(new_current) = ISC_TRUE;
rbt->root = new_current;
*nodep = new_current;
......@@ -618,6 +629,8 @@ dns_rbt_addnode(dns_rbt_t *rbt, dns_name_t *name, dns_rbtnode_t **nodep) {
MAKE_BLACK(current);
ATTRS(current) &= ~DNS_NAMEATTR_ABSOLUTE;
rbt->nodecount++;
if (common_labels ==
dns_name_countlabels(add_name) &&
common_bits == add_bits) {
......@@ -669,6 +682,7 @@ dns_rbt_addnode(dns_rbt_t *rbt, dns_name_t *name, dns_rbtnode_t **nodep) {
if (result == ISC_R_SUCCESS) {
dns_rbt_addonlevel(new_current, current, order, root, &chain);
rbt->nodecount++;
*nodep = new_current;
}
......@@ -1206,6 +1220,7 @@ dns_rbt_deletenode(dns_rbt_t *rbt, dns_rbtnode_t *node, isc_boolean_t recurse)
if (rbt->data_deleter != NULL)
rbt->data_deleter(DATA(node), rbt->deleter_arg);
isc_mem_put(rbt->mctx, node, NODE_SIZE(node));
rbt->nodecount--;
/*
* If there is one node left on this level, and the node one level up
......@@ -1378,9 +1393,12 @@ join_nodes(dns_rbt_t *rbt, dns_rbtnode_t *node) {
PARENT(DOWN(down)) = newnode;
isc_mem_put(rbt->mctx, node, NODE_SIZE(node));
rbt->nodecount--;
if (newnode != down)
if (newnode != down) {
isc_mem_put(rbt->mctx, down, NODE_SIZE(down));
rbt->nodecount--;
}
}
return (result);
......@@ -1829,6 +1847,7 @@ dns_rbt_deletetree(dns_rbt_t *rbt, dns_rbtnode_t *node) {
rbt->data_deleter(DATA(node), rbt->deleter_arg);
isc_mem_put(rbt->mctx, node, NODE_SIZE(node));
rbt->nodecount--;
}
static void
......
......@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: rbtdb.c,v 1.113 2000/08/01 01:22:39 tale Exp $ */
/* $Id: rbtdb.c,v 1.114 2000/08/03 19:46:34 bwelling Exp $ */
/*
* Principal Author: Bob Halley
......@@ -3778,6 +3778,22 @@ issecure(dns_db_t *db) {
return (secure);
}
static isc_boolean_t
nodecount(dns_db_t *db) {
dns_rbtdb_t *rbtdb;
unsigned int count;
rbtdb = (dns_rbtdb_t *)db;
REQUIRE(VALID_RBTDB(rbtdb));
RWLOCK(&rbtdb->tree_lock, isc_rwlocktype_read);
count = dns_rbt_nodecount(rbtdb->tree);
RWUNLOCK(&rbtdb->tree_lock, isc_rwlocktype_read);
return (count);
}
static dns_dbmethods_t zone_methods = {
attach,
detach,
......@@ -3801,7 +3817,8 @@ static dns_dbmethods_t zone_methods = {
addrdataset,
subtractrdataset,
deleterdataset,
issecure
issecure,
nodecount
};
static dns_dbmethods_t cache_methods = {
......@@ -3827,7 +3844,8 @@ static dns_dbmethods_t cache_methods = {
addrdataset,
subtractrdataset,
deleterdataset,
issecure
issecure,
nodecount
};
isc_result_t
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment