RPA Toolkit
renamed hasharray to map. added support for delete an element from rarray_t.
authorMartin Stoilov <martin@rpasearch.com>
Mon, 6 Jun 2011 06:27:12 +0000 (23:27 -0700)
committerMartin Stoilov <martin@rpasearch.com>
Mon, 6 Jun 2011 06:27:12 +0000 (23:27 -0700)
rlib/build/linux/rlib.mk
rlib/rarray.c
rlib/rarray.h
rlib/rhasharray.c [deleted file]
rlib/rmap.c [new file with mode: 0644]
rlib/rmap.h [moved from rlib/rhasharray.h with 51% similarity]
tests/testmisc/rarray-test.c

index 1321822..ce0defc 100644 (file)
@@ -13,10 +13,10 @@ RLIB_OBJECTS +=     $(OUTDIR)/ratomic.o
 RLIB_OBJECTS +=        $(OUTDIR)/rspinlock.o
 RLIB_OBJECTS +=        $(OUTDIR)/rjsobject.o
 RLIB_OBJECTS +=        $(OUTDIR)/rharray.o
-RLIB_OBJECTS +=        $(OUTDIR)/rhasharray.o
 RLIB_OBJECTS +=        $(OUTDIR)/rcarray.o
 RLIB_OBJECTS +=        $(OUTDIR)/rarray.o
 RLIB_OBJECTS +=        $(OUTDIR)/rhash.o
+RLIB_OBJECTS +=        $(OUTDIR)/rmap.o
 RLIB_OBJECTS +=        $(OUTDIR)/rstring.o
 RLIB_OBJECTS +=        $(OUTDIR)/rlist.o
 RLIB_OBJECTS +=        $(OUTDIR)/rutf.o
index 0165b93..ddd28d3 100644 (file)
@@ -185,3 +185,19 @@ rint r_array_move(rarray_t *array, rlong dest, rlong src, rlong size)
        }
        return 0;
 }
+
+
+void r_array_delete(rarray_t *array, rsize_t index)
+{
+       rsize_t movesize;
+       rsize_t moveindex;
+
+       if (r_array_length(array) <= index)
+               return;
+       moveindex = index + 1;
+       movesize = r_array_length(array) - moveindex;
+       if (movesize > 0) {
+               r_array_move(array, index, moveindex, movesize);
+       }
+       r_array_removelast(array);
+}
index a86f815..0e22b57 100644 (file)
@@ -49,6 +49,7 @@ rsize_t r_array_replace(rarray_t *array, rsize_t index, rconstpointer data);
 rsize_t r_array_setlength(rarray_t *array, rsize_t len);
 rsize_t r_array_expand(rarray_t *array, rsize_t len);
 void *r_array_slot_expand(rarray_t *array, rsize_t index);
+void r_array_delete(rarray_t *array, rsize_t index);
 
 /*
  * Virtual methods implementation
diff --git a/rlib/rhasharray.c b/rlib/rhasharray.c
deleted file mode 100644 (file)
index 9173bb9..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-#include "rhasharray.h"
-#include "rstring.h"
-#include "rmem.h"
-
-
-rhasharray_t *r_hasharray_create(ruint elt_size)
-{
-       return NULL;
-}
-
-
-void r_hasharray_destroy(rhasharray_t *array)
-{
-
-}
-
diff --git a/rlib/rmap.c b/rlib/rmap.c
new file mode 100644 (file)
index 0000000..67895a2
--- /dev/null
@@ -0,0 +1,16 @@
+#include "rmap.h"
+#include "rstring.h"
+#include "rmem.h"
+
+
+rmap_t *r_map_create(ruint elt_size)
+{
+       return NULL;
+}
+
+
+void r_map_destroy(rmap_t *array)
+{
+
+}
+
similarity index 51%
rename from rlib/rhasharray.h
rename to rlib/rmap.h
index cf5fc24..80f2ab5 100644 (file)
@@ -1,5 +1,5 @@
-#ifndef _RHASHARRAY_H_
-#define _RHASHARRAY_H_
+#ifndef _RMAP_H_
+#define _RMAP_H_
 
 #include "rcarray.h"
 #include "rhash.h"
@@ -11,20 +11,20 @@ extern "C" {
 #endif
 
 
-typedef struct rhasharray_s {
+typedef struct rmap_s {
        robject_t obj;
        rcarray_t *members;
        rarray_t *names;
        rhash_t *hash;
-} rhasharray_t;
+} rmap_t;
 
 
-rhasharray_t *r_hasharray_create(ruint elt_size);
-void r_hasharray_destroy(rhasharray_t *array);
+rmap_t *r_map_create(ruint elt_size);
+void r_map_destroy(rmap_t *array);
 
 
 #ifdef __cplusplus
 }
 #endif
 
-#endif /* _RHASHARRAY_H_ */
+#endif /* _RMAP_H_ */
index 7a62d22..394c0ce 100644 (file)
@@ -12,7 +12,7 @@ static void r_array_addint(rarray_t *array, int elt)
 
 int main(int argc, char *argv[])
 {
-       int i;
+       int i, j;
        rarray_t *a;
 
        a = r_array_create(sizeof(int));
@@ -43,6 +43,38 @@ int main(int argc, char *argv[])
        for (i = 0; i < r_array_length(a); i++) {
                fprintf(stdout, "index %d: %d\n", i, *((int*)r_array_slot(a, i)));
        }
+       fprintf(stdout, "\n");
+
+       r_array_delete(a, 0);
+       fprintf(stdout, "r_array_delete %d\n", 0);
+       for (i = 0; i < r_array_length(a); i++) {
+               fprintf(stdout, "index %d: %d\n", i, *((int*)r_array_slot(a, i)));
+       }
+       fprintf(stdout, "\n");
+
+       r_array_delete(a, 20);
+       fprintf(stdout, "r_array_delete %d\n", 20);
+       for (i = 0; i < r_array_length(a); i++) {
+               fprintf(stdout, "index %d: %d\n", i, *((int*)r_array_slot(a, i)));
+       }
+       fprintf(stdout, "\n");
+
+       r_array_delete(a, 19);
+       fprintf(stdout, "r_array_delete %d\n", 19);
+       for (i = 0; i < r_array_length(a); i++) {
+               fprintf(stdout, "index %d: %d\n", i, *((int*)r_array_slot(a, i)));
+       }
+       fprintf(stdout, "\n");
+
+       for (j = 0; j < 21; j++) {
+               r_array_delete(a, 0);
+               fprintf(stdout, "r_array_delete %d\n", 0);
+               for (i = 0; i < r_array_length(a); i++) {
+                       fprintf(stdout, "index %d: %d\n", i, *((int*)r_array_slot(a, i)));
+               }
+               fprintf(stdout, "\n");
+       }
+
 
        r_object_destroy((robject_t*)a);