lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nwelln...@apache.org
Subject [06/22] lucy-clownfish git commit: Implement VA_Insert_All
Date Wed, 29 Apr 2015 19:55:07 GMT
Implement VA_Insert_All

TODO: Write tests.


Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/35f8fbf5
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/35f8fbf5
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/35f8fbf5

Branch: refs/heads/master
Commit: 35f8fbf59d13af5fe34f3a3c82c9cbbe5db9c059
Parents: c43c1bc
Author: Nick Wellnhofer <wellnhofer@aevum.de>
Authored: Sun Apr 26 13:56:16 2015 +0200
Committer: Nick Wellnhofer <wellnhofer@aevum.de>
Committed: Sun Apr 26 19:39:58 2015 +0200

----------------------------------------------------------------------
 runtime/core/Clownfish/VArray.c   | 17 +++++++++++++++++
 runtime/core/Clownfish/VArray.cfh |  6 ++++++
 2 files changed, 23 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/35f8fbf5/runtime/core/Clownfish/VArray.c
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/VArray.c b/runtime/core/Clownfish/VArray.c
index 24f452e..408cd98 100644
--- a/runtime/core/Clownfish/VArray.c
+++ b/runtime/core/Clownfish/VArray.c
@@ -137,6 +137,23 @@ VA_Insert_IMP(VArray *self, size_t tick, Obj *elem) {
     self->size++;
 }
 
+void
+VA_Insert_All_IMP(VArray *self, size_t tick, VArray *other) {
+    SI_grow_and_oversize(self, tick, other->size);
+    if (tick < self->size) {
+        memmove(self->elems + tick + other->size, self->elems + tick,
+                (self->size - tick) * sizeof(Obj*));
+    }
+    else {
+        memset(self->elems + self->size, 0,
+               (tick - self->size) * sizeof(Obj*));
+    }
+    for (size_t i = 0; i < other->size; i++) {
+        self->elems[tick+i] = INCREF(other->elems[i]);
+    }
+    self->size = tick + other->size;
+}
+
 Obj*
 VA_Fetch_IMP(VArray *self, size_t num) {
     if (num >= self->size) {

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/35f8fbf5/runtime/core/Clownfish/VArray.cfh
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/VArray.cfh b/runtime/core/Clownfish/VArray.cfh
index 140b536..a506311 100644
--- a/runtime/core/Clownfish/VArray.cfh
+++ b/runtime/core/Clownfish/VArray.cfh
@@ -65,6 +65,12 @@ class Clownfish::VArray nickname VA inherits Clownfish::Obj {
     void
     Insert(VArray *self, size_t tick, decremented Obj *element = NULL);
 
+    /** Inserts elements from `other` array at `tick` moving the following
+     * elements.
+     */
+    void
+    Insert_All(VArray *self, size_t tick, VArray *other);
+
     /** Ensure that the VArray has room for at least `capacity`
      * elements.
      */


Mime
View raw message