]>
git.proxmox.com Git - libgit2.git/blob - src/vector.h
2 * Copyright (C) 2009-2011 the libgit2 contributors
4 * This file is part of libgit2, distributed under the GNU GPL v2 with
5 * a Linking Exception. For full terms see the included COPYING file.
7 #ifndef INCLUDE_vector_h__
8 #define INCLUDE_vector_h__
10 #include "git2/common.h"
12 typedef int (*git_vector_cmp
)(const void *, const void *);
14 typedef struct git_vector
{
15 unsigned int _alloc_size
;
22 int git_vector_init(git_vector
*v
, unsigned int initial_size
, git_vector_cmp cmp
);
23 void git_vector_free(git_vector
*v
);
24 void git_vector_clear(git_vector
*v
);
26 int git_vector_search(git_vector
*v
, const void *entry
);
27 int git_vector_search2(git_vector
*v
, git_vector_cmp cmp
, const void *key
);
29 int git_vector_bsearch(git_vector
*v
, const void *entry
);
30 int git_vector_bsearch2(git_vector
*v
, git_vector_cmp cmp
, const void *key
);
32 void git_vector_sort(git_vector
*v
);
34 GIT_INLINE(void *) git_vector_get(git_vector
*v
, unsigned int position
)
36 return (position
< v
->length
) ? v
->contents
[position
] : NULL
;
39 #define git_vector_foreach(v, iter, elem) \
40 for ((iter) = 0; (iter) < (v)->length && ((elem) = (v)->contents[(iter)], 1); (iter)++ )
42 int git_vector_insert(git_vector
*v
, void *element
);
43 int git_vector_remove(git_vector
*v
, unsigned int idx
);
44 void git_vector_uniq(git_vector
*v
);