Skip to content

Commit

Permalink
[api] using get instead of search throughout
Browse files Browse the repository at this point in the history
  • Loading branch information
albarrentine committed Dec 29, 2024
1 parent 00ebcdf commit 08afab4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
4 changes: 1 addition & 3 deletions src/binary_tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,7 @@ void BST_FUNC(rotate_right)(BST_NODE_TYPE *node) {
node->right->key = tmp_key;
}

#ifndef BST_CUSTOM_SEARCH
void *BST_FUNC(search)(BST_NODE_TYPE *node, BST_KEY_TYPE key) {
void *BST_FUNC(get)(BST_NODE_TYPE *node, BST_KEY_TYPE key) {
BST_NODE_TYPE *tmp_node = node;
BST_KEY_TYPE tmp_key = node->key;

Expand All @@ -168,7 +167,6 @@ void *BST_FUNC(search)(BST_NODE_TYPE *node, BST_KEY_TYPE key) {
return NULL;
}
}
#endif

#undef BST_CONCAT_
#undef BST_CONCAT
Expand Down
32 changes: 16 additions & 16 deletions test.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ TEST test_bst(void) {

char *a, *b, *c, *d;

a = binary_tree_search(root, 1);
a = binary_tree_get(root, 1);
ASSERT_STR_EQ(a, "a");
b = binary_tree_search(root, 3);
b = binary_tree_get(root, 3);
ASSERT_STR_EQ(b, "b");
c = binary_tree_search(root, 5);
c = binary_tree_get(root, 5);
ASSERT_STR_EQ(c, "c");
d = binary_tree_search(root, 7);
d = binary_tree_get(root, 7);
ASSERT_STR_EQ(d, "d");

binary_tree_stack_t stack = (binary_tree_stack_t){
Expand Down Expand Up @@ -109,13 +109,13 @@ TEST test_bst(void) {
ASSERT_EQ(root->left->left->left->key, 1);
ASSERT_EQ(root->left->left->right->key, 3);

a = binary_tree_search(root, 1);
a = binary_tree_get(root, 1);
ASSERT_STR_EQ(a, "a");
b = binary_tree_search(root, 3);
b = binary_tree_get(root, 3);
ASSERT_STR_EQ(b, "b");
c = binary_tree_search(root, 5);
c = binary_tree_get(root, 5);
ASSERT_STR_EQ(c, "c");
d = binary_tree_search(root, 7);
d = binary_tree_get(root, 7);
ASSERT_STR_EQ(d, "d");

candidate = binary_tree_candidate_leaf(root, 3, &stack);
Expand All @@ -136,13 +136,13 @@ TEST test_bst(void) {
ASSERT_EQ(root->right->left->key, 5);
ASSERT_EQ(root->right->right->key, 7);

a = binary_tree_search(root, 1);
a = binary_tree_get(root, 1);
ASSERT_STR_EQ(a, "a");
b = binary_tree_search(root, 3);
b = binary_tree_get(root, 3);
ASSERT_STR_EQ(b, "b");
c = binary_tree_search(root, 5);
c = binary_tree_get(root, 5);
ASSERT_STR_EQ(c, "c");
d = binary_tree_search(root, 7);
d = binary_tree_get(root, 7);
ASSERT_STR_EQ(d, "d");

binary_tree_rotate_right(root);
Expand All @@ -167,13 +167,13 @@ TEST test_bst(void) {
ASSERT_EQ(root->right->right->left->key, 5);
ASSERT_EQ(root->right->right->right->key, 7);

a = binary_tree_search(root, 1);
a = binary_tree_get(root, 1);
ASSERT_STR_EQ(a, "a");
b = binary_tree_search(root, 3);
b = binary_tree_get(root, 3);
ASSERT_STR_EQ(b, "b");
c = binary_tree_search(root, 5);
c = binary_tree_get(root, 5);
ASSERT_STR_EQ(c, "c");
d = binary_tree_search(root, 7);
d = binary_tree_get(root, 7);
ASSERT_STR_EQ(d, "d");

candidate = binary_tree_candidate_leaf(root, 7, &stack);
Expand Down

0 comments on commit 08afab4

Please sign in to comment.