Copyright | (c) Arbor Networks 2017 |
---|---|
License | BSD-style |
Maintainer | mayhem@arbor.net |
Stability | experimental |
Portability | non-portable (MPTCs and functional dependencies) |
Safe Haskell | Safe |
Language | Haskell2010 |
SegmentSet provides an efficient implementation of a set of segments (a.k.a intervals). Segments in the set are non-overlapping. Adjacent segments are merged (i.e. (a .. b), (b + 1 .. c) -> (a .. c)).
Segment sets are implemented using the FingerTree
type, following
section 4.8 of
- Ralf Hinze and Ross Paterson, "Finger trees: a simple general-purpose data structure", Journal of Functional Programmaxg 16:2 (2006) pp 197-217. http://staff.city.ac.uk/~ross/papers/FingerTree.html
An amortized running time is given for each operation, with n referring to the size of the set. These bounds hold even in a persistent (shared) setting.
Note: Many of these operations have the same names as similar
operations on lists in the Prelude. The ambiguity may be resolved
using either qualification or the hiding
clause.
- data Segment k = Segment {}
- point :: k -> Segment k
- newtype SegmentSet k = SegmentSet (OrderedMap (Max k) (Segment k))
- newtype OrderedMap k a = OrderedMap (FingerTree k (Item k a))
- delete :: forall k a. (Bounded k, Ord k, Enum k, Show k) => Segment k -> SegmentSet k -> SegmentSet k
- empty :: (Ord k, Bounded k) => SegmentSet k
- fromList :: (Ord v, Enum v, Bounded v, Show v) => [Segment v] -> SegmentSet v
- insert :: forall k a. (Bounded k, Ord k, Enum k, Show k) => Segment k -> SegmentSet k -> SegmentSet k
- singleton :: (Bounded k, Ord k) => Segment k -> SegmentSet k
- update :: forall k a. (Ord k, Enum k, Bounded k, Show k) => Segment k -> Bool -> SegmentSet k -> SegmentSet k
- segmentSetToList :: SegmentSet k -> [Segment k]
- data Item k a = Item !k !a
- cappedL :: (Enum k, Ord k, Bounded k, Show k) => k -> FingerTree (Max k) (Item (Max k) (Segment k)) -> (FingerTree (Max k) (Item (Max k) (Segment k)), FingerTree (Max k) (Item (Max k) (Segment k)))
- cappedM :: (Enum k, Ord k, Bounded k, Show k) => k -> FingerTree (Max k) (Item (Max k) (Segment k)) -> FingerTree (Max k) (Item (Max k) (Segment k))
Segments
A closed segment. The lower bound should be less than or equal to the higher bound.
Segment maps
newtype SegmentSet k Source #
SegmentSet (OrderedMap (Max k) (Segment k)) |
Show k => Show (SegmentSet k) Source # | |
Generic (SegmentSet k) Source # | |
NFData k => NFData (SegmentSet k) Source # | |
type Rep (SegmentSet k) Source # | |
newtype OrderedMap k a Source #
Map of closed segments, possibly with duplicates.
The Foldable
and Traversable
instances process the segments in
lexicographical order.
OrderedMap (FingerTree k (Item k a)) |
Functor (OrderedMap k) Source # | |
Foldable (OrderedMap k) Source # | |
Traversable (OrderedMap k) Source # | |
(Show a, Show k) => Show (OrderedMap k a) Source # | |
Generic (OrderedMap k a) Source # | |
(NFData a, NFData k) => NFData (OrderedMap k a) Source # | |
type Rep (OrderedMap k a) Source # | |
delete :: forall k a. (Bounded k, Ord k, Enum k, Show k) => Segment k -> SegmentSet k -> SegmentSet k Source #
O(log(n)). Remove a segment from the set. Alias of update.
insert :: forall k a. (Bounded k, Ord k, Enum k, Show k) => Segment k -> SegmentSet k -> SegmentSet k Source #
O(log(n)). Insert a segment into the set. Alias of update.
singleton :: (Bounded k, Ord k) => Segment k -> SegmentSet k Source #
O(1). Segment set with a single entry.
update :: forall k a. (Ord k, Enum k, Bounded k, Show k) => Segment k -> Bool -> SegmentSet k -> SegmentSet k Source #
segmentSetToList :: SegmentSet k -> [Segment k] Source #
Item !k !a |
Monoid k => Measured k (Item k a) Source # | |
Functor (Item k) Source # | |
Foldable (Item k) Source # | |
Traversable (Item k) Source # | |
(Eq a, Eq k) => Eq (Item k a) Source # | |
(Show a, Show k) => Show (Item k a) Source # | |
Generic (Item k a) Source # | |
(NFData a, NFData k) => NFData (Item k a) Source # | |
type Rep (Item k a) Source # | |