Portability | non-portable (tested with GHC only) |
---|---|
Stability | experimental |
Maintainer | oleg.grenrus@iki.fi |
Safe Haskell | Safe-Inferred |
A trivial implementation of range sets.
This module is intended to be imported qualified, to avoid name clashes with Prelude functions, e.g.
import Data.RangeSet.List (RSet) import qualified Data.RangeSet.List as RSet
The implementation of RSet
is based on list.
Compared to Set
, this module imposes also Enum
restriction for many functions.
We must be able to identify consecutive elements to be able to glue and split ranges properly.
The implementation assumes that
x < succ x pred x < x
and there aren't elements in between (not true for Float
and Double
).
Also succ
and pred
are never called for largest or smallest value respectively.
- data RSet a
- (\\) :: (Ord a, Enum a) => RSet a -> RSet a -> RSet a
- null :: RSet a -> Bool
- member :: (Ord a, Enum a) => a -> RSet a -> Bool
- notMember :: (Ord a, Enum a) => a -> RSet a -> Bool
- empty :: RSet a
- full :: Bounded a => RSet a
- singleton :: a -> RSet a
- singletonRange :: Ord a => (a, a) -> RSet a
- insert :: (Ord a, Enum a) => a -> RSet a -> RSet a
- insertRange :: (Ord a, Enum a) => (a, a) -> RSet a -> RSet a
- delete :: (Ord a, Enum a) => a -> RSet a -> RSet a
- deleteRange :: (Ord a, Enum a) => (a, a) -> RSet a -> RSet a
- union :: (Ord a, Enum a) => RSet a -> RSet a -> RSet a
- difference :: (Ord a, Enum a) => RSet a -> RSet a -> RSet a
- intersection :: (Ord a, Enum a) => RSet a -> RSet a -> RSet a
- complement :: (Ord a, Enum a, Bounded a) => RSet a -> RSet a
- elems :: Enum a => RSet a -> [a]
- toList :: Enum a => RSet a -> [a]
- fromList :: (Ord a, Enum a) => [a] -> RSet a
- toRangeList :: RSet a -> [(a, a)]
- fromRangeList :: (Ord a, Enum a) => [(a, a)] -> RSet a
Range set type
Internally set is represented as sorted list of distinct inclusive ranges.
Operators
Query
Construction
singletonRange :: Ord a => (a, a) -> RSet aSource
O(1). Create a continuos range set.
insertRange :: (Ord a, Enum a) => (a, a) -> RSet a -> RSet aSource
O(n). Insert a continuos range in a set.
deleteRange :: (Ord a, Enum a) => (a, a) -> RSet a -> RSet aSource
/O(n). Delete a continuos range from a set.
Combine
intersection :: (Ord a, Enum a) => RSet a -> RSet a -> RSet aSource
O(n*m). The intersection of two sets.
Complement
Conversion
elems :: Enum a => RSet a -> [a]Source
O(n*r). Convert the set to a list of elements. r is the size of longest range.
toList :: Enum a => RSet a -> [a]Source
O(n*r). Convert the set to a list of elements. r is the size of longest range.
toRangeList :: RSet a -> [(a, a)]Source
O(1). Convert the set to a list of range pairs.
fromRangeList :: (Ord a, Enum a) => [(a, a)] -> RSet aSource
O(n^2). Create a set from a list of range pairs.