diff options
-rw-r--r-- | src/sorted_array.c | 3 | ||||
-rw-r--r-- | zix/sorted_array.h | 16 |
2 files changed, 18 insertions, 1 deletions
diff --git a/src/sorted_array.c b/src/sorted_array.c index e841380..7d5358b 100644 --- a/src/sorted_array.c +++ b/src/sorted_array.c @@ -130,6 +130,7 @@ zix_sorted_array_index_unchecked(const ZixSortedArray* a, size_t index) return (char*)a->array + (a->elem_size * index); } +ZIX_API void* zix_sorted_array_index(const ZixSortedArray* a, size_t index) { @@ -155,7 +156,7 @@ zix_sorted_array_find(const ZixSortedArray* a, intptr_t upper = a->num_elems - 1; while (upper >= lower) { const size_t i = lower + ((upper - lower) / 2); - void* elem_i = zix_sorted_array_index(a, i); + void* elem_i = zix_sorted_array_index_unchecked(a, i); const int cmp = a->cmp(elem_i, e, a->cmp_data); if (cmp == 0) { diff --git a/zix/sorted_array.h b/zix/sorted_array.h index da3a1d4..1d508f2 100644 --- a/zix/sorted_array.h +++ b/zix/sorted_array.h @@ -1,3 +1,4 @@ + /* Copyright 2011 David Robillard <http://drobilla.net> @@ -45,6 +46,7 @@ typedef void* ZixSortedArrayIter; /** Create a new (empty) sorted array. */ +ZIX_API ZixSortedArray* zix_sorted_array_new(bool allow_duplicates, ZixComparator cmp, void* cmp_data, size_t elem_size); @@ -52,18 +54,21 @@ zix_sorted_array_new(bool allow_duplicates, ZixComparator cmp, void* cmp_data, /** Free @a a. */ +ZIX_API void zix_sorted_array_free(ZixSortedArray* a); /** Return the number of elements in @a a. */ +ZIX_API size_t zix_sorted_array_size(ZixSortedArray* a); /** Insert the element @a e into @a a and point @a ai at the new element. */ +ZIX_API ZixStatus zix_sorted_array_insert(ZixSortedArray* a, const void* e, @@ -72,6 +77,7 @@ zix_sorted_array_insert(ZixSortedArray* a, /** Remove the item pointed at by @a ai from @a a. */ +ZIX_API ZixStatus zix_sorted_array_remove(ZixSortedArray* a, ZixSortedArrayIter ai); @@ -79,41 +85,51 @@ zix_sorted_array_remove(ZixSortedArray* a, ZixSortedArrayIter ai); Set @a ai to be the largest element <= @a e in @a a. If no such item exists, @a ai is set to NULL. */ +ZIX_API ZixStatus zix_sorted_array_find(const ZixSortedArray* a, const void* e, ZixSortedArrayIter* ai); +/** + Return the element at index @a index. +*/ +ZIX_API void* zix_sorted_array_index(const ZixSortedArray* a, size_t index); /** Return the data associated with the given array item. */ +ZIX_API void* zix_sorted_array_get_data(ZixSortedArrayIter ai); /** Return an iterator to the first (smallest) element in @a a. */ +ZIX_API ZixSortedArrayIter zix_sorted_array_begin(ZixSortedArray* a); /** Return an iterator the the element one past the last element in @a a. */ +ZIX_API ZixSortedArrayIter zix_sorted_array_end(ZixSortedArray* a); /** Return true iff @a a is an iterator to the end of its tree. */ +ZIX_API bool zix_sorted_array_iter_is_end(ZixSortedArray* a, ZixSortedArrayIter i); /** Return an iterator that points to the element one past @a a. */ +ZIX_API ZixSortedArrayIter zix_sorted_array_iter_next(ZixSortedArray* a, ZixSortedArrayIter i); |