[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[patch 2/7] Add insert_range, insert_element functions.
From: |
blp |
Subject: |
[patch 2/7] Add insert_range, insert_element functions. |
Date: |
Sat, 02 Jun 2007 15:36:49 -0700 |
User-agent: |
quilt/0.45-1 |
diff --git a/src/libpspp/array.c b/src/libpspp/array.c
index 2e011b6..56afb1a 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 38d38bb..a867ade 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))
--
1.4.4.3
--
- [patch 0/7] some bits of simpler-proc ready for review, blp, 2007/06/03
- [patch 2/7] Add insert_range, insert_element functions.,
blp <=
- [patch 7/7] Implement support for "INTEGER LIST"-type subcommands in q2c. The documentation claimed these were supported, but actually they werent., blp, 2007/06/03
- [patch 5/7] Remove author. Fix compile-command., blp, 2007/06/03
- [patch 6/7] Use var_is_alpha., blp, 2007/06/03
- [patch 4/7] Remove next, prev, up node names from @node lines, to make structural changes to the manual easier. (These node names are not needed by makeinfo.), blp, 2007/06/03
- [patch 3/7] Ignore _ndebug, _profile directories that I use for -DNDEBUG and profiling builds., blp, 2007/06/03
- [patch 1/7] Insert some missing "#include <config.h>" lines., blp, 2007/06/03
- Re: [patch 0/7] some bits of simpler-proc ready for review, John Darrington, 2007/06/03