next up previous contents index
Next: Usage Rules Up: Map Operations Previous: mapClose

mapForEach

   

Allows iterative access to the entries of a map by the provided callback function func. Each call to mapForEach puts the external key and its internal id into arguments passed the function func. The third argument passed to func is the supplied value arg. As long as the flag MFE_CONTINUE is set in the callback function's return value and there are unprocessed keys, mapForEach will continue to call func.

If the flag MFE_REMOVE is set in the return value of the callback function, mapForEach will remove the entry from the map after the user function returns and before it is called with the next map entry. This is the only correct way to remove the ``current'' map entry during a mapForEach operation. If the user callback function attempts to remove the ``current'' entry directly (via mapRemoveBinding or mapRemoveKey), the result is unpredictable and may result in system crashes.

It is currently possible to remove entries other than the ``current'' entry from within the callback function. However, we strongly discourage such use as its correctness depends on implementation details that may change in future versions of the x-kernel .

New map entries added in the middle of a mapForEach iteration may or may not show up during that iteration. Map manipulations within a mapForEach user function are generally not recommended.

MFE_REMOVE and MFE_CONTINUE are binary flags which may be combined using bitwise OR. The order in which keys are returned depends on the internal structure of the map.

void mapForEach(Map map, MapForEachFun func, void *arg)

typedef int MapForEachFun(void *key, void *id, void *arg)



Larry Peterson
Wed Jan 10 10:40:08 MST 1996