]> git.ozlabs.org Git - ccan/commit
order: Module for comparison callbacks
authorDavid Gibson <david@gibson.dropbear.id.au>
Tue, 2 Jun 2015 07:26:49 +0000 (17:26 +1000)
committerDavid Gibson <david@gibson.dropbear.id.au>
Thu, 18 Jun 2015 09:26:40 +0000 (19:26 +1000)
commitc2a3098b254830f33e800bfa398882786632631e
treefc7fdeb3ba905e8299405765c1dd6f0e4ccc556e
parent04b63db616a482d6ed0f51a3ede8001415884bab
order: Module for comparison callbacks

Many common algorithms take a callback for comparing items - effectively
giving the items a user defined order.

For example, the standard library qsort() and bsearch() routines take such
a callback.  The ccan/avl module takes an identical one.  The ccan/asort
and ccan/asearch modules use a different variant: their callback takes an
additional context parameter, and is also typed via use of macros and
typesafe_cb.

This module provides helper types and macros for easily declaring any of
the common variants on comparison functions: the 2-parameter untyped form
(as used by qsort), the 3-parameter untyped form (used by the asort back
end) and the 3-parameter typed form (used by the asort front end).  It
provides a wrapper macro for doing the typesafe_cb conversion from
3-parameter typed to 3-parameter untyped.

It also provides a container struct to describe both a comparison callback
and a context value as a single structure.  This also comes in both
untyped and typed variants.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
ccan/order/LICENSE [new symlink]
ccan/order/_info [new file with mode: 0644]
ccan/order/order.h [new file with mode: 0644]
ccan/order/test/compile_fail_1.c [new file with mode: 0644]
ccan/order/test/compile_fail_2.c [new file with mode: 0644]
ccan/order/test/compile_ok.c [new file with mode: 0644]
ccan/order/test/fancy_cmp.h [new file with mode: 0644]