* Assign unique ID to all buckets
*/
static void
-assign_bucket_id(struct aggregator_proto *p, struct trie_node *node, u32 *counter)
+assign_bucket_id(struct aggregator_proto *p, struct aggregator_bucket *bucket)
{
- assert(node != NULL);
-
- if (node->bucket)
- {
- if (node->bucket->id == 0)
- {
- node->bucket->id = *counter;
- *counter += 1;
- proto_insert_bucket(p, node->bucket);
- }
-
- /* All leaves have a bucket */
- if (is_leaf(node))
- return;
- }
-
- if (node->child[0])
- assign_bucket_id(p, node->child[0], counter);
+ assert(p != NULL);
+ assert(bucket != NULL);
+ assert(bucket->id == 0);
- if (node->child[1])
- assign_bucket_id(p, node->child[1], counter);
+ bucket->id = hmap_first_zero(&p->bucket_id_map);
+ hmap_set(&p->bucket_id_map, bucket->id);
}
/*
{
assert(p->addr_type == NET_IP4 || p->addr_type == NET_IP6);
- /* Start with 1 as 0 is reserved for IDs that have not been assigned yet */
- u32 bucket_counter = 1;
- assign_bucket_id(p, p->root, &bucket_counter);
-
if (p->logging)
{
log("==== PREFIXES BEFORE ====");
new_bucket = lp_allocz(p->bucket_pool, sizeof(*new_bucket) + sizeof(new_bucket->aggr_data[0]) * p->aggr_on_count);
memcpy(new_bucket, tmp_bucket, sizeof(*new_bucket) + sizeof(new_bucket->aggr_data[0]) * p->aggr_on_count);
HASH_INSERT2(p->buckets, AGGR_BUCK, p->p.pool, new_bucket);
+
+ assign_bucket_id(p, new_bucket);
+ proto_insert_bucket(p, new_bucket);
}
/* Store the route attributes */
mem_hash_init(&haux);
new_bucket->hash = mem_hash_value(&haux);
+ /* Assign ID to root node */
+ assign_bucket_id(p, new_bucket);
+ proto_insert_bucket(p, new_bucket);
+ assert(get_bucket_ptr(p, new_bucket->id) == new_bucket);
+
struct aggregator_route *arte = lp_allocz(p->route_pool, sizeof(*arte));
*arte = (struct aggregator_route) {
settle_init(&p->notify_settle, &p->notify_settle_cf, request_feed_on_settle_timer, p);
}
+ hmap_init(&p->bucket_id_map, p->p.pool, 1024);
+ hmap_set(&p->bucket_id_map, 0); /* 0 is default value, do not use it as ID */
+
p->first_run = 1;
times_update(&main_timeloop);
p->bucket_list = NULL;
p->bucket_list_size = 0;
p->bucket_list_count = 0;
+
+ p->bucket_id_map = (struct hmap) { 0 };
}
static int