Skip to content

Commit c60fd4a

Browse files
committed
Fix cases where *Key and *Value types were confused
1 parent 6539f4e commit c60fd4a

File tree

5 files changed

+12
-12
lines changed

5 files changed

+12
-12
lines changed

src/avl-tree.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ unsigned int avl_tree_num_entries(AVLTree *tree)
532532
}
533533

534534
static void avl_tree_to_array_add_subtree(AVLTreeNode *subtree,
535-
AVLTreeValue *array, int *index)
535+
AVLTreeKey *array, int *index)
536536
{
537537
if (subtree == NULL) {
538538
return;
@@ -551,13 +551,13 @@ static void avl_tree_to_array_add_subtree(AVLTreeNode *subtree,
551551
array, index);
552552
}
553553

554-
AVLTreeValue *avl_tree_to_array(AVLTree *tree)
554+
AVLTreeKey *avl_tree_to_array(AVLTree *tree)
555555
{
556-
AVLTreeValue *array;
556+
AVLTreeKey *array;
557557
int index;
558558

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

562562
if (array == NULL) {
563563
return NULL;

src/avl-tree.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ typedef enum {
115115
* be sorted before value1, zero if the two keys
116116
* are equal.
117117
*/
118-
typedef int (*AVLTreeCompareFunc)(AVLTreeValue value1, AVLTreeValue value2);
118+
typedef int (*AVLTreeCompareFunc)(AVLTreeKey value1, AVLTreeKey value2);
119119

120120
/**
121121
* Create a new AVL tree.
@@ -248,11 +248,11 @@ int avl_tree_subtree_height(AVLTreeNode *node);
248248
*
249249
* @param tree The tree.
250250
* @return A newly allocated C array containing all the keys
251-
* in the tree, in order. The length of the array
251+
* in the tree, in order. The length of the array
252252
* is equal to the number of entries in the tree
253253
* (see @ref avl_tree_num_entries).
254254
*/
255-
AVLTreeValue *avl_tree_to_array(AVLTree *tree);
255+
AVLTreeKey *avl_tree_to_array(AVLTree *tree);
256256

257257
/**
258258
* Retrieve the number of entries in the tree.

src/hash-table.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ HashTablePair hash_table_iter_next(HashTableIterator *iterator)
418418
{
419419
HashTableEntry *current_entry;
420420
HashTable *hash_table;
421-
HashTablePair pair = {HASH_TABLE_NULL, HASH_TABLE_NULL};
421+
HashTablePair pair = {HASH_TABLE_KEY_NULL, HASH_TABLE_NULL};
422422
unsigned int chain;
423423

424424
hash_table = iterator->hash_table;

src/rb-tree.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ RBTreeNode *rb_tree_insert(RBTree *tree, RBTreeKey key, RBTreeValue value)
344344
parent = *rover;
345345

346346
/* Choose which path to go down, left or right child */
347-
if (tree->compare_func(value, (*rover)->value) < 0) {
347+
if (tree->compare_func(key, (*rover)->key) < 0) {
348348
side = RB_TREE_NODE_LEFT;
349349
} else {
350350
side = RB_TREE_NODE_RIGHT;
@@ -456,7 +456,7 @@ RBTreeNode *rb_tree_node_parent(RBTreeNode *node)
456456
return node->parent;
457457
}
458458

459-
RBTreeValue *rb_tree_to_array(RBTree *tree)
459+
RBTreeKey *rb_tree_to_array(RBTree *tree)
460460
{
461461
/* TODO */
462462
return NULL;

src/rb-tree.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ typedef struct _RBTreeNode RBTreeNode;
106106
* be sorted before data1, zero if the two keys
107107
* are equal.
108108
*/
109-
typedef int (*RBTreeCompareFunc)(RBTreeValue data1, RBTreeValue data2);
109+
typedef int (*RBTreeCompareFunc)(RBTreeKey data1, RBTreeKey data2);
110110

111111
/**
112112
* Each node in a red-black tree is either red or black.
@@ -259,7 +259,7 @@ int rb_tree_subtree_height(RBTreeNode *node);
259259
* is equal to the number of entries in the tree
260260
* (see @ref rb_tree_num_entries).
261261
*/
262-
RBTreeValue *rb_tree_to_array(RBTree *tree);
262+
RBTreeKey *rb_tree_to_array(RBTree *tree);
263263

264264
/**
265265
* Retrieve the number of entries in the tree.

0 commit comments

Comments
 (0)