3 Intmap, allocmap, freemap, insertkey, caninsertkey, lookupkey,
4 deletekey \- integer to data structure maps
18 Intmap* allocmap(void (*inc)(void*))
19 void freemap(Intmap *map, void (*dec)(void*))
20 void* lookupkey(Intmap *map, ulong key)
21 void* insertkey(Intmap *map, ulong key, void *val)
22 int caninsertkey(Intmap *map, ulong key, void *val)
23 void* lookupkey(Intmap *map, ulong key)
24 void* deletekey(Intmap *map, ulong key)
29 is an arbitrary mapping from integers to pointers.
31 creates a new map, and
36 function is called each time a new pointer is added
37 to the map; similarly,
39 is called on each pointer left in the map
40 when it is being freed.
41 Typically these functions maintain reference counts.
42 New entries are added to the map by calling
44 which will return the previous value
45 associated with the given
47 or zero if there was no previous value.
53 if there is no current mapping.
56 was inserted, 0 otherwise.
58 returns the pointer associated with
60 or zero if there is no such pointer.
64 from the map, returning the
65 associated pointer, if any.
76 In anticipation of the storage of reference-counted
77 structures, an increment function
85 on pointers before returning them.
86 If the reference count adjustments were
87 left to the caller (and thus not protected by the lock),
88 it would be possible to accidentally reclaim a structure
89 if, for example, it was deleted from the map and its
90 reference count decremented between the return
93 and the external increment.
109 when returning old map entries.
110 The rationale is that calling
111 an insertion function transfers responsibility for the reference
112 to the map, and responsibility is given back via the return value of
118 are used by the 9P library to implement
123 .B /usr/local/plan9/src/lib9p/intmap.c