Beispiel #1
0
/* Adds a key-value pair to a map. */
void map_add(Map *map, Hashable *key, Value *value)
{
    int hashval = hash_hashable(key) % map->n;
    Node *list = map->lists[hashval];
    
    map->lists[hashval] = prepend(key, value, list);
}
Beispiel #2
0
/* Looks up a key and returns the corresponding value, or NULL. */
Value *map_lookup(Map *map, Hashable *key)
{
    int hashval = hash_hashable(key) % map->n;
    Node *list = map->lists[hashval];
    
    return list_lookup(list, key);
}
Beispiel #3
0
/* Finds which list a key is in */
int map_index(Map *map, Hashable *key) {
    unsigned int hash, step;

    hash = (unsigned int) hash_hashable(key);
    step = UINT_MAX / map->n;
    return (int) (hash / step);
}
Beispiel #4
0
/* Looks up a key and returns the corresponding value, or NULL. */
Value *map_lookup(Map *map, Hashable *key)
{
    int index;
    Node *list;

    index = hash_hashable(key) % map->n;
    list = (map->lists)[index];
    return list_lookup(list, key);
}
Beispiel #5
0
/* Adds a key-value pair to a map. */
void map_add(Map *map, Hashable *key, Value *value)
{
    // FIX ME! done
    int index;
    Node *list;

    index = hash_hashable(key) % map->n;
    list = (map->lists)[index];
    (map->lists)[index] = make_node(key, value, list);
}
Beispiel #6
0
/* Looks up a key and returns the corresponding value, or NULL. */
Value *map_lookup(Map *map, Hashable *key)
{
    int hashValue = hash_hashable(key);
    if(hashValue > map->n - 1){
        hashValue = hashValue % (map->n -1);
    }
    if (map->lists[hashValue]){
        return list_lookup(map->lists[hashValue],key);
    }
    return NULL;
}
Beispiel #7
0
/* Adds a key-value pair to a map. */
void map_add(Map *map, Hashable *key, Value *value)
{
    int hashValue = hash_hashable(key);
    if(hashValue > map->n - 1){
        hashValue = hashValue % (map->n -1);
    }
    if(map->lists[hashValue]) {
        Node *checkNode = map->lists[hashValue];
        while(checkNode->next){
            checkNode = checkNode->next;
        }
        checkNode->next = make_node(key, value, NULL);
    }else{
        map->lists[hashValue] = make_node(key, value, NULL);
    }
}
Beispiel #8
0
/* Adds a key-value pair to a map. */
void map_add(Map *map, Hashable *key, Value *value)
{
    int hashed_val = hash_hashable(key);
    if
}
Beispiel #9
0
int get_map_index(Map *map, Hashable *key) {
    return hash_hashable(key) % map->n;
}