From: Ben Pfaff Date: Mon, 4 Jun 2007 01:22:47 +0000 (+0000) Subject: * range-set.c (range_set_clone): New function. X-Git-Tag: v0.6.0~456 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=24b37bba66595150594008c350944a14ab654a52;p=pspp-builds.git * range-set.c (range_set_clone): New function. * tests/range-set-test.c: Also test the range_set_clone function. --- diff --git a/src/libpspp/ChangeLog b/src/libpspp/ChangeLog index acdad231..c125ac41 100644 --- a/src/libpspp/ChangeLog +++ b/src/libpspp/ChangeLog @@ -1,5 +1,7 @@ 2007-06-03 Ben Pfaff + * range-set.c (range_set_clone): New function. + * array.c (insert_range): New function. (insert_element): New function. (move_range): New function. diff --git a/src/libpspp/range-set.c b/src/libpspp/range-set.c index 4e7d6d2f..dc123d9b 100644 --- a/src/libpspp/range-set.c +++ b/src/libpspp/range-set.c @@ -100,6 +100,20 @@ range_set_create_pool (struct pool *pool) return rs; } +/* Creates and returns a clone of OLD range set in the given POOL + (which may be null). */ +struct range_set * +range_set_clone (const struct range_set *old, struct pool *pool) +{ + struct range_set *new; + struct range_set_node *node; + + new = range_set_create_pool (pool); + for (node = first_node (old); node != NULL; node = next_node (old, node)) + insert_node (new, node->start, node->end); + return new; +} + /* Destroys range set RS. */ void range_set_destroy (struct range_set *rs) diff --git a/src/libpspp/range-set.h b/src/libpspp/range-set.h index b6b60a44..1b9fea50 100644 --- a/src/libpspp/range-set.h +++ b/src/libpspp/range-set.h @@ -32,6 +32,7 @@ struct pool; struct range_set *range_set_create (void); struct range_set *range_set_create_pool (struct pool *); +struct range_set *range_set_clone (const struct range_set *, struct pool *); void range_set_destroy (struct range_set *); void range_set_insert (struct range_set *, diff --git a/tests/ChangeLog b/tests/ChangeLog index 2801b7b2..5c89d0da 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,7 @@ +2007-06-03 Ben Pfaff + + * tests/range-set-test.c: Also test the range_set_clone function. + 2007-05-06 Ben Pfaff Abstract the documents within a dictionary a little better. diff --git a/tests/libpspp/range-set-test.c b/tests/libpspp/range-set-test.c index b1c7451e..1aa87760 100644 --- a/tests/libpspp/range-set-test.c +++ b/tests/libpspp/range-set-test.c @@ -202,14 +202,17 @@ test_insert (void) for (i = 0; i < positions + 1; i++) for (j = i; j <= positions + 1; j++) { - struct range_set *rs; + struct range_set *rs, *rs2; unsigned int final_pat; rs = make_pattern (init_pat); range_set_insert (rs, i, j - i); final_pat = init_pat | bit_range (i, j - i); check_pattern (rs, final_pat); + rs2 = range_set_clone (rs, NULL); + check_pattern (rs2, final_pat); range_set_destroy (rs); + range_set_destroy (rs2); } }