vote

igwn_segments.utils.vote(seglists, n)

Given a sequence of segmentlists, returns the intervals during which at least n of them intersect. The input segmentlists must be coalesced, the output is coalesced.

Example:

>>> from igwn_segments import *
>>> w = segmentlist([segment(0, 15)])
>>> x = segmentlist([segment(5, 20)])
>>> y = segmentlist([segment(10, 25)])
>>> z = segmentlist([segment(15, 30)])
>>> vote((w, x, y, z), 3)
[segment(10, 20)]

The sequence of segmentlists is only iterated over once, and the segmentlists within it are only iterated over once; they can all be generators. If there are a total of N segments in M segment lists and the final result has L segments the algorithm is O(N M) + O(L).