summaryrefslogtreecommitdiff
path: root/vect.c
diff options
context:
space:
mode:
authorChanho Park <chanho61.park@samsung.com>2014-08-22 20:34:56 +0900
committerChanho Park <chanho61.park@samsung.com>2014-08-22 20:34:56 +0900
commit517f5529d7008eba87b8b2fee5ec9ec0a5075f6e (patch)
treec71720a9b41309713c089478f921165bd2d63b25 /vect.c
parent689b9dbb8d7f88ab91e7741932ed000b6e49be9a (diff)
downloadltrace-517f5529d7008eba87b8b2fee5ec9ec0a5075f6e.tar.gz
ltrace-517f5529d7008eba87b8b2fee5ec9ec0a5075f6e.tar.bz2
ltrace-517f5529d7008eba87b8b2fee5ec9ec0a5075f6e.zip
Imported Upstream version 0.7.91upstream/0.7.91upstream
Diffstat (limited to 'vect.c')
-rw-r--r--vect.c56
1 files changed, 47 insertions, 9 deletions
diff --git a/vect.c b/vect.c
index 3a29118..5ccd53f 100644
--- a/vect.c
+++ b/vect.c
@@ -1,6 +1,6 @@
/*
* This file is part of ltrace.
- * Copyright (C) 2011,2012 Petr Machata, Red Hat Inc.
+ * Copyright (C) 2011,2012,2013 Petr Machata, Red Hat Inc.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
@@ -129,9 +129,31 @@ vect_pushback(struct vect *vec, void *eltp)
}
void
-vect_popback(struct vect *vec)
+vect_erase(struct vect *vec, size_t start, size_t end,
+ void (*dtor)(void *emt, void *data), void *data)
{
- vec->size--;
+ assert(start < vect_size(vec) || start == 0);
+ assert(end <= vect_size(vec));
+
+ /* First, destroy the elements that are to be erased. */
+ if (dtor != NULL) {
+ size_t i;
+ for (i = start; i < end; ++i)
+ dtor(slot(vec, i), data);
+ }
+
+ /* Now move the tail forward and adjust size. */
+ memmove(slot(vec, start), slot(vec, end),
+ slot(vec, vec->size) - slot(vec, end));
+ vec->size -= end - start;
+}
+
+void
+vect_popback(struct vect *vec,
+ void (*dtor)(void *emt, void *data), void *data)
+{
+ assert(vect_size(vec) > 0);
+ vect_erase(vec, vect_size(vec)-1, vect_size(vec), dtor, data);
}
void
@@ -140,12 +162,8 @@ vect_destroy(struct vect *vec, void (*dtor)(void *emt, void *data), void *data)
if (vec == NULL)
return;
- if (dtor != NULL) {
- size_t i;
- size_t sz = vect_size(vec);
- for (i = 0; i < sz; ++i)
- dtor(slot(vec, i), data);
- }
+ vect_erase(vec, 0, vect_size(vec), dtor, data);
+ assert(vect_size(vec) == 0);
free(vec->data);
}
@@ -170,3 +188,23 @@ vect_each(struct vect *vec, void *start_after,
return NULL;
}
+
+void
+vect_qsort(struct vect *vec, int (*compar)(const void *, const void *))
+{
+ qsort(vec->data, vec->size, vec->elt_size, compar);
+}
+
+const void *
+vect_each_cst(const struct vect *vec, const void *start_after,
+ enum callback_status (*cb)(const void *, void *), void *data)
+{
+ return vect_each((struct vect *)vec, (void *)start_after,
+ (void *)cb, data);
+}
+
+void
+vect_dtor_string(char **key, void *data)
+{
+ free(*key);
+}