dovecot: seq_range_array_remove_range() returns now how many seq...

dovecot at dovecot.org dovecot at dovecot.org
Tue Jul 17 21:19:21 EEST 2007


details:   http://hg.dovecot.org/dovecot/rev/fef4aad133dd
changeset: 6040:fef4aad133dd
user:      Timo Sirainen <tss at iki.fi>
date:      Tue Jul 17 21:16:23 2007 +0300
description:
seq_range_array_remove_range() returns now how many sequences were removed.

diffstat:

2 files changed, 20 insertions(+), 10 deletions(-)
src/lib/seq-range-array.c |   21 +++++++++++++--------
src/lib/seq-range-array.h |    9 +++++++--

diffs (77 lines):

diff -r 3887591e7a54 -r fef4aad133dd src/lib/seq-range-array.c
--- a/src/lib/seq-range-array.c	Tue Jul 17 20:39:27 2007 +0300
+++ b/src/lib/seq-range-array.c	Tue Jul 17 21:16:23 2007 +0300
@@ -172,23 +172,26 @@ bool seq_range_array_remove(ARRAY_TYPE(s
 	return FALSE;
 }
 
-void seq_range_array_remove_range(ARRAY_TYPE(seq_range) *array,
-				  uint32_t seq1, uint32_t seq2)
+unsigned int seq_range_array_remove_range(ARRAY_TYPE(seq_range) *array,
+					  uint32_t seq1, uint32_t seq2)
 {
 	const struct seq_range *data;
-	unsigned int idx, idx2, count;
+	unsigned int idx, idx2, count, remove_count = 0;
 
 	/* remove first and last. this makes sure that everything between
 	   can simply be deleted with array_delete().
 
 	   FIXME: it would be faster if we did only one binary lookup here
 	   and handled the splitting ourself.. */
-	seq_range_array_remove(array, seq1++);
+	if (seq_range_array_remove(array, seq1++))
+		remove_count++;
 	if (seq1 > seq2)
-		return;
-	seq_range_array_remove(array, seq2--);
+		return remove_count;
+
+	if (seq_range_array_remove(array, seq2--))
+		remove_count++;
 	if (seq1 == seq2)
-		return;
+		return remove_count;
 
 	/* find the beginning */
 	data = array_get(array, &count);
@@ -197,14 +200,16 @@ void seq_range_array_remove_range(ARRAY_
 		idx++;
 
 	if (idx == count)
-		return;
+		return remove_count;
 
 	i_assert(data[idx].seq1 >= seq1);
 	for (idx2 = idx; idx2 < count; idx2++) {
 		if (data[idx2].seq1 > seq2)
 			break;
+		remove_count += data[idx2].seq2 - data[idx2].seq1 + 1;
 	}
 	array_delete(array, idx, idx2-idx);
+	return remove_count;
 }
 
 bool seq_range_exists(const ARRAY_TYPE(seq_range) *array, uint32_t seq)
diff -r 3887591e7a54 -r fef4aad133dd src/lib/seq-range-array.h
--- a/src/lib/seq-range-array.h	Tue Jul 17 20:39:27 2007 +0300
+++ b/src/lib/seq-range-array.h	Tue Jul 17 21:16:23 2007 +0300
@@ -7,11 +7,16 @@ struct seq_range {
 
 ARRAY_DEFINE_TYPE(seq_range, struct seq_range);
 
+/* Add sequrence to range. If the array isn't created yet, create it with
+   initial size of init_count. */
 void seq_range_array_add(ARRAY_TYPE(seq_range) *array, unsigned int init_count,
 			 uint32_t seq);
+/* Remove given sequrence from range. Returns TRUE if it was found. */
 bool seq_range_array_remove(ARRAY_TYPE(seq_range) *array, uint32_t seq);
-void seq_range_array_remove_range(ARRAY_TYPE(seq_range) *array,
-				  uint32_t seq1, uint32_t seq2);
+/* Remove a sequence range. Returns number of sequences actually removed. */
+unsigned int seq_range_array_remove_range(ARRAY_TYPE(seq_range) *array,
+					  uint32_t seq1, uint32_t seq2);
+/* Returns TRUE if sequence exists in the range. */
 bool seq_range_exists(const ARRAY_TYPE(seq_range) *array, uint32_t seq);
 
 #endif


More information about the dovecot-cvs mailing list