From: Ben Pfaff <blp@gnu.org>
Date: Sun, 3 Jun 2007 21:58:14 +0000 (+0000)
Subject: (insert_range): New function.
X-Git-Tag: sav-api~1470
X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=19f2bec879b9b03eebc8b32b67332c9ea586188d;p=pspp

(insert_range): New function.
(insert_element): New function.
---

diff --git a/src/libpspp/ChangeLog b/src/libpspp/ChangeLog
index 9050f18f08..fa02a8b940 100644
--- a/src/libpspp/ChangeLog
+++ b/src/libpspp/ChangeLog
@@ -1,3 +1,8 @@
+2007-06-03  Ben Pfaff  <blp@gnu.org>
+
+	* array.c (insert_range): New function.
+	(insert_element): New function.
+
 2007-04-25  Ben Pfaff  <blp@gnu.org>
 
 	* model-checker.c: Don't use type sighandler_t, which is a GNU
diff --git a/src/libpspp/array.c b/src/libpspp/array.c
index db4dbcba01..8af5d8fece 100644
--- a/src/libpspp/array.c
+++ b/src/libpspp/array.c
@@ -360,6 +360,31 @@ remove_element (void *array, size_t count, size_t size,
   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))
diff --git a/src/libpspp/array.h b/src/libpspp/array.h
index c80fb24c5b..3cfb245a26 100644
--- a/src/libpspp/array.h
+++ b/src/libpspp/array.h
@@ -108,6 +108,20 @@ void remove_range (void *array, size_t count, size_t size,
 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))