diff options
author | Holden Rohrer <hr@hrhr.dev> | 2020-05-28 10:55:38 -0400 |
---|---|---|
committer | Holden Rohrer <hr@hrhr.dev> | 2020-05-28 10:55:38 -0400 |
commit | 9addd39acd0e53656ccedf4fb5380c8df7845a8f (patch) | |
tree | bd7e0a2e969523e7c7f07fc40b26931c58dbd30c | |
parent | d6e6291efe4281adb4d69071537f6f7010e71dfd (diff) |
made functions static
-rw-r--r-- | read.c | 16 | ||||
-rw-r--r-- | strbst.c | 6 |
2 files changed, 12 insertions, 10 deletions
@@ -8,14 +8,14 @@ #include "nodelink.h" #include "ll.h" -void consumespaces(FILE* file) { +static void consumespaces(FILE* file) { // used to consume spaces in an item ("- list item" -> "list item") int c; while ( ( c = fgetc(file) ) != EOF && c == ' ' ); ungetc(c, file); } -void wsclean(char* txt, size_t sz){ // "string \n \n" -> "string" +static void wsclean(char* txt, size_t sz){ // "string\n \n" -> "string" size_t i; for (i = sz; i > 0; i--) { // start at end [i-1] and dec // break on non-nl, non-space char @@ -24,14 +24,14 @@ void wsclean(char* txt, size_t sz){ // "string \n \n" -> "string" txt[i] = 0; // finish string } -char* empty(void) { +static char* empty(void) { // "" with a freeable memory address char* str = malloc(sizeof(char)); *str = 0; return str; } -char* getline(size_t* n, FILE* file) { +static char* getline(size_t* n, FILE* file) { size_t sz = 100; *n = 0; int c; @@ -47,7 +47,7 @@ char* getline(size_t* n, FILE* file) { return realloc(out, sizeof(char) * (*n+1) ); } -char* line(FILE* file) { // gets a line from file +static char* line(FILE* file) { // gets a line from file size_t n; char* link = getline(&n, file); // getline stores a line of size n in link @@ -61,7 +61,7 @@ char* line(FILE* file) { // gets a line from file } } -link* insorget(strbst* tgt, char* name) { +static link* insorget(strbst* tgt, char* name) { link* get = query(tgt, name); if (!get) { get = newlink(newnode()); @@ -70,13 +70,13 @@ link* insorget(strbst* tgt, char* name) { return get; } -link* addbstlink(strbst* tree, char* name, node* to) { +static link* addbstlink(strbst* tree, char* name, node* to) { link* l = newlink(to); insbst(tree, name, l); return l; } -char* resolvell(llnode* tail, size_t sz) { +static char* resolvell(llnode* tail, size_t sz) { char *out, *pos; pos = out = malloc(sizeof(char)*(sz+1)); out[sz] = 0; while (tail != NULL) { @@ -58,8 +58,10 @@ e b => a c *bst = (*bst)->right; // tip = b (*bst)->left->right = flip; } +// NOTE: These functions are valid because `b` is guaranteed in the +// conditions where the rotations are called. -int insnode(strbstnode** bst, strbstnode* new) { +static int insnode(strbstnode** bst, strbstnode* new) { // returns height of right node minus height of left node ("bias") if (!*bst) { // When an empty node is reached, *bst = new; // place the node @@ -96,7 +98,7 @@ void insbst(strbst* bst, char* ind, void* data) { insnode(&(bst->head), newbstnode(ind, data)); // allows recursion } -void* querynode(strbstnode* node, char* ind){ +static void* querynode(strbstnode* node, char* ind){ // tail-recursive finding algorithm if (!node) return NULL; // NULL => node not found int cmp = strcmp(ind, node->ind); |