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 # | |
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 # | |
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 |