seq-range-array.h revision e4cebacdec9c9e5b685dde5f7cbf7a5cf7e1d248
02c335c23bf5fa225a467c19f2c063fb0dc7b8c3Timo Sirainen#ifndef SEQ_RANGE_ARRAY_H
94ba4820927b906b333e39445c1508a29387c3aaTimo Sirainen#define SEQ_RANGE_ARRAY_H
94ba4820927b906b333e39445c1508a29387c3aaTimo Sirainen
cdf294e5cceee81d58c8477c7c28d9ad6b55c36aTimo Sirainenstruct seq_range {
94ba4820927b906b333e39445c1508a29387c3aaTimo Sirainen uint32_t seq1, seq2;
94ba4820927b906b333e39445c1508a29387c3aaTimo Sirainen};
94ba4820927b906b333e39445c1508a29387c3aaTimo SirainenARRAY_DEFINE_TYPE(seq_range, struct seq_range);
cf1c3e6833fc5031d89db48dad46ed025beda4e7Timo Sirainen
cdf294e5cceee81d58c8477c7c28d9ad6b55c36aTimo Sirainenstruct seq_range_iter {
46d283ef537885386ab3fc72d1831054ea5f986bTimo Sirainen const ARRAY_TYPE(seq_range) *array;
c4ac0f222613903b7f8c9e0825198396e6bf793eTimo Sirainen unsigned int prev_n, prev_idx;
46d283ef537885386ab3fc72d1831054ea5f986bTimo Sirainen};
cdf294e5cceee81d58c8477c7c28d9ad6b55c36aTimo Sirainen
1631885636d15abaf0375304a17928c8c23782cdTimo Sirainen/* Add sequrence to range. If the array isn't created yet, create it with
94ba4820927b906b333e39445c1508a29387c3aaTimo Sirainen initial size of init_count. */
f330fcc3307d48954b6f8909349546773368a041Timo Sirainenvoid seq_range_array_add(ARRAY_TYPE(seq_range) *array, unsigned int init_count,
d389c93ada174a8fc6edf995b4f829d38e8fe567Timo Sirainen uint32_t seq);
f24b245f49b030d7dba3bcb2463cbc05b98c9d1dTimo Sirainenvoid seq_range_array_add_range(ARRAY_TYPE(seq_range) *array,
c154a05c76d4d83de1cdf9746ce4e2da0869705dTimo Sirainen uint32_t seq1, uint32_t seq2);
94ba4820927b906b333e39445c1508a29387c3aaTimo Sirainenvoid seq_range_array_merge(ARRAY_TYPE(seq_range) *dest,
5fbccc935e3f7b916aa7c6e302a212821072e83aTimo Sirainen const ARRAY_TYPE(seq_range) *src);
f23baa3b53b1dd4eb19729e99a43937fa3c7f309Timo Sirainen/* Remove given sequrence from range. Returns TRUE if it was found. */
8732bdd21579472feb40da8ffc99b8fd3b341417Timo Sirainenbool seq_range_array_remove(ARRAY_TYPE(seq_range) *array, uint32_t seq);
7f098e28ddad259d9fbe76e18347c722bb005189Timo Sirainen/* Remove a sequence range. Returns number of sequences actually removed. */
7f098e28ddad259d9fbe76e18347c722bb005189Timo Sirainenunsigned int seq_range_array_remove_range(ARRAY_TYPE(seq_range) *array,
cf63dc8723b971cc80638fccbf494d961cbafc7fTimo Sirainen uint32_t seq1, uint32_t seq2);
cf63dc8723b971cc80638fccbf494d961cbafc7fTimo Sirainenunsigned int seq_range_array_remove_seq_range(ARRAY_TYPE(seq_range) *dest,
cf63dc8723b971cc80638fccbf494d961cbafc7fTimo Sirainen const ARRAY_TYPE(seq_range) *src);
cdf294e5cceee81d58c8477c7c28d9ad6b55c36aTimo Sirainen/* Remove sequences from dest that don't exist in src.
cdf294e5cceee81d58c8477c7c28d9ad6b55c36aTimo Sirainen Returns the number of sequences actually removed. */
71fbc9af425dc9afc2fb58f911bfe4c5b4edba9bTimo Sirainenunsigned int
d38ca817bdcec666a3b91efb917064ab844c36a2Timo Sirainenseq_range_array_intersect(ARRAY_TYPE(seq_range) *dest,
cdf294e5cceee81d58c8477c7c28d9ad6b55c36aTimo Sirainen const ARRAY_TYPE(seq_range) *src);
8732bdd21579472feb40da8ffc99b8fd3b341417Timo Sirainen/* Returns TRUE if sequence exists in the range. */
d38ca817bdcec666a3b91efb917064ab844c36a2Timo Sirainenbool seq_range_exists(const ARRAY_TYPE(seq_range) *array, uint32_t seq);
2d7da70c0e6768afeb1200c95f3e1293f2e502c6Timo Sirainen/* Returns TRUE if arrays have common sequences. */
2d7da70c0e6768afeb1200c95f3e1293f2e502c6Timo Sirainenbool seq_range_array_have_common(const ARRAY_TYPE(seq_range) *array1,
2d7da70c0e6768afeb1200c95f3e1293f2e502c6Timo Sirainen const ARRAY_TYPE(seq_range) *array2);
cdf294e5cceee81d58c8477c7c28d9ad6b55c36aTimo Sirainen/* Return number of sequences in the range. */
cdf294e5cceee81d58c8477c7c28d9ad6b55c36aTimo Sirainenunsigned int seq_range_count(const ARRAY_TYPE(seq_range) *array);
d38ca817bdcec666a3b91efb917064ab844c36a2Timo Sirainen
d38ca817bdcec666a3b91efb917064ab844c36a2Timo Sirainen/* Invert the sequence range. For example 5:6 -> min_seq:4,7:max_seq. */
d38ca817bdcec666a3b91efb917064ab844c36a2Timo Sirainenvoid seq_range_array_invert(ARRAY_TYPE(seq_range) *array,
d38ca817bdcec666a3b91efb917064ab844c36a2Timo Sirainen uint32_t min_seq, uint32_t max_seq);
d38ca817bdcec666a3b91efb917064ab844c36a2Timo Sirainen
d38ca817bdcec666a3b91efb917064ab844c36a2Timo Sirainenvoid seq_range_array_iter_init(struct seq_range_iter *iter_r,
1631885636d15abaf0375304a17928c8c23782cdTimo Sirainen const ARRAY_TYPE(seq_range) *array);
1631885636d15abaf0375304a17928c8c23782cdTimo Sirainen/* Get the nth sequence (0 = first). Returns FALSE if idx is too large. */
c154a05c76d4d83de1cdf9746ce4e2da0869705dTimo Sirainenbool seq_range_array_iter_nth(struct seq_range_iter *iter, unsigned int n,
1631885636d15abaf0375304a17928c8c23782cdTimo Sirainen uint32_t *seq_r);
1631885636d15abaf0375304a17928c8c23782cdTimo Sirainen
1631885636d15abaf0375304a17928c8c23782cdTimo Sirainen#endif
cf63dc8723b971cc80638fccbf494d961cbafc7fTimo Sirainen