[dovecot-cvs] dovecot/src/lib seq-range-array.c, 1.9, 1.10 seq-range-array.h, 1.4, 1.5
tss at dovecot.org
tss at dovecot.org
Wed Dec 20 14:44:42 UTC 2006
Update of /var/lib/cvs/dovecot/src/lib
In directory talvi:/tmp/cvs-serv21062
Modified Files:
seq-range-array.c seq-range-array.h
Log Message:
Added seq_range_array_remove_range()
Index: seq-range-array.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/seq-range-array.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- seq-range-array.c 15 Oct 2006 17:44:32 -0000 1.9
+++ seq-range-array.c 20 Dec 2006 14:44:40 -0000 1.10
@@ -171,6 +171,41 @@
}
}
+void 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;
+
+ /* 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 (seq1 > seq2)
+ return;
+ seq_range_array_remove(array, seq2--);
+ if (seq1 == seq2)
+ return;
+
+ /* find the beginning */
+ data = array_get(array, &count);
+ (void)seq_range_lookup(array, seq1, &idx);
+ if (idx < count && data[idx].seq2 < seq1)
+ idx++;
+
+ if (idx == count)
+ return;
+
+ i_assert(data[idx].seq1 >= seq1);
+ for (idx2 = idx; idx2 < count; idx2++) {
+ if (data[idx2].seq1 > seq2)
+ break;
+ }
+ array_delete(array, idx, idx2-idx);
+}
+
bool seq_range_exists(const ARRAY_TYPE(seq_range) *array, uint32_t seq)
{
unsigned int idx;
Index: seq-range-array.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/seq-range-array.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- seq-range-array.h 15 Oct 2006 17:44:33 -0000 1.4
+++ seq-range-array.h 20 Dec 2006 14:44:40 -0000 1.5
@@ -10,6 +10,8 @@
void seq_range_array_add(ARRAY_TYPE(seq_range) *array, unsigned int init_count,
uint32_t seq);
void 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);
bool seq_range_exists(const ARRAY_TYPE(seq_range) *array, uint32_t seq);
#endif
More information about the dovecot-cvs
mailing list