dict_t dict_remove(dict_t dict, word_t word) { assert((dict != NULL) && (word != NULL) && (dict_exists(dict, word))); index_t index_word = index_from_string(word); list_t new_list = list_remove(dict->list, index_word); index_word = index_destroy(index_word); dict->list = new_list; dict->length--; return (dict); }
dict_t dict_add(dict_t dict, word_t word, def_t def) { assert(dict != NULL && word != NULL && def != NULL && (!dict_exists(dict, word))); index_t index_word = index_from_string(word); data_t data_def = data_from_string(def); list_t new_list = list_append(dict->list, index_word, data_def); dict->list = new_list; dict->length++; return (dict); }
def_t dict_search(dict_t dict, word_t word) { assert(dict != NULL && word != NULL && dict_exists(dict, word)); index_t palabra = NULL; palabra = index_from_string(word); data_t definition = list_search(dict->list, palabra); def_t result = data_to_string(definition); palabra = index_destroy(palabra); assert(result != NULL); return (result); }
bool dict_exists(dict_t dict, word_t word) { assert(dict != NULL && word != NULL); bool result = false; index_t palabra = index_from_string(word); data_t definition = list_search(dict->list, palabra); if (definition != NULL) result = true; palabra = index_destroy(palabra); return (result); }
dict_t dict_add(dict_t dict, word_t word, def_t def) { assert(dict != NULL && word != NULL && def != NULL && !dict_exists(dict,word)); index_t index = index_from_string(word); data_t data = data_from_string(def); dict->length = dict->length +1; dict->data = list_add(dict->data,index,data); return dict; }
def_t dict_search(dict_t dict, word_t word) { index_t index = index_from_string(word); assert(dict != NULL && word != NULL && dict_exists(dict,word)); def_t result = NULL; result = data_to_string(list_search(dict->data,index)); free(index); index=NULL; assert(result != NULL); return result; }
bool dict_exists(dict_t dict, word_t word) { /*Precondition verification*/ assert(dict != NULL); assert(word != NULL); index_t index = index_from_string(word); data_t data = bst_search(dict->data, index); index_destroy(index); return (data != NULL); }
dict_t dict_remove(dict_t dict, word_t word) { assert(dict != NULL && word != NULL && dict_exists(dict, word)); index_t index = index_from_string(word); if(dict_exists(dict,word)) { dict->length = dict->length-1; dict->data = list_remove(dict->data,index); free(index); index = NULL; } return dict; }
dict_t dict_remove(dict_t dict, word_t word) { /*Precondition verification*/ assert(word != NULL); assert(dict != NULL); assert(dict_exists(dict, word)); index_t index = index_from_string(word); dict->data = bst_remove(dict->data, index); dict->length -= 1; index_destroy(index); return (dict); }
bool dict_exists(dict_t dict, word_t word) { assert(dict != NULL && word != NULL); index_t index = index_from_string(word); data_t def = NULL; def = list_search(dict->data, index); bool result = false; if(NULL != def) { result = true; } free(index); index = NULL; def = NULL; return result; }
def_t dict_search(dict_t dict, word_t word) { /*Precondition verification*/ assert(dict != NULL); assert(word != NULL); assert( dict_exists(dict, word) ); index_t index = index_from_string(word); data_t data = bst_search(dict->data, index); def_t definicion = data_to_string(data); index_destroy(index); /*Postcondition verification*/ assert(definicion != NULL); return (definicion); }
dict_t dict_add(dict_t dict, word_t word, def_t def) { /*Precondition verification*/ assert(dict != NULL); assert(word != NULL); assert(def != NULL); assert(!dict_exists(dict, word)); index_t index = index_from_string(word); data_t data = data_from_string(def); dict->length += 1; dict->data = bst_add(dict->data, index, data); /* POST: the elements of the result are the same as the one in 'dict' with * the new pair ('word', 'def') added.*/ return (dict); }