Skip to content

Commit

Permalink
INTERNAL: Change DFS traverse order in set and map
Browse files Browse the repository at this point in the history
  • Loading branch information
jam2in authored and jeesup0103 committed Jan 6, 2025
1 parent e395870 commit da71623
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 45 deletions.
35 changes: 12 additions & 23 deletions engines/default/coll_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -497,30 +497,19 @@ static int do_map_elem_traverse_dfs_bycnt(map_meta_info *info, map_hash_node *no
int hidx;
int fcnt = 0; /* found count */

if (node->tot_hash_cnt > 0) {
map_hash_node *child_node;
int rcnt; /* request count */
for (hidx = 0; hidx < MAP_HASHTAB_SIZE; hidx++) {
if (node->hcnt[hidx] == -1) {
child_node = (map_hash_node *)node->htab[hidx];
rcnt = (count > 0 ? (count - fcnt) : 0);
fcnt += do_map_elem_traverse_dfs_bycnt(info, child_node, rcnt, delete,
(elem_array==NULL ? NULL : &elem_array[fcnt]), cause);
if (delete) {
if (child_node->tot_hash_cnt == 0 &&
child_node->tot_elem_cnt < (MAP_MAX_HASHCHAIN_SIZE/2)) {
do_map_node_unlink(info, node, hidx);
}
for (hidx = 0; hidx < MAP_HASHTAB_SIZE; hidx++) {
if (node->hcnt[hidx] == -1) {
map_hash_node *child_node = (map_hash_node *)node->htab[hidx];
int rcnt = (count > 0 ? (count - fcnt) : 0);
fcnt += do_map_elem_traverse_dfs_bycnt(info, child_node, rcnt, delete,
(elem_array==NULL ? NULL : &elem_array[fcnt]), cause);
if (delete) {
if (child_node->tot_hash_cnt == 0 &&
child_node->tot_elem_cnt < (MAP_MAX_HASHCHAIN_SIZE/2)) {
do_map_node_unlink(info, node, hidx);
}
if (count > 0 && fcnt >= count)
return fcnt;
}
}
}
assert(count == 0 || fcnt < count);

for (hidx = 0; hidx < MAP_HASHTAB_SIZE; hidx++) {
if (node->hcnt[hidx] > 0) {
} else if (node->hcnt[hidx] > 0) {
map_elem_item *elem = node->htab[hidx];
while (elem != NULL) {
if (elem_array) {
Expand All @@ -532,8 +521,8 @@ static int do_map_elem_traverse_dfs_bycnt(map_meta_info *info, map_hash_node *no
if (count > 0 && fcnt >= count) break;
elem = (delete ? node->htab[hidx] : elem->next);
}
if (count > 0 && fcnt >= count) break;
}
if (count > 0 && fcnt >= count) break;
}
return fcnt;
}
Expand Down
33 changes: 11 additions & 22 deletions engines/default/coll_set.c
Original file line number Diff line number Diff line change
Expand Up @@ -493,30 +493,19 @@ static int do_set_elem_traverse_dfs(set_meta_info *info, set_hash_node *node,
int hidx;
int fcnt = 0; /* found count */

if (node->tot_hash_cnt > 0) {
set_hash_node *child_node;
int rcnt; /* request count */
for (hidx = 0; hidx < SET_HASHTAB_SIZE; hidx++) {
if (node->hcnt[hidx] == -1) {
child_node = (set_hash_node *)node->htab[hidx];
rcnt = (count > 0 ? (count - fcnt) : 0);
fcnt += do_set_elem_traverse_dfs(info, child_node, rcnt, delete,
for (hidx = 0; hidx < SET_HASHTAB_SIZE; hidx++) {
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]));
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);
}
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);
}
if (count > 0 && fcnt >= count)
return fcnt;
}
}
}
assert(count == 0 || fcnt < count);

for (hidx = 0; hidx < SET_HASHTAB_SIZE; hidx++) {
if (node->hcnt[hidx] > 0) {
} else if (node->hcnt[hidx] > 0) {
set_elem_item *elem = node->htab[hidx];
while (elem != NULL) {
if (elem_array) {
Expand All @@ -530,8 +519,8 @@ static int do_set_elem_traverse_dfs(set_meta_info *info, set_hash_node *node,
if (count > 0 && fcnt >= count) break;
elem = (delete ? node->htab[hidx] : elem->next);
}
if (count > 0 && fcnt >= count) break;
}
if (count > 0 && fcnt >= count) break;
}
return fcnt;
}
Expand Down

0 comments on commit da71623

Please sign in to comment.