Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKirill A. Shutemov <kirill@shutemov.name>2011-07-02 01:41:49 +0400
committerKirill A. Shutemov <kirill@shutemov.name>2011-07-05 18:52:39 +0400
commit476c42acc554e7b3f79c945c2a461d4e25dde41c (patch)
tree82808af7f61a45323ae8d71ed2504216c04e8a6b /src/vector.c
parent0b0a6b115d617fe79a0be0ddecd89738aefa574c (diff)
vector: implement git_vector_uniq()
The routine remove duplictes from the vector. Only the last added element of elements with equal keys remains in the vector. Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
Diffstat (limited to 'src/vector.c')
-rw-r--r--src/vector.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/vector.c b/src/vector.c
index 8d09350fc..2fc051f0c 100644
--- a/src/vector.c
+++ b/src/vector.c
@@ -162,6 +162,26 @@ int git_vector_remove(git_vector *v, unsigned int idx)
return GIT_SUCCESS;
}
+void git_vector_uniq(git_vector *v)
+{
+ git_vector_cmp cmp;
+ unsigned int i, j;
+
+ if (v->length <= 1)
+ return;
+
+ git_vector_sort(v);
+ cmp = v->_cmp ? v->_cmp : strict_comparison;
+
+ for (i = 0, j = 1 ; j < v->length; ++j)
+ if (!cmp(v->contents + i, v->contents + j))
+ v->contents[i] = v->contents[j];
+ else
+ v->contents[++i] = v->contents[j];
+
+ v->length -= j - i - 1;
+}
+
void git_vector_clear(git_vector *v)
{
assert(v);