Next: , Previous: , Up: Run-time library functions   [Contents][Index]


6.3.10 Unordered-set functions

Because unordered collections of data are a widely applicable construct, the run-time library provides support for sets. A set contains zero or more keys, each of which must be unique within the set. Furthermore, each key can be associated with a data value. Sets are currently implemented in the coNCePTuaL run-time library as hash tables.

Function: NCPTL_SET * ncptl_set_init (ncptl_int numelts, ncptl_int keybytes, ncptl_int valuebytes)

Allocate and initialize a set object and return a pointer to it. Each element in the set maps a keybytes-byte key to a valuebytes-byte value. The numelts parameter is an estimate of the maximum number of elements in the set. ncptl_set_init() returns a pointer to the set.

Function: void * ncptl_set_find (NCPTL_SET *set, void *key)

Given a set and a pointer to a key, return a pointer to the associated value or NULL if the key is not found in the set.

Function: void ncptl_set_insert (NCPTL_SET *set, void *key, void *value)

Insert a key into a set and associate a value with it. ncptl_set_insert() copies both key and value so stack-allocated keys and values are acceptable inputs. The run-time library aborts with an error message if the key is already in the set.

Function: void ncptl_set_walk (NCPTL_SET *set, void (*userfunc)(void *, void *))

Execute function userfunc for every <key:value> pair in a set. userfunc must take two void * values as input: a pointer to a key and a pointer to a value. The order in which keys and values are passed to the function is unspecified.

Function: void ncptl_set_remove (NCPTL_SET *set, void *key)

Remove a key and its associated value from a set. The run-time library aborts with an error message if the key is not found in the set.

Function: void ncptl_set_empty (NCPTL_SET *set)

Empty a set, freeing the memory that had been allocated for its contents. The set itself can continue to be used and should be deallocated with ncptl_free() (see Memory-allocation functions) when no longer needed.

Function: ncptl_int ncptl_set_length (NCPTL_SET *set)

Return the number of <key:value> pairs in set set.


Next: , Previous: , Up: Run-time library functions   [Contents][Index]

Scott Pakin, pakin@lanl.gov