]> git.proxmox.com Git - libgit2.git/blame - src/vector.h
Merge pull request #392 from sschuberth/development
[libgit2.git] / src / vector.h
CommitLineData
bb742ede
VM
1/*
2 * Copyright (C) 2009-2011 the libgit2 contributors
3 *
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.
6 */
c4034e63
VM
7#ifndef INCLUDE_vector_h__
8#define INCLUDE_vector_h__
9
44908fe7 10#include "git2/common.h"
c4034e63 11
c4034e63 12typedef int (*git_vector_cmp)(const void *, const void *);
c4034e63
VM
13
14typedef struct git_vector {
15 unsigned int _alloc_size;
16 git_vector_cmp _cmp;
c4034e63
VM
17 void **contents;
18 unsigned int length;
86d7e1ca 19 int sorted;
c4034e63
VM
20} git_vector;
21
86d7e1ca 22int git_vector_init(git_vector *v, unsigned int initial_size, git_vector_cmp cmp);
c4034e63
VM
23void git_vector_free(git_vector *v);
24void git_vector_clear(git_vector *v);
25
86d7e1ca
VM
26int git_vector_search(git_vector *v, const void *entry);
27int git_vector_search2(git_vector *v, git_vector_cmp cmp, const void *key);
28
29int git_vector_bsearch(git_vector *v, const void *entry);
30int git_vector_bsearch2(git_vector *v, git_vector_cmp cmp, const void *key);
31
c4034e63
VM
32void git_vector_sort(git_vector *v);
33
86194b24
VM
34GIT_INLINE(void *) git_vector_get(git_vector *v, unsigned int position)
35{
36 return (position < v->length) ? v->contents[position] : NULL;
37}
c4034e63 38
bcf21c55
CMN
39#define git_vector_foreach(v, iter, elem) \
40 for ((iter) = 0; (iter) < (v)->length && ((elem) = (v)->contents[(iter)], 1); (iter)++ )
41
c4034e63
VM
42int git_vector_insert(git_vector *v, void *element);
43int git_vector_remove(git_vector *v, unsigned int idx);
476c42ac 44void git_vector_uniq(git_vector *v);
c4034e63 45#endif