Next: , Previous: Chain insertion, Up: Chains


13.6 Traversing a chain

— Function pointer: Chain_walk_f int (*) (void *obj, void *args

The type of a function pointer used to perform arbitrary actions on an object in a chain. The function is passed a pointer to an object, obj, as well as a user-supplied pointer to parameters, args. The function should return zero on success, or -1 on some error which must terminate the traversal of the chain holding obj.

— Function: void chain_walk (Chain *chain, Chain_walk_f walker, void *walk_args)
— Function: void chain_rwalk (Chain *chain, Chain_walk_f walker, void *walk_args)

Calls walker on every node in chain. Stops traversing if walker returns a negative value on any node. walk_args is passed as the last argument to walker. ‘chain_walk’ starts from the front of chain and traverses in order, while ‘chain_rwalk’ starts from the back and traverses in reverse order.