[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pspp-cvs] pspp/src/libpspp ChangeLog array.c array.h
From: |
Ben Pfaff |
Subject: |
[Pspp-cvs] pspp/src/libpspp ChangeLog array.c array.h |
Date: |
Mon, 04 Jun 2007 01:19:03 +0000 |
CVSROOT: /cvsroot/pspp
Module name: pspp
Changes by: Ben Pfaff <blp> 07/06/04 01:19:03
Modified files:
src/libpspp : ChangeLog array.c array.h
Log message:
(move_range): New function.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/pspp/src/libpspp/ChangeLog?cvsroot=pspp&r1=1.66&r2=1.67
http://cvs.savannah.gnu.org/viewcvs/pspp/src/libpspp/array.c?cvsroot=pspp&r1=1.11&r2=1.12
http://cvs.savannah.gnu.org/viewcvs/pspp/src/libpspp/array.h?cvsroot=pspp&r1=1.7&r2=1.8
Patches:
Index: ChangeLog
===================================================================
RCS file: /cvsroot/pspp/pspp/src/libpspp/ChangeLog,v
retrieving revision 1.66
retrieving revision 1.67
diff -u -b -r1.66 -r1.67
--- ChangeLog 3 Jun 2007 21:58:14 -0000 1.66
+++ ChangeLog 4 Jun 2007 01:19:03 -0000 1.67
@@ -2,6 +2,7 @@
* array.c (insert_range): New function.
(insert_element): New function.
+ (move_range): New function.
2007-04-25 Ben Pfaff <address@hidden>
Index: array.c
===================================================================
RCS file: /cvsroot/pspp/pspp/src/libpspp/array.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -b -r1.11 -r1.12
--- array.c 3 Jun 2007 21:58:14 -0000 1.11
+++ array.c 4 Jun 2007 01:19:03 -0000 1.12
@@ -415,6 +415,36 @@
}
}
+/* Moves N elements in ARRAY starting at OLD_IDX, which consists
+ of COUNT elements of SIZE bytes each, so that they now start
+ at NEW_IDX, shifting around other elements as needed. */
+void
+move_range (void *array_, size_t count, size_t size,
+ size_t old_idx, size_t new_idx, size_t n)
+{
+ assert (array_ != NULL || count == 0);
+ assert (n <= count);
+ assert (old_idx + n <= count);
+ assert (new_idx + n <= count);
+
+ if (old_idx != new_idx && n > 0)
+ {
+ char *array = array_;
+ char *range = xmalloc (size * n);
+ char *new = array + new_idx * size;
+ char *old = array + old_idx * size;
+
+ memcpy (range, old, size * n);
+ if (new < old)
+ memmove (new + size * n, new, (old_idx - new_idx) * size);
+ else
+ memmove (old, old + size * n, (new_idx - old_idx) * size);
+ memcpy (new, range, size * n);
+
+ free (range);
+ }
+}
+
/* A predicate and its auxiliary data. */
struct pred_aux
{
Index: array.h
===================================================================
RCS file: /cvsroot/pspp/pspp/src/libpspp/array.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- array.h 3 Jun 2007 21:58:14 -0000 1.7
+++ array.h 4 Jun 2007 01:19:03 -0000 1.8
@@ -129,6 +129,12 @@
void move_element (void *array, size_t count, size_t size,
size_t old_idx, size_t new_idx);
+/* Moves N elements in ARRAY starting at OLD_IDX, which consists
+ of COUNT elements of SIZE bytes each, so that they now start
+ at NEW_IDX, shifting around other elements as needed. */
+void move_range (void *array, size_t count, size_t size,
+ size_t old_idx, size_t new_idx, size_t n);
+
/* Removes elements equal to ELEMENT from ARRAY, which consists
of COUNT elements of SIZE bytes each. Returns the number of
remaining elements. AUX is passed to COMPARE as auxiliary