[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pspp-cvs] pspp/src/libpspp array.h array.c [simpler-proc]
From: |
Ben Pfaff |
Subject: |
[Pspp-cvs] pspp/src/libpspp array.h array.c [simpler-proc] |
Date: |
Wed, 18 Apr 2007 05:41:13 +0000 |
CVSROOT: /cvsroot/pspp
Module name: pspp
Branch: simpler-proc
Changes by: Ben Pfaff <blp> 07/04/18 05:41:13
Modified files:
src/libpspp : array.h array.c
Log message:
Add insert_range, insert_element functions.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/pspp/src/libpspp/array.h?cvsroot=pspp&only_with_tag=simpler-proc&r1=1.6.2.1&r2=1.6.2.2
http://cvs.savannah.gnu.org/viewcvs/pspp/src/libpspp/array.c?cvsroot=pspp&only_with_tag=simpler-proc&r1=1.10.2.2&r2=1.10.2.3
Patches:
Index: array.h
===================================================================
RCS file: /cvsroot/pspp/pspp/src/libpspp/array.h,v
retrieving revision 1.6.2.1
retrieving revision 1.6.2.2
diff -u -b -r1.6.2.1 -r1.6.2.2
--- array.h 14 Apr 2007 05:04:23 -0000 1.6.2.1
+++ array.h 18 Apr 2007 05:41:13 -0000 1.6.2.2
@@ -108,6 +108,20 @@
void remove_element (void *array, size_t count, size_t size,
size_t idx);
+/* Makes room for N elements starting at IDX in ARRAY, which
+ initially consists of COUNT elements of SIZE bytes each, by
+ shifting elements IDX...COUNT (exclusive) to the right by N
+ positions. */
+void insert_range (void *array, size_t count, size_t size,
+ size_t idx, size_t n);
+
+/* Makes room for a new element at IDX in ARRAY, which initially
+ consists of COUNT elements of SIZE bytes each, by shifting
+ elements IDX...COUNT (exclusive) to the right by one
+ positions. */
+void insert_element (void *array, size_t count, size_t size,
+ size_t idx);
+
/* Moves an element in ARRAY, which consists of COUNT elements of
SIZE bytes each, from OLD_IDX to NEW_IDX, shifting around
other elements as needed. Runs in O(abs(OLD_IDX - NEW_IDX))
Index: array.c
===================================================================
RCS file: /cvsroot/pspp/pspp/src/libpspp/array.c,v
retrieving revision 1.10.2.2
retrieving revision 1.10.2.3
diff -u -b -r1.10.2.2 -r1.10.2.3
--- array.c 14 Apr 2007 05:04:23 -0000 1.10.2.2
+++ array.c 18 Apr 2007 05:41:13 -0000 1.10.2.3
@@ -360,6 +360,31 @@
remove_range (array, count, size, idx, 1);
}
+/* Makes room for N elements starting at IDX in ARRAY, which
+ initially consists of COUNT elements of SIZE bytes each, by
+ shifting elements IDX...COUNT (exclusive) to the right by N
+ positions. */
+void
+insert_range (void *array_, size_t count, size_t size,
+ size_t idx, size_t n)
+{
+ char *array = array_;
+
+ assert (idx <= count);
+ memmove (array + (idx + n) * size, array + idx * size, (count - idx) * size);
+}
+
+/* Makes room for a new element at IDX in ARRAY, which initially
+ consists of COUNT elements of SIZE bytes each, by shifting
+ elements IDX...COUNT (exclusive) to the right by one
+ positions. */
+void
+insert_element (void *array, size_t count, size_t size,
+ size_t idx)
+{
+ insert_range (array, count, size, idx, 1);
+}
+
/* Moves an element in ARRAY, which consists of COUNT elements of
SIZE bytes each, from OLD_IDX to NEW_IDX, shifting around
other elements as needed. Runs in O(abs(OLD_IDX - NEW_IDX))
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Pspp-cvs] pspp/src/libpspp array.h array.c [simpler-proc],
Ben Pfaff <=