Skip to content

Commit

Permalink
INTERNAL: Change tot_elem_cnt to subtree element count in set
Browse files Browse the repository at this point in the history
  • Loading branch information
jeesup0103 committed Jan 9, 2025
1 parent c3340cb commit 2199b09
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
19 changes: 13 additions & 6 deletions engines/default/coll_set.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ static void do_set_node_link(set_meta_info *info,

par_node->htab[par_hidx] = node;
par_node->hcnt[par_hidx] = -1; /* child hash node */
par_node->tot_elem_cnt -= num_found;
par_node->tot_hash_cnt += 1;
}

Expand Down Expand Up @@ -263,12 +262,10 @@ static void do_set_node_unlink(set_meta_info *info,
assert(node->hcnt[hidx] == 0);
}
}
assert(fcnt == node->tot_elem_cnt);
node->tot_elem_cnt = 0;

par_node->htab[par_hidx] = head;
par_node->hcnt[par_hidx] = fcnt;
par_node->tot_elem_cnt += fcnt;
par_node->tot_hash_cnt -= 1;
}

Expand Down Expand Up @@ -324,7 +321,14 @@ static ENGINE_ERROR_CODE do_set_elem_link(set_meta_info *info, set_elem_item *el
elem->next = node->htab[hidx];
node->htab[hidx] = elem;
node->hcnt[hidx] += 1;
node->tot_elem_cnt += 1;
node = info->root;
while (node != NULL) {
node->tot_elem_cnt += 1;
hidx = SET_GET_HASHIDX(elem->hval, node->hdepth);
if (node->hcnt[hidx] >= 0)
break;
node = node->htab[hidx];
}

info->ccnt++;

Expand Down Expand Up @@ -400,6 +404,7 @@ static ENGINE_ERROR_CODE do_set_elem_traverse_delete(set_meta_info *info, set_ha
child_node->tot_elem_cnt < (SET_MAX_HASHCHAIN_SIZE/2)) {
do_set_node_unlink(info, node, hidx);
}
node->tot_elem_cnt--;
}
} else {
ret = ENGINE_ELEM_ENOENT;
Expand Down Expand Up @@ -497,13 +502,15 @@ static int do_set_elem_traverse_dfs(set_meta_info *info, set_hash_node *node,
if (node->hcnt[hidx] == -1) {
set_hash_node *child_node = (set_hash_node *)node->htab[hidx];
int rcnt = (count > 0 ? (count - fcnt) : 0);
fcnt += do_set_elem_traverse_dfs(info, child_node, rcnt, delete,
(elem_array==NULL ? NULL : &elem_array[fcnt]));
int ecnt = do_set_elem_traverse_dfs(info, child_node, rcnt, delete,
(elem_array==NULL ? NULL : &elem_array[fcnt]));
fcnt += ecnt;
if (delete) {
if (child_node->tot_hash_cnt == 0 &&
child_node->tot_elem_cnt < (SET_MAX_HASHCHAIN_SIZE/2)) {
do_set_node_unlink(info, node, hidx);
}
node->tot_elem_cnt -= ecnt;
}
} else if (node->hcnt[hidx] > 0) {
set_elem_item *elem = node->htab[hidx];
Expand Down
2 changes: 1 addition & 1 deletion engines/default/item_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ typedef struct _set_hash_node {
uint16_t refcount;
uint8_t slabs_clsid; /* which slab class we're in */
uint8_t hdepth;
uint16_t tot_elem_cnt;
uint32_t tot_elem_cnt;
uint16_t tot_hash_cnt;
int16_t hcnt[SET_HASHTAB_SIZE];
void *htab[SET_HASHTAB_SIZE];
Expand Down

0 comments on commit 2199b09

Please sign in to comment.