void TNF_CmdSelect(TNF_Index* index, char** line) { char* token, *svalue, *table_name; //int value; while ((token = getToken(line)) != '\0') { // //fprintf(stderr, "insert: token: %s\n", token); // if (!strncmp(token, "INTO", 1)) { // table_name = getToken(line); // assert(token != '\0'); // fprintf(stderr, "table: %s\n", table_name); // } // if (!strncmp(token, "VALUE", 1)) { // svalue = getToken(line); // '(' // svalue = getToken(line); // value = atoi(svalue); // fprintf(stderr, "value: %d\n", value); // } } int th = 2; TNF_NodeResult* list = Tree_search(index->tree, (void*)&th, all_true); int i; for (i = 0; i < list->size; i++) { TNF_RecordAddrMap* map = *(TNF_RecordAddrMap**)(list->data + (i * SIZEOF_VOIDPTR)); fprintf(stderr, "id: %s\n", Record_read(index->record, map->addr)); } }
Node *Tree_search(Node *node, int value) { //Search a given item in the //subtree starting from the node //provided as argument if(node->value==value) { return node; } List *list = node->list; //Is it a leaf node? if(list==NULL) { return NULL; } else { Node *current = list->first; while(current!=NULL) { Node *found = Tree_search(current, value); if (found!=NULL) { return found; } current = current->next; } return NULL; } }
TreeNode * Tree_search(TreeNode * tn, int val) { if (tn == NULL) { // cannot find return NULL; } if (val == (tn -> value)) { // found return tn; } if (val < (tn -> value)) { // search the left side return Tree_search(tn -> left, val); } return Tree_search(tn -> right, val); }
TreeNode * Tree_search(TreeNode * tn, int val) /* * return a pointer to the node whose data is val * return NULL if no such node can be found */ { if (tn == NULL) { return NULL; // cannot find } if ((tn -> data) == val) { return tn; // found it } if ((tn -> data) > val) { return Tree_search(tn -> left, val); // go to the left side } return Tree_search(tn -> right, val); // go to the right side }
void Tree_add_somewhere(Node *node, int add_to, int value) { Node *parent = Tree_search(node, add_to); if(parent==NULL) { printf("Position you specified for adding does not exist.\n"); } else { Node *child = Node_create(value); Tree_add_child(parent, child); child->parent = parent; } }