dovecot-2.2: Added seq_range_array_remove_nth()
dovecot at dovecot.org
dovecot at dovecot.org
Mon May 5 11:02:53 UTC 2014
details: http://hg.dovecot.org/dovecot-2.2/rev/0d237a4dacd2
changeset: 17312:0d237a4dacd2
user: Timo Sirainen <tss at iki.fi>
date: Mon May 05 14:02:16 2014 +0300
description:
Added seq_range_array_remove_nth()
diffstat:
src/lib/seq-range-array.c | 22 ++++++++++++++++++++++
src/lib/seq-range-array.h | 3 +++
src/lib/test-seq-range-array.c | 27 +++++++++++++++++++++++++++
3 files changed, 52 insertions(+), 0 deletions(-)
diffs (89 lines):
diff -r 36d07c48049f -r 0d237a4dacd2 src/lib/seq-range-array.c
--- a/src/lib/seq-range-array.c Fri May 02 19:31:49 2014 +0300
+++ b/src/lib/seq-range-array.c Mon May 05 14:02:16 2014 +0300
@@ -288,6 +288,28 @@
return ret;
}
+void seq_range_array_remove_nth(ARRAY_TYPE(seq_range) *array,
+ uint32_t n, uint32_t count)
+{
+ struct seq_range_iter iter;
+ uint32_t seq1, seq2;
+
+ if (count == 0)
+ return;
+
+ seq_range_array_iter_init(&iter, array);
+ if (!seq_range_array_iter_nth(&iter, n, &seq1)) {
+ /* n points beyond array */
+ return;
+ }
+ if (count-1 >= (uint32_t)-1 - n ||
+ !seq_range_array_iter_nth(&iter, n + (count-1), &seq2)) {
+ /* count points beyond array */
+ seq2 = (uint32_t)-1;
+ }
+ seq_range_array_remove_range(array, seq1, seq2);
+}
+
unsigned int seq_range_array_intersect(ARRAY_TYPE(seq_range) *dest,
const ARRAY_TYPE(seq_range) *src)
{
diff -r 36d07c48049f -r 0d237a4dacd2 src/lib/seq-range-array.h
--- a/src/lib/seq-range-array.h Fri May 02 19:31:49 2014 +0300
+++ b/src/lib/seq-range-array.h Mon May 05 14:02:16 2014 +0300
@@ -33,6 +33,9 @@
unsigned int ATTR_NOWARN_UNUSED_RESULT
seq_range_array_remove_seq_range(ARRAY_TYPE(seq_range) *dest,
const ARRAY_TYPE(seq_range) *src);
+/* Remove count number of sequences from the nth sequence (0 = first). */
+void seq_range_array_remove_nth(ARRAY_TYPE(seq_range) *array,
+ uint32_t n, uint32_t count);
/* Remove sequences from dest that don't exist in src. */
unsigned int ATTR_NOWARN_UNUSED_RESULT
seq_range_array_intersect(ARRAY_TYPE(seq_range) *dest,
diff -r 36d07c48049f -r 0d237a4dacd2 src/lib/test-seq-range-array.c
--- a/src/lib/test-seq-range-array.c Fri May 02 19:31:49 2014 +0300
+++ b/src/lib/test-seq-range-array.c Mon May 05 14:02:16 2014 +0300
@@ -54,6 +54,32 @@
test_end();
}
+static void test_seq_range_array_remove_nth(void)
+{
+ ARRAY_TYPE(seq_range) range;
+ const struct seq_range *r;
+
+ test_begin("seq_range_array_remove_nth()");
+ t_array_init(&range, 8);
+ seq_range_array_add_range(&range, 1, 5);
+ seq_range_array_add(&range, 7);
+ seq_range_array_add_range(&range, 10,20);
+ test_assert(array_count(&range) == 3);
+
+ seq_range_array_remove_nth(&range, 0, 2);
+ r = array_idx(&range, 0); test_assert(r->seq1 == 3 && r->seq2 == 5);
+
+ seq_range_array_remove_nth(&range, 1, 4);
+ r = array_idx(&range, 0); test_assert(r->seq1 == 3 && r->seq2 == 3);
+ r = array_idx(&range, 1); test_assert(r->seq1 == 11 && r->seq2 == 20);
+
+ seq_range_array_remove_nth(&range, 5, (uint32_t)-1);
+ r = array_idx(&range, 1); test_assert(r->seq1 == 11 && r->seq2 == 14);
+
+ test_assert(array_count(&range) == 2);
+ test_end();
+}
+
static void test_seq_range_array_random(void)
{
#define SEQ_RANGE_TEST_BUFSIZE 20
@@ -206,6 +232,7 @@
{
test_seq_range_array_add_boundaries();
test_seq_range_array_add_merge();
+ test_seq_range_array_remove_nth();
test_seq_range_array_invert();
test_seq_range_array_have_common();
test_seq_range_array_random();
More information about the dovecot-cvs
mailing list