예제 #1
0
void hashTree::destroyTable(treeNode *&root)
{
        if(root)
        {
            destroyTable(root->left);
            destroyTable(root->right);
            delete root;
            root = NULL;
        }
}
예제 #2
0
파일: hashtable.cpp 프로젝트: tbieker/CS260
const hashTable& hashTable::operator=(const hashTable& aTable){
	if(this == &aTable){
		return *this;
	}else{
		destroyTable();

		capacity = DEFAULT_CAPACITY;
		table = new node*[capacity];

		for(int i = 0; i < capacity; i++){
			if(aTable.table[i] == nullptr){
				table[i] = nullptr;
			}else{
				node * src;
				node * dest;

				table[i] = new node;
				table[i]->data = aTable.table[i]->data;

				dest = table[i];
				src = aTable.table[i]->next;
				while(src){
					dest->next = new node;
					dest->data = src->data;
					src = src->next;
				}
				dest->next = nullptr;
			}
		}
	}
    return *this;
}
예제 #3
0
int main() {

    hashTable h;

    h = init(10);
//    printf("size is %d\n", h->size);

    for(int i = 1; i < 20; i++)
        insert(i*i, h);

    if(find(11 * 11, h))
        printf("11*11 found\n");

    delete(11 * 11, h);

    for(int i = 1; i < 20; i += 2)
        if(!find(i * i, h))
            printf("%d deleted\n", i * i);
        else
            printf("%d found\n", i * i);

    destroyTable(h);
    return 0;

}
예제 #4
0
void destroyEnvironment(Environment *env){
  if (env){
    assert(env->bindings!=NULL);
    assert(env->bindings->type==tableType);
    destroyTable(env->bindings->tableValue);
    free(env->bindings);
    free(env);
  }
}
예제 #5
0
hashTree::~hashTree()
{
    int i;
    hashNode * curr = nullptr;
    destroyTable(root);
    for(i = 0; i < capacity; i++)
    {
        hashNode * prev;
        for(curr = table[i]; curr; curr = curr->next)
        {
            prev = curr;
            prev = nullptr;
        }
    }
    table = nullptr;
}
예제 #6
0
int main(int argc, char* argv[])
{
    FILE* file = NULL;
    STRING** table = NULL;
    int max = 0;

    checkParam(argc);

    file = fopen(argv[1], "r");
    checkFile(file, argv[1]);
    table = readFile(file);
    max = findMax(table);
    printMax(file, table, max);
    destroyTable(table);

    return 0;
}
예제 #7
0
void freeValue(Value *value){
  if (!value){
    return;
  }

  if (value->type == stringType){
    free(value->stringValue);
    free(value);
    
  }else if (value->type == symbolType){
    free(value->symbolValue);
    free(value);
  
  }else if (value->type == envType){
    //destroyFrame(value->envValue);
    //free(value);
  }else if (value->type == cellType){
    assert(value->cons!=NULL);
    assert(value->cons->car!=NULL);
    freeValue(value->cons->car);
    freeValue(value->cons->cdr);
    free(value->cons);
    free(value);

  }else if (value->type == primitiveType){
    
    free(value);
  }else if (value->type == closureType){
    destroyClosure(value->closureValue);
    free(value);
  }else if (value->type == tableType){
    destroyTable(value->tableValue);
    free(value);
  }else{
    free(value);
  }
   
}
예제 #8
0
파일: hashtable.cpp 프로젝트: tbieker/CS260
hashTable::~hashTable(){
  destroyTable();
  return;
}
예제 #9
0
int main(){

	HashTable *theTable = initTable(INITIAL_HASH_SIZE);
	addKey(theTable,"apple","pie");
	addKey(theTable,"orange","cider");
	addKey(theTable,"pikachu","rules");
	addKey(theTable,"en","un");
	addKey(theTable,"lugar de","la mancha");
	addKey(theTable,"de curyo","nombre no");
	addKey(theTable,"quiero","acordarme");
	addKey(theTable,"no hace","mucho que");
	addKey(theTable,"vivia un","hombre de");
	addKey(theTable,"rocin","flaco");
	addKey(theTable,"adarga antigua","y galgo corredor");
	addKey(theTable,"un sopin","mas que");
	addKey(theTable,"aaaabbbb","burp");
	addKey(theTable,"bbbbaaaa","meh");

	//uint32_t x = theTable->count;

	printAllPairs(theTable);


	deleteKey(theTable,"pikachu");
	deleteKey(theTable,"vivia un");
	deleteKey(theTable,"aaaabbbb");
	deleteKey(theTable,"en");

	printAllPairs(theTable);

	addKey(theTable,"animal","acordarme");
	addKey(theTable,"artic","mucho que");
	addKey(theTable,"antartic","hombre de");
	addKey(theTable,"metropolitan","flaco");
	addKey(theTable,"antimetro","y galgo corredor");
	addKey(theTable,"lumbersexual","mas que");
	addKey(theTable,"metrosexual","burp");
	addKey(theTable,"albaricoque","meh");
	addKey(theTable,"melocoton","acordarme");
	addKey(theTable,"ipad","mucho que");
	addKey(theTable,"ipodipod","hombre de");
	addKey(theTable,"ipad","flaco");
	addKey(theTable,"mallulah","y galgo corredor");
	addKey(theTable,"flashcard","mas que");
	addKey(theTable,"marker","burp");
	addKey(theTable,"whiteboard","meh");


	printAllPairs(theTable);

/*
	k = findKey(theTable,"pikachu");
	if(k) printf("pikachu: %s\n",k->value);
	else printf("Could not find the value\n");

	k = findKey(theTable,"lugar de");
	if(k) printf("lugar de: %s\n",k->value);
	else printf("Could not find the value\n");
	k = findKey(theTable,"de cuyo");
	if(k) printf("de cuyo: %s\n",k->value);
	else printf("Could not find the value\n");
	k = findKey(theTable,"quiero");
	if(k) printf("quiero : %s\n",k->value);
	else printf("Could not find the value\n");
	k = findKey(theTable,"no hace");
	if(k) printf("no hace: %s\n",k->value);
	else printf("Could not find the value\n");
*/

	destroyTable(theTable);

	return 0;
}