From 5bd8318b7fbf98d409e5c2fa9255b96d185d670f Mon Sep 17 00:00:00 2001 From: Nalin Dahyabhai Date: Thu, 4 Sep 2008 19:25:39 -0400 Subject: - track the length of the list of entries kept by a map - add a way to read the number of entries in a map - add a way to read the number of maps in a domain --- src/map.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src/map.c') diff --git a/src/map.c b/src/map.c index 3652455..8487a74 100644 --- a/src/map.c +++ b/src/map.c @@ -78,6 +78,7 @@ static struct { void *backend_data; void (*free_backend_data)(void *backend_data); } *entries; + int n_unique_entries; /* Search trees to speed up searches for entries. */ unsigned int n_key_trees; void **key_trees; @@ -705,6 +706,7 @@ map_data_clear_map_map(struct plugin_state *state, struct map *map) } free(entry); } + map->n_unique_entries = 0; map->entries = NULL; map->id_tree = NULL; free(map->key_trees); @@ -906,6 +908,7 @@ map_data_unset_map_entry(struct plugin_state *state, if (map->entries == entry) { map->entries = next; } + map->n_unique_entries--; /* Remove every key for this entry from the applicable key * trees. */ for (i = 0; i < entry->n_keys; i++) { @@ -1070,6 +1073,7 @@ map_data_set_entry(struct plugin_state *state, map->entries->prev = entry; } map->entries = entry; + map->n_unique_entries++; /* Index the keys. */ for (i = 0; i < entry->n_keys; i++) { entry->key_index = i; @@ -1139,6 +1143,29 @@ map_done(struct plugin_state *state) map_data.lock = NULL; } +int +map_data_get_domain_size(struct plugin_state *state, const char *domain_name) +{ + struct domain *domain; + domain = map_data_find_domain(state, domain_name); + if (domain != NULL) { + return domain->n_maps; + } + return 0; +} + +int +map_data_get_map_size(struct plugin_state *state, + const char *domain_name, const char *map_name) +{ + struct map *map; + map = map_data_find_map(state, domain_name, map_name); + if (map != NULL) { + return map->n_unique_entries; + } + return 0; +} + void map_rdlock(void) { -- cgit