-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve red-black tree performance #131
Conversation
Meanwhile, resolve the concerns raised by CodeQL. |
TODO:
|
e1753a8
to
87c7f21
Compare
internal_map_path_entry_t path[RB_MAX_DEPTH]; | ||
internal_map_path_entry_t *pathp; | ||
rbt_node_init(node); | ||
/* Wind. */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Improve the comment.
rbtn_black_set(left); | ||
if (pathp == path) { | ||
rbtree->root = left; | ||
/* Nothing to summarize -- the subtree rooted at the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See if "Nothing to summarize" makes sense or not. We shall ignore the handling of summary.
a72f62f
to
0035e63
Compare
* Each node in the red-black tree consumes at least 1 byte of space (for the | ||
* linkage if nothing else, so there are a maximum of sizeof(void *) << 3 rb | ||
* tree nodes in any process (and thus, at most sizeof(void *) << 3 nodes in any | ||
* rb tree). The choice of algorithm bounds the depth of a tree to twice the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Improve the English writing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prepare test program(s) for map.[ch] which appear in directory tests/map
.
Example: https://github.com/sysprog21/rv32emu/tree/master/tests/cache
e40ed35
to
7541a26
Compare
map_r_r(obj, node, parent, grandparent, uncle); | ||
int cmp; | ||
map_node_t *ret = rbtree->root; | ||
while (ret && (cmp = (rbtree->cmp)(keynode->key, ret->key)) != 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace 0
with _CMP_EQUAL
for readability.
path->node = rbtree->root; | ||
for (pathp = path; pathp->node; pathp++) { | ||
int cmp = pathp->cmp = (rbtree->cmp)(node->key, pathp->node->key); | ||
if (cmp == 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would propose the following:
switch (cmp) {
case _CMP_LESS:
pathp[1].node = rbnode_get_left(pathp->node);
break;
case _CMP_GREATER:
pathp[1].node = rbnode_get_right(pathp->node);
break;
default: /* _CMP_EQUAL */
break;
}
/* If there is no left child, keep going up until there is a left child */ | ||
it->prev = it->node; | ||
it->node = rb_parent(it->node); | ||
map_t tree = (map_t) malloc(sizeof(map_head_t)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No cast is required. That is,
map_t tree = malloc(sizeof(map_head_t));
Close in favor of incoming revised pull request for reviewing. |
map.[ch]
is the C Implementation for C++ std::map using red-black tree. It works well, but there is room for improvements.Close #29