aboutsummaryrefslogtreecommitdiff
path: root/src/boxvec.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/boxvec.c')
-rw-r--r--src/boxvec.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/boxvec.c b/src/boxvec.c
index f00a81c..218dddb 100644
--- a/src/boxvec.c
+++ b/src/boxvec.c
@@ -26,6 +26,7 @@
#endif
#include <stdlib.h>
+#include <stdio.h>
#include <string.h>
#include <assert.h>
@@ -75,6 +76,30 @@ int bv_add(struct boxvec *vec, struct wrap_box *bx)
}
+static int find_box(struct boxvec *vec, struct wrap_box *bx)
+{
+ int i = 0;
+ while ( (i<vec->n_boxes) && (vec->boxes[i] != bx) ) i++;
+ return i;
+}
+
+
+void bv_del(struct boxvec *vec, struct wrap_box *bx)
+{
+ int n = find_box(vec, bx);
+ if ( n == vec->n_boxes ) {
+ fprintf(stderr, "Couldn't find box to delete it!\n");
+ return;
+ }
+ assert(vec->boxes[n] == bx);
+ if ( n < vec->n_boxes-1 ) {
+ memmove(&vec->boxes[n], &vec->boxes[n+1],
+ (vec->n_boxes-n-1)*sizeof(struct wrap_box *));
+ }
+ vec->n_boxes--;
+}
+
+
struct wrap_box *bv_box(struct boxvec *vec, int i)
{
assert(vec != NULL);