12 typedef struct Intlist Intlist;
39 allocmap(void (*inc)(void*))
43 m = emalloc9p(sizeof(*m));
51 freemap(Intmap *map, void (*destroy)(void*))
58 for(i=0; i<NHASH; i++){
59 for(p=map->hash[i]; p; p=nlink){
70 llookup(Intmap *map, ulong id)
74 for(lf=&map->hash[hashid(id)]; *lf; lf=&(*lf)->link)
81 * The RWlock is used as expected except that we allow
82 * inc() to be called while holding it. This is because we're
83 * locking changes to the tree structure, not to the references.
84 * Inc() is expected to have its own locking.
87 lookupkey(Intmap *map, ulong id)
93 if(f = *llookup(map, id)){
103 insertkey(Intmap *map, ulong id, void *v)
110 if(f = *llookup(map, id)){
111 /* no decrement for ov because we're returning it */
115 f = emalloc9p(sizeof(*f));
119 f->link = map->hash[h];
128 caninsertkey(Intmap *map, ulong id, void *v)
135 if(*llookup(map, id))
138 f = emalloc9p(sizeof *f);
142 f->link = map->hash[h];
151 deletekey(Intmap *map, ulong id)
157 if(f = *(lf = llookup(map, id))){