Esempio n. 1
0
void hashmap_add_list(hashmap_t* hashmap, list_value_t* lt) {
    hashmap_node_t* tmp_node;
    while(lt!=NULL) {
        tmp_node = hashmap_node_create(hashmap_hash(lt->key), lt);
        hashmap_set(hashmap, tmp_node);
        lt=lt->next;
    }

}
Esempio n. 2
0
hashmap_node_t* hashmap_find(hashmap_t* hashmap,char *string) {
    char* key;
    list_value_t* find=JSON_parse(string);
    key=find->key;
    int create=1;
    hashmap_node_t* result=NULL;
    if(strlen(key)==0) {
        int i;
        for(i=0; i<BUCKET_NUMBER; i++) {
            hashmap_node_t* tmp=hashmap->map[i];
            while (tmp!=NULL) {
                if(create) {
                    result=hashmap_node_create(0, tmp->lt);
                    create=0;
                } else
                    hashmap_node_append_node(result, hashmap_node_create(0, tmp->lt));
                tmp=tmp->next;
            }
        }
        return result;
    } else {
        uint32_t hash=hashmap_hash(key);
        hashmap_node_t* bucket = *hashmap_get_bucket(hashmap, hash);
        if(bucket==NULL)
            return bucket;
        else {
            while(bucket!=NULL) {
                if(bucket->hash==hash && strcmp(key,bucket->lt->key)==0 && value_compare(find, bucket->lt)==0) {
                    if(create) {
                        result=hashmap_node_create(hash, bucket->lt);
                        create=0;
                    } else
                        hashmap_node_append_node(result, hashmap_node_create(hash, bucket->lt));
                }
                bucket=bucket->next;
            }
        }
        return result;
    }
}
Esempio n. 3
0
int hashmap_set(Hashmap *map, void *key, void *data) {
    uint32_t hash = 0;
    DArray *bucket = hashmap_find_bucket(map, key, 1, &hash);
    check(bucket, "error: can't create bucket");

    HashmapNode *node = hashmap_node_create(hash, key, data);
    check_mem(node);

    darray_push(bucket, node);

    return 0;

error:
    return -1;
}