#include "invertedIndexTree.h" // Returns a newly malloc'ed inverted index node, fields initialised to zero // except for word. struct InvertedIndexNode *createInvertedIndexNode(char *const word) { struct InvertedIndexNode *ret = calloc(1, sizeof(struct InvertedIndexNode)); ret->word = word; return ret; } // Inserts to a FileListNode BST. Uses strcmp to determine priority, with // negative values moving into the left and positive values into the right. struct InvertedIndexNode * insertInvertedIndexNode(struct InvertedIndexNode *node, char *const word) { if (node == NULL) { return createInvertedIndexNode(word); } const int comparison = strcmp(word, node->word); if (comparison < 0) { node->left = insertInvertedIndexNode(node->left, word); } if (comparison > 0) { node->right = insertInvertedIndexNode(node->right, word); } return node; } // Searches for an invertedIndexNode via a string. struct InvertedIndexNode * searchInvertedIndexNode(struct InvertedIndexNode *head, char *const word) { int comparison = strcmp(word, head->word); if (head == NULL || !comparison) { return head; } if (comparison < 0) { return searchInvertedIndexNode(head->left, word); } return searchInvertedIndexNode(head->right, word); }