Skip to content

Commit

Permalink
Fix cases where *Key and *Value types were confused
Browse files Browse the repository at this point in the history
  • Loading branch information
fragglet committed Dec 17, 2024
1 parent 6539f4e commit c60fd4a
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
8 changes: 4 additions & 4 deletions src/avl-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ unsigned int avl_tree_num_entries(AVLTree *tree)
}

static void avl_tree_to_array_add_subtree(AVLTreeNode *subtree,
AVLTreeValue *array, int *index)
AVLTreeKey *array, int *index)
{
if (subtree == NULL) {
return;
Expand All @@ -551,13 +551,13 @@ static void avl_tree_to_array_add_subtree(AVLTreeNode *subtree,
array, index);
}

AVLTreeValue *avl_tree_to_array(AVLTree *tree)
AVLTreeKey *avl_tree_to_array(AVLTree *tree)
{
AVLTreeValue *array;
AVLTreeKey *array;
int index;

/* Allocate the array */
array = malloc(sizeof(AVLTreeValue) * tree->num_nodes);
array = malloc(sizeof(AVLTreeKey) * tree->num_nodes);

if (array == NULL) {
return NULL;
Expand Down
6 changes: 3 additions & 3 deletions src/avl-tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ typedef enum {
* be sorted before value1, zero if the two keys
* are equal.
*/
typedef int (*AVLTreeCompareFunc)(AVLTreeValue value1, AVLTreeValue value2);
typedef int (*AVLTreeCompareFunc)(AVLTreeKey value1, AVLTreeKey value2);

/**
* Create a new AVL tree.
Expand Down Expand Up @@ -248,11 +248,11 @@ int avl_tree_subtree_height(AVLTreeNode *node);
*
* @param tree The tree.
* @return A newly allocated C array containing all the keys
* in the tree, in order. The length of the array
* in the tree, in order. The length of the array
* is equal to the number of entries in the tree
* (see @ref avl_tree_num_entries).
*/
AVLTreeValue *avl_tree_to_array(AVLTree *tree);
AVLTreeKey *avl_tree_to_array(AVLTree *tree);

/**
* Retrieve the number of entries in the tree.
Expand Down
2 changes: 1 addition & 1 deletion src/hash-table.c
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ HashTablePair hash_table_iter_next(HashTableIterator *iterator)
{
HashTableEntry *current_entry;
HashTable *hash_table;
HashTablePair pair = {HASH_TABLE_NULL, HASH_TABLE_NULL};
HashTablePair pair = {HASH_TABLE_KEY_NULL, HASH_TABLE_NULL};
unsigned int chain;

hash_table = iterator->hash_table;
Expand Down
4 changes: 2 additions & 2 deletions src/rb-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ RBTreeNode *rb_tree_insert(RBTree *tree, RBTreeKey key, RBTreeValue value)
parent = *rover;

/* Choose which path to go down, left or right child */
if (tree->compare_func(value, (*rover)->value) < 0) {
if (tree->compare_func(key, (*rover)->key) < 0) {
side = RB_TREE_NODE_LEFT;
} else {
side = RB_TREE_NODE_RIGHT;
Expand Down Expand Up @@ -456,7 +456,7 @@ RBTreeNode *rb_tree_node_parent(RBTreeNode *node)
return node->parent;
}

RBTreeValue *rb_tree_to_array(RBTree *tree)
RBTreeKey *rb_tree_to_array(RBTree *tree)
{
/* TODO */
return NULL;
Expand Down
4 changes: 2 additions & 2 deletions src/rb-tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ typedef struct _RBTreeNode RBTreeNode;
* be sorted before data1, zero if the two keys
* are equal.
*/
typedef int (*RBTreeCompareFunc)(RBTreeValue data1, RBTreeValue data2);
typedef int (*RBTreeCompareFunc)(RBTreeKey data1, RBTreeKey data2);

/**
* Each node in a red-black tree is either red or black.
Expand Down Expand Up @@ -259,7 +259,7 @@ int rb_tree_subtree_height(RBTreeNode *node);
* is equal to the number of entries in the tree
* (see @ref rb_tree_num_entries).
*/
RBTreeValue *rb_tree_to_array(RBTree *tree);
RBTreeKey *rb_tree_to_array(RBTree *tree);

/**
* Retrieve the number of entries in the tree.
Expand Down

0 comments on commit c60fd4a

Please sign in to comment.