diff options
author | David Robillard <d@drobilla.net> | 2011-09-15 16:10:34 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2011-09-15 16:10:34 +0000 |
commit | 62585c184ed99cb8acc11b025be414752d8b0240 (patch) | |
tree | 1c312e39cf2235dd35ac0ba13cd9f2d02c8ad5a0 /zix | |
parent | 4547add54e051067e450ad13115d7b864c14a384 (diff) | |
download | zix-62585c184ed99cb8acc11b025be414752d8b0240.tar.gz zix-62585c184ed99cb8acc11b025be414752d8b0240.tar.bz2 zix-62585c184ed99cb8acc11b025be414752d8b0240.zip |
Add ZixSortedArray.
git-svn-id: http://svn.drobilla.net/zix/trunk@9 df6676b4-ccc9-40e5-b5d6-7c4628a128e3
Diffstat (limited to 'zix')
-rw-r--r-- | zix/sorted_array.h | 125 |
1 files changed, 125 insertions, 0 deletions
diff --git a/zix/sorted_array.h b/zix/sorted_array.h new file mode 100644 index 0000000..355bdf2 --- /dev/null +++ b/zix/sorted_array.h @@ -0,0 +1,125 @@ +/* + Copyright 2011 David Robillard <http://drobilla.net> + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +#ifndef ZIX_SORTED_ARRAY_H +#define ZIX_SORTED_ARRAY_H + +#include <stdbool.h> + +#include "zix/common.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + @addtogroup zix + @{ + @name SortedArray + @{ +*/ + +/** + A sorted array. +*/ +typedef struct ZixSortedArrayImpl ZixSortedArray; + +/** + An iterator over a @ref ZixSortedArray. +*/ +typedef void* ZixSortedArrayIter; + +/** + Create a new (empty) sorted array. +*/ +ZixSortedArray* +zix_sorted_array_new(bool allow_duplicates, ZixComparator cmp, void* cmp_data, + size_t elem_size); + +/** + Free @a a. +*/ +void +zix_sorted_array_free(ZixSortedArray* a); + +/** + Return the number of elements in @a a. +*/ +size_t +zix_sorted_array_size(ZixSortedArray* a); + +/** + Insert the element @a e into @a a and point @a ai at the new element. +*/ +ZixStatus +zix_sorted_array_insert(ZixSortedArray* a, const void* e, ZixSortedArrayIter* ai); + +/** + Remove the item pointed at by @a ai from @a a. +*/ +ZixStatus +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. +*/ +ZixStatus +zix_sorted_array_find(const ZixSortedArray* a, const void* e, ZixSortedArrayIter* ai); + +void* +zix_sorted_array_index(const ZixSortedArray* a, size_t index); + +/** + Return the data associated with the given array item. +*/ +void* +zix_sorted_array_get_data(ZixSortedArrayIter ai); + +/** + Return an iterator to the first (smallest) element in @a a. +*/ +ZixSortedArrayIter +zix_sorted_array_begin(ZixSortedArray* a); + +/** + Return an iterator the the element one past the last element in @a a. +*/ +ZixSortedArrayIter +zix_sorted_array_end(ZixSortedArray* a); + +/** + Return true iff @a a is an iterator to the end of its tree. +*/ +bool +zix_sorted_array_iter_is_end(ZixSortedArray* a, ZixSortedArrayIter i); + +/** + Return an iterator that points to the element one past @a a. +*/ +ZixSortedArrayIter +zix_sorted_array_iter_next(ZixSortedArray* a, ZixSortedArrayIter i); + +/** + @} + @} +*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* ZIX_SORTED_ARRAY_H */ |