1
0
Fork 0

Clean up TODO items

This commit is contained in:
wael 2021-11-07 14:47:00 +02:00
parent f631feca97
commit acbef5d0ec
6 changed files with 13 additions and 8 deletions

View File

@ -1,3 +1,3 @@
#!/bin/zsh
# This script lists files with TODO while ignoring backup files, object files and compiled executables.
grep "TODO" . --line-number --with-filename --recursive --context=2 | sed '/~/d' | sed '/\.o/d'
grep "TODO" . --line-number --with-filename --recursive --context=2 | sed '/~/d' | sed '/\.o/d' | sed '/\.git/d'

View File

@ -52,4 +52,3 @@ Array list (?).
Dynamic array/vector.
Misc tasks:
Write a script to locate all TODO occurances throughout the project.

View File

@ -3,8 +3,6 @@
#include <assert.h>
#include "../trees/binary_search_tree/binary_search_tree.h"
/* TODO: Check the functions which BST added (in comparison to regular trees). */
/* Define constants. */
#define PRINT_INFO_TESTING_START "Starting tests.\n"
#define PRINT_INFO_TESTING_END "Done testing.\n"

View File

@ -1,5 +1,3 @@
/* TODO: Check the code and make sure that these tests pass! */
/* Include statements. */
#include <stdio.h>
#include <assert.h>

View File

@ -184,7 +184,6 @@ tree_node_t* search_in_binary_search_tree(tree_node_t *root, void *data, int (*c
/* Check if we found the right node, and recurse accordingly. */
comparison_result = (*comparison_function)(root->data, data);
/* TODO: sanity check on this code, it should be right, but it seems a bit off. */
return ((comparison_result == 0) ? root : ((comparison_result == 1) ? search_in_binary_search_tree(root->left, data, comparison_function) : search_in_binary_search_tree(root->right, data, comparison_function)));
}
@ -248,7 +247,7 @@ void **sorted_array_from_binary_search_tree(tree_node_t *root, size_t *length) {
height = find_binary_search_tree_depth(root);
/* Derive the array's (maximal) size based on said height (assumes a balanced and near-full tree). */
array_size = (size_t) (pow(2, height + 1) - 1); /* TODO: Check if this calculation agrees with the height-finding function. */
array_size = (size_t) (pow(2, height + 1) - 1);
/* Attempt to allocate the array. */
array = (void**) calloc(array_size, sizeof(void*));
@ -264,6 +263,15 @@ void **sorted_array_from_binary_search_tree(tree_node_t *root, size_t *length) {
free(array);
return NULL;
}
/* Set the array's length. */
*length = ++index;
/* Resize the array if needed. */
if (index < array_size) {
/* Check for (non-fatal) failure. */
if (rallocarray(array, index, sizeof(void*)) == ENOMEM)
printf(BINARY_SEARCH_TREE_RESIZING_ARRAY_FAILURE_CODE);
}
/* Success. */
return array;
}

View File

@ -16,6 +16,8 @@
#define BINARY_SEARCH_TREE_COMPARISON_EQUAL_TO 0
/* Return code for comparison, larger. */
#define BINARY_SEARCH_TREE_COMPARISON_LARGER_THAN 1
/* Error text for when resizing fails. */
#define BINARY_SEARCH_TREE_RESIZING_ARRAY_FAILURE_CODE "Failed to resize/shrink the array in sorted_array_from_binary_search_tree().\n"
/* Define all the functions. */
/* This function initializes a single node. */