File: hashmapinsert.c

package info (click to toggle)
yodl 4.05.02-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,724 kB
  • sloc: ansic: 7,803; perl: 683; cpp: 570; sh: 411; xml: 190; makefile: 163
file content (28 lines) | stat: -rw-r--r-- 502 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include "hashmap.ih"

/*  returns idx of inserted element or FAILED, if already inserted */

Result hashmap_insert(register HashMap *map, register HashItem *hashitem)
{
    size_t idx;

    if (map->d_n * 100 > map->d_size * 70)
        hm_expand(map);

    if
    (
        hm_find(&idx, map->d_map, map->d_size,
                                hashitem_key(hashitem)) == UFAILED
    )
    {
        map->d_map[idx] = hashitem;
        map->d_n++;
        return idx;
    }
    return FAILED;
}