diff options
| author | Russell Belfer <rb@github.com> | 2013-01-09 16:00:16 -0800 |
|---|---|---|
| committer | Russell Belfer <rb@github.com> | 2013-01-15 09:51:35 -0800 |
| commit | 851ad65081793bb5fd65052907bf1c3c4e7e5729 (patch) | |
| tree | f548ff1dbc20894aebfabfe2cf6e19ba372bbfb0 /src/util.h | |
| parent | a49340c3e5de90ca551b46ea79573c428e3836b0 (diff) | |
| download | libgit2-851ad65081793bb5fd65052907bf1c3c4e7e5729.tar.gz | |
Add payload "_r" versions of bsearch and tsort
git__bsearch and git__tsort did not pass a payload through to the
comparison function. This makes it impossible to implement sorted
lists where the sort order depends on external data (e.g. building
a secondary sort order for the entries in a tree). This commit
adds git__bsearch_r and git__tsort_r versions that pass a third
parameter to the cmp function of a user payload.
Diffstat (limited to 'src/util.h')
| -rw-r--r-- | src/util.h | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/src/util.h b/src/util.h index ee0d0e3ed..9bcd3203e 100644 --- a/src/util.h +++ b/src/util.h @@ -119,7 +119,15 @@ GIT_INLINE(const char *) git__next_line(const char *s) return s; } -extern void git__tsort(void **dst, size_t size, int (*cmp)(const void *, const void *)); +typedef int (*git__tsort_cmp)(const void *a, const void *b); + +extern void git__tsort(void **dst, size_t size, git__tsort_cmp cmp); + +typedef int (*git__tsort_r_cmp)(const void *a, const void *b, void *payload); + +extern void git__tsort_r( + void **dst, size_t size, git__tsort_r_cmp cmp, void *payload); + /** * @param position If non-NULL, this will be set to the position where the @@ -130,7 +138,15 @@ extern int git__bsearch( void **array, size_t array_len, const void *key, - int (*compare)(const void *, const void *), + int (*compare)(const void *key, const void *element), + size_t *position); + +extern int git__bsearch_r( + void **array, + size_t array_len, + const void *key, + int (*compare_r)(const void *key, const void *element, void *payload), + void *payload, size_t *position); extern int git__strcmp_cb(const void *a, const void *b); |
