Commit 16248ee2 by Russell Belfer Committed by Ben Straub

Fix up some missing consts in tree & index

This fixes some missed places where we can apply const-ness to
various public APIs.

There are still some index and tree APIs that cannot take const
pointers because we sort our `git_vectors` lazily and so we can't
reliably bsearch the index and tree content without applying a
`git_vector_sort()` first.

This also fixes some missed places where size_t can be used and
where const can be applied to a couple internal functions.
parent f45d51ff
...@@ -258,7 +258,7 @@ GIT_EXTERN(int) git_index_write_tree_to(git_oid *out, git_index *index, git_repo ...@@ -258,7 +258,7 @@ GIT_EXTERN(int) git_index_write_tree_to(git_oid *out, git_index *index, git_repo
* @param index an existing index object * @param index an existing index object
* @return integer of count of current entries * @return integer of count of current entries
*/ */
GIT_EXTERN(unsigned int) git_index_entrycount(git_index *index); GIT_EXTERN(unsigned int) git_index_entrycount(const git_index *index);
/** /**
* Clear the contents (all the entries) of an index object. * Clear the contents (all the entries) of an index object.
...@@ -282,7 +282,8 @@ GIT_EXTERN(void) git_index_clear(git_index *index); ...@@ -282,7 +282,8 @@ GIT_EXTERN(void) git_index_clear(git_index *index);
* @param n the position of the entry * @param n the position of the entry
* @return a pointer to the entry; NULL if out of bounds * @return a pointer to the entry; NULL if out of bounds
*/ */
GIT_EXTERN(const git_index_entry *) git_index_get_byindex(git_index *index, size_t n); GIT_EXTERN(const git_index_entry *) git_index_get_byindex(
git_index *index, size_t n);
/** /**
* Get a pointer to one of the entries in the index * Get a pointer to one of the entries in the index
...@@ -298,7 +299,8 @@ GIT_EXTERN(const git_index_entry *) git_index_get_byindex(git_index *index, size ...@@ -298,7 +299,8 @@ GIT_EXTERN(const git_index_entry *) git_index_get_byindex(git_index *index, size
* @param stage stage to search * @param stage stage to search
* @return a pointer to the entry; NULL if it was not found * @return a pointer to the entry; NULL if it was not found
*/ */
GIT_EXTERN(const git_index_entry *) git_index_get_bypath(git_index *index, const char *path, int stage); GIT_EXTERN(const git_index_entry *) git_index_get_bypath(
git_index *index, const char *path, int stage);
/** /**
* Remove an entry from the index * Remove an entry from the index
...@@ -443,7 +445,7 @@ GIT_EXTERN(void) git_index_conflict_cleanup(git_index *index); ...@@ -443,7 +445,7 @@ GIT_EXTERN(void) git_index_conflict_cleanup(git_index *index);
* *
* @return 1 if at least one conflict is found, 0 otherwise. * @return 1 if at least one conflict is found, 0 otherwise.
*/ */
GIT_EXTERN(int) git_index_has_conflicts(git_index *index); GIT_EXTERN(int) git_index_has_conflicts(const git_index *index);
/**@}*/ /**@}*/
......
...@@ -127,7 +127,7 @@ GIT_EXTERN(const git_tree_entry *) git_tree_entry_byindex( ...@@ -127,7 +127,7 @@ GIT_EXTERN(const git_tree_entry *) git_tree_entry_byindex(
* @return the tree entry; NULL if not found * @return the tree entry; NULL if not found
*/ */
GIT_EXTERN(const git_tree_entry *) git_tree_entry_byoid( GIT_EXTERN(const git_tree_entry *) git_tree_entry_byoid(
git_tree *tree, const git_oid *oid); const git_tree *tree, const git_oid *oid);
/** /**
* Retrieve a tree entry contained in a tree or in any of its subtrees, * Retrieve a tree entry contained in a tree or in any of its subtrees,
...@@ -351,18 +351,15 @@ typedef enum { ...@@ -351,18 +351,15 @@ typedef enum {
} git_treewalk_mode; } git_treewalk_mode;
/** /**
* Traverse the entries in a tree and its subtrees in * Traverse the entries in a tree and its subtrees in post or pre order.
* post or pre order
* *
* The entries will be traversed in the specified order, * The entries will be traversed in the specified order, children subtrees
* children subtrees will be automatically loaded as required, * will be automatically loaded as required, and the `callback` will be
* and the `callback` will be called once per entry with * called once per entry with the current (relative) root for the entry and
* the current (relative) root for the entry and the entry * the entry data itself.
* data itself.
* *
* If the callback returns a positive value, the passed entry will be * If the callback returns a positive value, the passed entry will be
* skipped on the traversal (in pre mode). A negative value stops the * skipped on the traversal (in pre mode). A negative value stops the walk.
* walk.
* *
* @param tree The tree to walk * @param tree The tree to walk
* @param mode Traversal mode (pre or post-order) * @param mode Traversal mode (pre or post-order)
......
...@@ -298,7 +298,7 @@ static void index_free(git_index *index) ...@@ -298,7 +298,7 @@ static void index_free(git_index *index)
{ {
git_index_entry *e; git_index_entry *e;
git_index_reuc_entry *reuc; git_index_reuc_entry *reuc;
unsigned int i; size_t i;
git_index_clear(index); git_index_clear(index);
git_vector_foreach(&index->entries, i, e) { git_vector_foreach(&index->entries, i, e) {
...@@ -488,20 +488,22 @@ int git_index_write_tree_to(git_oid *oid, git_index *index, git_repository *repo ...@@ -488,20 +488,22 @@ int git_index_write_tree_to(git_oid *oid, git_index *index, git_repository *repo
return git_tree__write_index(oid, index, repo); return git_tree__write_index(oid, index, repo);
} }
unsigned int git_index_entrycount(git_index *index) unsigned int git_index_entrycount(const git_index *index)
{ {
assert(index); assert(index);
return (unsigned int)index->entries.length; return (unsigned int)index->entries.length;
} }
const git_index_entry *git_index_get_byindex(git_index *index, size_t n) const git_index_entry *git_index_get_byindex(
git_index *index, size_t n)
{ {
assert(index); assert(index);
git_vector_sort(&index->entries); git_vector_sort(&index->entries);
return git_vector_get(&index->entries, n); return git_vector_get(&index->entries, n);
} }
const git_index_entry *git_index_get_bypath(git_index *index, const char *path, int stage) const git_index_entry *git_index_get_bypath(
git_index *index, const char *path, int stage)
{ {
int pos; int pos;
...@@ -810,13 +812,15 @@ int git_index_find(git_index *index, const char *path) ...@@ -810,13 +812,15 @@ int git_index_find(git_index *index, const char *path)
assert(index && path); assert(index && path);
if ((pos = git_vector_bsearch2(&index->entries, index->entries_search_path, path)) < 0) if ((pos = git_vector_bsearch2(
&index->entries, index->entries_search_path, path)) < 0)
return pos; return pos;
/* Since our binary search only looked at path, we may be in the /* Since our binary search only looked at path, we may be in the
* middle of a list of stages. */ * middle of a list of stages.
*/
while (pos > 0) { while (pos > 0) {
git_index_entry *prev = git_vector_get(&index->entries, pos-1); const git_index_entry *prev = git_vector_get(&index->entries, pos-1);
if (index->entries_cmp_path(prev->path, path) != 0) if (index->entries_cmp_path(prev->path, path) != 0)
break; break;
...@@ -827,10 +831,10 @@ int git_index_find(git_index *index, const char *path) ...@@ -827,10 +831,10 @@ int git_index_find(git_index *index, const char *path)
return pos; return pos;
} }
unsigned int git_index__prefix_position(git_index *index, const char *path) size_t git_index__prefix_position(git_index *index, const char *path)
{ {
struct entry_srch_key srch_key; struct entry_srch_key srch_key;
unsigned int pos; size_t pos;
srch_key.path = path; srch_key.path = path;
srch_key.stage = 0; srch_key.stage = 0;
...@@ -961,7 +965,7 @@ int git_index_conflict_remove(git_index *index, const char *path) ...@@ -961,7 +965,7 @@ int git_index_conflict_remove(git_index *index, const char *path)
return error; return error;
} }
static int index_conflicts_match(git_vector *v, size_t idx) static int index_conflicts_match(const git_vector *v, size_t idx)
{ {
git_index_entry *entry = git_vector_get(v, idx); git_index_entry *entry = git_vector_get(v, idx);
...@@ -979,9 +983,9 @@ void git_index_conflict_cleanup(git_index *index) ...@@ -979,9 +983,9 @@ void git_index_conflict_cleanup(git_index *index)
git_vector_remove_matching(&index->entries, index_conflicts_match); git_vector_remove_matching(&index->entries, index_conflicts_match);
} }
int git_index_has_conflicts(git_index *index) int git_index_has_conflicts(const git_index *index)
{ {
unsigned int i; size_t i;
git_index_entry *entry; git_index_entry *entry;
assert(index); assert(index);
...@@ -1361,7 +1365,7 @@ static int parse_index(git_index *index, const char *buffer, size_t buffer_size) ...@@ -1361,7 +1365,7 @@ static int parse_index(git_index *index, const char *buffer, size_t buffer_size)
static int is_index_extended(git_index *index) static int is_index_extended(git_index *index)
{ {
unsigned int i, extended; size_t i, extended;
git_index_entry *entry; git_index_entry *entry;
extended = 0; extended = 0;
...@@ -1374,7 +1378,7 @@ static int is_index_extended(git_index *index) ...@@ -1374,7 +1378,7 @@ static int is_index_extended(git_index *index)
} }
} }
return extended; return (int)extended;
} }
static int write_disk_entry(git_filebuf *file, git_index_entry *entry) static int write_disk_entry(git_filebuf *file, git_index_entry *entry)
...@@ -1440,7 +1444,7 @@ static int write_disk_entry(git_filebuf *file, git_index_entry *entry) ...@@ -1440,7 +1444,7 @@ static int write_disk_entry(git_filebuf *file, git_index_entry *entry)
static int write_entries(git_index *index, git_filebuf *file) static int write_entries(git_index *index, git_filebuf *file)
{ {
int error = 0; int error = 0;
unsigned int i; size_t i;
git_vector case_sorted; git_vector case_sorted;
git_index_entry *entry; git_index_entry *entry;
git_vector *out = &index->entries; git_vector *out = &index->entries;
...@@ -1506,7 +1510,7 @@ static int write_reuc_extension(git_index *index, git_filebuf *file) ...@@ -1506,7 +1510,7 @@ static int write_reuc_extension(git_index *index, git_filebuf *file)
git_vector *out = &index->reuc; git_vector *out = &index->reuc;
git_index_reuc_entry *reuc; git_index_reuc_entry *reuc;
struct index_extension extension; struct index_extension extension;
unsigned int i; size_t i;
int error = 0; int error = 0;
git_vector_foreach(out, i, reuc) { git_vector_foreach(out, i, reuc) {
...@@ -1529,9 +1533,7 @@ done: ...@@ -1529,9 +1533,7 @@ done:
static int write_index(git_index *index, git_filebuf *file) static int write_index(git_index *index, git_filebuf *file)
{ {
git_oid hash_final; git_oid hash_final;
struct index_header header; struct index_header header;
int is_extended; int is_extended;
assert(index && file); assert(index && file);
......
...@@ -43,7 +43,7 @@ struct git_index { ...@@ -43,7 +43,7 @@ struct git_index {
extern void git_index_entry__init_from_stat(git_index_entry *entry, struct stat *st); extern void git_index_entry__init_from_stat(git_index_entry *entry, struct stat *st);
extern unsigned int git_index__prefix_position(git_index *index, const char *path); extern size_t git_index__prefix_position(git_index *index, const char *path);
extern int git_index_entry__cmp(const void *a, const void *b); extern int git_index_entry__cmp(const void *a, const void *b);
extern int git_index_entry__cmp_icase(const void *a, const void *b); extern int git_index_entry__cmp_icase(const void *a, const void *b);
......
...@@ -434,7 +434,7 @@ typedef struct workdir_iterator_frame workdir_iterator_frame; ...@@ -434,7 +434,7 @@ typedef struct workdir_iterator_frame workdir_iterator_frame;
struct workdir_iterator_frame { struct workdir_iterator_frame {
workdir_iterator_frame *next; workdir_iterator_frame *next;
git_vector entries; git_vector entries;
unsigned int index; size_t index;
char *start; char *start;
}; };
...@@ -761,7 +761,8 @@ static int spoolandsort_iterator__current( ...@@ -761,7 +761,8 @@ static int spoolandsort_iterator__current(
spoolandsort_iterator *si = (spoolandsort_iterator *)self; spoolandsort_iterator *si = (spoolandsort_iterator *)self;
if (si->position < si->entries.length) if (si->position < si->entries.length)
*entry = (const git_index_entry *)git_vector_get_const(&si->entries, si->position); *entry = (const git_index_entry *)git_vector_get(
&si->entries, si->position);
else else
*entry = NULL; *entry = NULL;
...@@ -781,7 +782,8 @@ static int spoolandsort_iterator__advance( ...@@ -781,7 +782,8 @@ static int spoolandsort_iterator__advance(
spoolandsort_iterator *si = (spoolandsort_iterator *)self; spoolandsort_iterator *si = (spoolandsort_iterator *)self;
if (si->position < si->entries.length) if (si->position < si->entries.length)
*entry = (const git_index_entry *)git_vector_get_const(&si->entries, ++si->position); *entry = (const git_index_entry *)git_vector_get(
&si->entries, ++si->position);
else else
*entry = NULL; *entry = NULL;
......
...@@ -98,11 +98,11 @@ static int homing_search_cmp(const void *key, const void *array_member) ...@@ -98,11 +98,11 @@ static int homing_search_cmp(const void *key, const void *array_member)
* ambiguous because of folder vs file sorting, we look linearly * ambiguous because of folder vs file sorting, we look linearly
* around the area for our target file. * around the area for our target file.
*/ */
static int tree_key_search(git_vector *entries, const char *filename, size_t filename_len) static int tree_key_search(
git_vector *entries, const char *filename, size_t filename_len)
{ {
struct tree_key_search ksearch; struct tree_key_search ksearch;
const git_tree_entry *entry; const git_tree_entry *entry;
int homing, i; int homing, i;
ksearch.filename = filename; ksearch.filename = filename;
...@@ -226,7 +226,8 @@ int git_tree_entry_to_object( ...@@ -226,7 +226,8 @@ int git_tree_entry_to_object(
return git_object_lookup(object_out, repo, &entry->oid, GIT_OBJ_ANY); return git_object_lookup(object_out, repo, &entry->oid, GIT_OBJ_ANY);
} }
static git_tree_entry *entry_fromname(git_tree *tree, const char *name, size_t name_len) static const git_tree_entry *entry_fromname(
git_tree *tree, const char *name, size_t name_len)
{ {
int idx = tree_key_search(&tree->entries, name, name_len); int idx = tree_key_search(&tree->entries, name, name_len);
if (idx < 0) if (idx < 0)
...@@ -235,22 +236,25 @@ static git_tree_entry *entry_fromname(git_tree *tree, const char *name, size_t n ...@@ -235,22 +236,25 @@ static git_tree_entry *entry_fromname(git_tree *tree, const char *name, size_t n
return git_vector_get(&tree->entries, idx); return git_vector_get(&tree->entries, idx);
} }
const git_tree_entry *git_tree_entry_byname(git_tree *tree, const char *filename) const git_tree_entry *git_tree_entry_byname(
git_tree *tree, const char *filename)
{ {
assert(tree && filename); assert(tree && filename);
return entry_fromname(tree, filename, strlen(filename)); return entry_fromname(tree, filename, strlen(filename));
} }
const git_tree_entry *git_tree_entry_byindex(git_tree *tree, size_t idx) const git_tree_entry *git_tree_entry_byindex(
git_tree *tree, size_t idx)
{ {
assert(tree); assert(tree);
return git_vector_get(&tree->entries, idx); return git_vector_get(&tree->entries, idx);
} }
const git_tree_entry *git_tree_entry_byoid(git_tree *tree, const git_oid *oid) const git_tree_entry *git_tree_entry_byoid(
const git_tree *tree, const git_oid *oid)
{ {
unsigned int i; size_t i;
git_tree_entry *e; const git_tree_entry *e;
assert(tree); assert(tree);
...@@ -266,7 +270,7 @@ int git_tree__prefix_position(git_tree *tree, const char *path) ...@@ -266,7 +270,7 @@ int git_tree__prefix_position(git_tree *tree, const char *path)
{ {
git_vector *entries = &tree->entries; git_vector *entries = &tree->entries;
struct tree_key_search ksearch; struct tree_key_search ksearch;
unsigned int at_pos; size_t at_pos;
ksearch.filename = path; ksearch.filename = path;
ksearch.filename_len = strlen(path); ksearch.filename_len = strlen(path);
...@@ -286,7 +290,7 @@ int git_tree__prefix_position(git_tree *tree, const char *path) ...@@ -286,7 +290,7 @@ int git_tree__prefix_position(git_tree *tree, const char *path)
break; break;
} }
return at_pos; return (int)at_pos;
} }
size_t git_tree_entrycount(const git_tree *tree) size_t git_tree_entrycount(const git_tree *tree)
...@@ -422,7 +426,7 @@ static int write_tree( ...@@ -422,7 +426,7 @@ static int write_tree(
*/ */
for (i = start; i < entries; ++i) { for (i = start; i < entries; ++i) {
const git_index_entry *entry = git_index_get_byindex(index, i); const git_index_entry *entry = git_index_get_byindex(index, i);
char *filename, *next_slash; const char *filename, *next_slash;
/* /*
* If we've left our (sub)tree, exit the loop and return. The * If we've left our (sub)tree, exit the loop and return. The
...@@ -497,7 +501,8 @@ on_error: ...@@ -497,7 +501,8 @@ on_error:
return -1; return -1;
} }
int git_tree__write_index(git_oid *oid, git_index *index, git_repository *repo) int git_tree__write_index(
git_oid *oid, git_index *index, git_repository *repo)
{ {
int ret; int ret;
...@@ -814,10 +819,10 @@ static int tree_walk( ...@@ -814,10 +819,10 @@ static int tree_walk(
bool preorder) bool preorder)
{ {
int error = 0; int error = 0;
unsigned int i; size_t i;
for (i = 0; i < tree->entries.length; ++i) { for (i = 0; i < tree->entries.length; ++i) {
git_tree_entry *entry = tree->entries.contents[i]; const git_tree_entry *entry = tree->entries.contents[i];
if (preorder) { if (preorder) {
error = callback(path->ptr, entry, payload); error = callback(path->ptr, entry, payload);
......
...@@ -51,7 +51,8 @@ int git_tree__prefix_position(git_tree *tree, const char *prefix); ...@@ -51,7 +51,8 @@ int git_tree__prefix_position(git_tree *tree, const char *prefix);
/** /**
* Write a tree to the given repository * Write a tree to the given repository
*/ */
int git_tree__write_index(git_oid *oid, git_index *index, git_repository *repo); int git_tree__write_index(
git_oid *oid, git_index *index, git_repository *repo);
/** /**
* Obsolete mode kept for compatibility reasons * Obsolete mode kept for compatibility reasons
......
...@@ -9,14 +9,14 @@ ...@@ -9,14 +9,14 @@
#include "repository.h" #include "repository.h"
#include "vector.h" #include "vector.h"
static const double resize_factor = 1.75; static const double git_vector_resize_factor = 1.75;
static const unsigned int minimum_size = 8; static const size_t git_vector_minimum_size = 8;
static int resize_vector(git_vector *v) static int resize_vector(git_vector *v)
{ {
v->_alloc_size = ((unsigned int)(v->_alloc_size * resize_factor)) + 1; v->_alloc_size = (size_t)(v->_alloc_size * git_vector_resize_factor) + 1;
if (v->_alloc_size < minimum_size) if (v->_alloc_size < git_vector_minimum_size)
v->_alloc_size = minimum_size; v->_alloc_size = git_vector_minimum_size;
v->contents = git__realloc(v->contents, v->_alloc_size * sizeof(void *)); v->contents = git__realloc(v->contents, v->_alloc_size * sizeof(void *));
GITERR_CHECK_ALLOC(v->contents); GITERR_CHECK_ALLOC(v->contents);
...@@ -24,7 +24,7 @@ static int resize_vector(git_vector *v) ...@@ -24,7 +24,7 @@ static int resize_vector(git_vector *v)
return 0; return 0;
} }
int git_vector_dup(git_vector *v, git_vector *src, git_vector_cmp cmp) int git_vector_dup(git_vector *v, const git_vector *src, git_vector_cmp cmp)
{ {
assert(v && src); assert(v && src);
...@@ -58,7 +58,7 @@ int git_vector_init(git_vector *v, size_t initial_size, git_vector_cmp cmp) ...@@ -58,7 +58,7 @@ int git_vector_init(git_vector *v, size_t initial_size, git_vector_cmp cmp)
memset(v, 0x0, sizeof(git_vector)); memset(v, 0x0, sizeof(git_vector));
if (initial_size == 0) if (initial_size == 0)
initial_size = minimum_size; initial_size = git_vector_minimum_size;
v->_alloc_size = initial_size; v->_alloc_size = initial_size;
v->_cmp = cmp; v->_cmp = cmp;
...@@ -133,7 +133,7 @@ void git_vector_sort(git_vector *v) ...@@ -133,7 +133,7 @@ void git_vector_sort(git_vector *v)
} }
int git_vector_bsearch3( int git_vector_bsearch3(
unsigned int *at_pos, size_t *at_pos,
git_vector *v, git_vector *v,
git_vector_cmp key_lookup, git_vector_cmp key_lookup,
const void *key) const void *key)
...@@ -151,15 +151,15 @@ int git_vector_bsearch3( ...@@ -151,15 +151,15 @@ int git_vector_bsearch3(
rval = git__bsearch(v->contents, v->length, key, key_lookup, &pos); rval = git__bsearch(v->contents, v->length, key, key_lookup, &pos);
if (at_pos != NULL) if (at_pos != NULL)
*at_pos = (unsigned int)pos; *at_pos = pos;
return (rval >= 0) ? (int)pos : GIT_ENOTFOUND; return (rval >= 0) ? (int)pos : GIT_ENOTFOUND;
} }
int git_vector_search2( int git_vector_search2(
git_vector *v, git_vector_cmp key_lookup, const void *key) const git_vector *v, git_vector_cmp key_lookup, const void *key)
{ {
unsigned int i; size_t i;
assert(v && key && key_lookup); assert(v && key && key_lookup);
...@@ -176,14 +176,14 @@ static int strict_comparison(const void *a, const void *b) ...@@ -176,14 +176,14 @@ static int strict_comparison(const void *a, const void *b)
return (a == b) ? 0 : -1; return (a == b) ? 0 : -1;
} }
int git_vector_search(git_vector *v, const void *entry) int git_vector_search(const git_vector *v, const void *entry)
{ {
return git_vector_search2(v, v->_cmp ? v->_cmp : strict_comparison, entry); return git_vector_search2(v, v->_cmp ? v->_cmp : strict_comparison, entry);
} }
int git_vector_remove(git_vector *v, unsigned int idx) int git_vector_remove(git_vector *v, size_t idx)
{ {
unsigned int i; size_t i;
assert(v); assert(v);
...@@ -206,7 +206,7 @@ void git_vector_pop(git_vector *v) ...@@ -206,7 +206,7 @@ void git_vector_pop(git_vector *v)
void git_vector_uniq(git_vector *v) void git_vector_uniq(git_vector *v)
{ {
git_vector_cmp cmp; git_vector_cmp cmp;
unsigned int i, j; size_t i, j;
if (v->length <= 1) if (v->length <= 1)
return; return;
...@@ -223,9 +223,10 @@ void git_vector_uniq(git_vector *v) ...@@ -223,9 +223,10 @@ void git_vector_uniq(git_vector *v)
v->length -= j - i - 1; v->length -= j - i - 1;
} }
void git_vector_remove_matching(git_vector *v, int (*match)(git_vector *v, size_t idx)) void git_vector_remove_matching(
git_vector *v, int (*match)(const git_vector *v, size_t idx))
{ {
unsigned int i, j; size_t i, j;
for (i = 0, j = 0; j < v->length; ++j) { for (i = 0, j = 0; j < v->length; ++j) {
v->contents[i] = v->contents[j]; v->contents[i] = v->contents[j];
......
...@@ -24,23 +24,23 @@ typedef struct git_vector { ...@@ -24,23 +24,23 @@ typedef struct git_vector {
int git_vector_init(git_vector *v, size_t initial_size, git_vector_cmp cmp); int git_vector_init(git_vector *v, size_t initial_size, git_vector_cmp cmp);
void git_vector_free(git_vector *v); void git_vector_free(git_vector *v);
void git_vector_clear(git_vector *v); void git_vector_clear(git_vector *v);
int git_vector_dup(git_vector *v, git_vector *src, git_vector_cmp cmp); int git_vector_dup(git_vector *v, const git_vector *src, git_vector_cmp cmp);
void git_vector_swap(git_vector *a, git_vector *b); void git_vector_swap(git_vector *a, git_vector *b);
void git_vector_sort(git_vector *v); void git_vector_sort(git_vector *v);
/** Linear search for matching entry using internal comparison function */ /** Linear search for matching entry using internal comparison function */
int git_vector_search(git_vector *v, const void *entry); int git_vector_search(const git_vector *v, const void *entry);
/** Linear search for matching entry using explicit comparison function */ /** Linear search for matching entry using explicit comparison function */
int git_vector_search2(git_vector *v, git_vector_cmp cmp, const void *key); int git_vector_search2(const git_vector *v, git_vector_cmp cmp, const void *key);
/** /**
* Binary search for matching entry using explicit comparison function that * Binary search for matching entry using explicit comparison function that
* returns position where item would go if not found. * returns position where item would go if not found.
*/ */
int git_vector_bsearch3( int git_vector_bsearch3(
unsigned int *at_pos, git_vector *v, git_vector_cmp cmp, const void *key); size_t *at_pos, git_vector *v, git_vector_cmp cmp, const void *key);
/** Binary search for matching entry using internal comparison function */ /** Binary search for matching entry using internal comparison function */
GIT_INLINE(int) git_vector_bsearch(git_vector *v, const void *key) GIT_INLINE(int) git_vector_bsearch(git_vector *v, const void *key)
...@@ -60,14 +60,9 @@ GIT_INLINE(void *) git_vector_get(const git_vector *v, size_t position) ...@@ -60,14 +60,9 @@ GIT_INLINE(void *) git_vector_get(const git_vector *v, size_t position)
return (position < v->length) ? v->contents[position] : NULL; return (position < v->length) ? v->contents[position] : NULL;
} }
GIT_INLINE(const void *) git_vector_get_const(const git_vector *v, size_t position)
{
return (position < v->length) ? v->contents[position] : NULL;
}
#define GIT_VECTOR_GET(V,I) ((I) < (V)->length ? (V)->contents[(I)] : NULL) #define GIT_VECTOR_GET(V,I) ((I) < (V)->length ? (V)->contents[(I)] : NULL)
GIT_INLINE(void *) git_vector_last(git_vector *v) GIT_INLINE(void *) git_vector_last(const git_vector *v)
{ {
return (v->length > 0) ? git_vector_get(v, v->length - 1) : NULL; return (v->length > 0) ? git_vector_get(v, v->length - 1) : NULL;
} }
...@@ -81,10 +76,11 @@ GIT_INLINE(void *) git_vector_last(git_vector *v) ...@@ -81,10 +76,11 @@ GIT_INLINE(void *) git_vector_last(git_vector *v)
int git_vector_insert(git_vector *v, void *element); int git_vector_insert(git_vector *v, void *element);
int git_vector_insert_sorted(git_vector *v, void *element, int git_vector_insert_sorted(git_vector *v, void *element,
int (*on_dup)(void **old, void *new)); int (*on_dup)(void **old, void *new));
int git_vector_remove(git_vector *v, unsigned int idx); int git_vector_remove(git_vector *v, size_t idx);
void git_vector_pop(git_vector *v); void git_vector_pop(git_vector *v);
void git_vector_uniq(git_vector *v); void git_vector_uniq(git_vector *v);
void git_vector_remove_matching(git_vector *v, int (*match)(git_vector *v, size_t idx)); void git_vector_remove_matching(
git_vector *v, int (*match)(const git_vector *v, size_t idx));
int git_vector_resize_to(git_vector *v, size_t new_length); int git_vector_resize_to(git_vector *v, size_t new_length);
int git_vector_set(void **old, git_vector *v, size_t position, void *value); int git_vector_set(void **old, git_vector *v, size_t position, void *value);
......
...@@ -190,7 +190,7 @@ void test_core_vector__5(void) ...@@ -190,7 +190,7 @@ void test_core_vector__5(void)
git_vector_free(&x); git_vector_free(&x);
} }
static int remove_ones(git_vector *v, size_t idx) static int remove_ones(const git_vector *v, size_t idx)
{ {
return (git_vector_get(v, idx) == (void *)0x001); return (git_vector_get(v, idx) == (void *)0x001);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment