diff options
author | Vicent Marti <tanoku@gmail.com> | 2010-12-02 04:31:54 +0200 |
---|---|---|
committer | Vicent Marti <tanoku@gmail.com> | 2010-12-02 04:31:54 +0200 |
commit | c4034e63f358cfed6bd851a831c50dbcd5006ffe (patch) | |
tree | 2417969470e0b1e8a65b928c711ab5dab34eb9c8 /src/vector.h | |
parent | 1e35f929ef0df0e28c14655fa47406732f30cc73 (diff) | |
download | libgit2-c4034e63f358cfed6bd851a831c50dbcd5006ffe.tar.gz |
Refactor all 'vector' functions into common code
All the operations on the 'git_index_entry' array and the
'git_tree_entry' array have been refactored into common code in the
src/vector.c file.
The new vector methods support:
- insertion: O(1) (avg)
- deletion: O(n)
- searching: O(logn)
- sorting: O(logn)
- r. access: O(1)
Signed-off-by: Vicent Marti <tanoku@gmail.com>
Diffstat (limited to 'src/vector.h')
-rw-r--r-- | src/vector.h | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/vector.h b/src/vector.h new file mode 100644 index 000000000..8239abade --- /dev/null +++ b/src/vector.h @@ -0,0 +1,32 @@ +#ifndef INCLUDE_vector_h__ +#define INCLUDE_vector_h__ + +#include "git/common.h" + + +typedef int (*git_vector_cmp)(const void *, const void *); +typedef int (*git_vector_srch)(const void *, const void *); + +typedef struct git_vector { + unsigned int _alloc_size; + git_vector_cmp _cmp; + git_vector_srch _srch; + + void **contents; + unsigned int length; +} git_vector; + + +int git_vector_init(git_vector *v, unsigned int initial_size, git_vector_cmp cmp, git_vector_srch srch); +void git_vector_free(git_vector *v); +void git_vector_clear(git_vector *v); + +int git_vector_search(git_vector *v, const void *key); +void git_vector_sort(git_vector *v); + +void *git_vector_get(git_vector *v, unsigned int position); + +int git_vector_insert(git_vector *v, void *element); +int git_vector_remove(git_vector *v, unsigned int idx); + +#endif |