Ejemplo n.º 1
0
Archivo: node.c Proyecto: yipf/C-lisp
node_t hash_pop_value(char* key, int pop){
	node_t target,value;
	target=get_node((HASH+key2hash(key,NUM))->cdr,key);
	value=0;
	if(target&&(value=target->child)&&pop){		target->child=value->cdr; 	}
	return value?(value->child):0;
}
Ejemplo n.º 2
0
	void hash_table_remove(hash_table *ht, const wchar_t *key) {
		size_t hash = key2hash(key, ht->rows);
		struct hash_table_sub_list *p;
		assert(ht != NULL);
		assert(ht->table != NULL);
		assert(key != NULL);
		if (ht->table[hash] == NULL)
			return;
		p = ht->table[hash];
		do {
			if (wcscmp(p->key, key) == 0) {
				if (p == ht->table[hash])
					ht->table[hash] = p->next;
				if (p->prev != NULL)
					p->prev->next = p->next;
				if (p->next != NULL)
					p->next->prev = p->prev;
				assert(p->key != NULL);
				free(p->key);
				free(p);
				return;
			}
			p = p->next;
		} while (p != NULL);
		return;
	}
Ejemplo n.º 3
0
Archivo: node.c Proyecto: yipf/C-lisp
char* unique_string(char* string){
	string_node_t head,node;
	head=STRINGS+key2hash(string,NUM);
	node=head->next;
	while(node&&strcmp(string,node->key)){node=node->next;}
	if(node){		return node->key; }
	node=calloc(1,sizeof(string_node_));
	node->key=string; 	node->next=head->next; 	head->next=node;
	return string;
}
Ejemplo n.º 4
0
	palo_err hash_table_add_or_update_ex(hash_table *ht, const wchar_t *key, void *data, palo_bool *updated, void **old_data) {
		struct hash_table_sub_list *p;
		size_t hash = key2hash(key, ht->rows);

		assert(ht != NULL);
		assert(key != NULL);
		assert(updated != NULL);
		assert(old_data != NULL);

		*updated = PALO_FALSE;

		if (ht->table[hash] == NULL) {
			ht->table[hash] = (struct hash_table_sub_list*)malloc(sizeof(struct hash_table_sub_list));
			if (ht->table[hash] == NULL)
				return PALO_ERR_NO_MEM;
			ht->table[hash]->next = NULL;
			ht->table[hash]->prev = NULL;
			ht->table[hash]->data = data;
			ht->table[hash]->key = wcsdup(key);
			if (ht->table[hash]->key == NULL) {
				free(ht->table[hash]);
				ht->table[hash] = NULL;
				return PALO_ERR_NO_MEM;
			}
		} else {
			p = ht->table[hash];
			while (p->next != NULL && wcscmp(p->key, key) != 0)
				p = p->next;
			if (wcscmp(p->key, key) == 0) {
				/* update */
				*old_data = p->data;
				p->data = data;
				*updated = PALO_TRUE;
			} else {
				/* add */
				p->next = (struct hash_table_sub_list*)malloc(sizeof(struct hash_table_sub_list));
				if (p->next == NULL)
					return PALO_ERR_NO_MEM;
				p->next->key = wcsdup(key);
				if (p->next->key == NULL) {
					free(p->next);
					p->next = NULL;
					return PALO_ERR_NO_MEM;
				}
				p->next->next = NULL;
				p->next->prev = p;
				p->next->data = data;
			}
		}
		return PALO_SUCCESS;
	}
Ejemplo n.º 5
0
Archivo: node.c Proyecto: yipf/C-lisp
node_t hash_push_value(char* key,node_t value){
	node_t head,target,nvalue;
	head=HASH+key2hash(key,NUM);
	target=get_node(head->cdr,key);
	if(!target){
		target=alloc_node(key);
		target->cdr=head->cdr;
		head->cdr=target;
	}
	nvalue=alloc_node(key);
	nvalue->child=value;
	node->child=push_value(node->child,nvalue);
	return value;
}
Ejemplo n.º 6
0
	void *hash_table_find(const hash_table *ht, const wchar_t *key) {
		size_t hash = key2hash(key, ht->rows);
		struct hash_table_sub_list *p;
		assert(ht != NULL);
		assert(ht->table != NULL);
		assert(key != NULL);
		if (ht->table[hash] == NULL)
			return NULL;
		p = ht->table[hash];
		while (p != NULL) {
			if (wcscmp(p->key, key) == 0)
				return p->data;
			p = p->next;
		}
		return NULL;
	}