Copyright | (c) Eric Mertens 2021 |
---|---|
License | ISC |
Maintainer | emertens@gmail.com |
Safe Haskell | None |
Language | Haskell2010 |
A compact set type for when you have very few elements to track.
Synopsis
- newtype SmallSet = SmallSet Word64
- fromList :: [Int] -> SmallSet
- toList :: SmallSet -> [Int]
- inRange :: Int -> Bool
- empty :: SmallSet
- singleton :: Int -> SmallSet
- union :: SmallSet -> SmallSet -> SmallSet
- unions :: [SmallSet] -> SmallSet
- intersection :: SmallSet -> SmallSet -> SmallSet
- difference :: SmallSet -> SmallSet -> SmallSet
- insert :: Int -> SmallSet -> SmallSet
- delete :: Int -> SmallSet -> SmallSet
- member :: Int -> SmallSet -> Bool
- size :: SmallSet -> Int
Documentation
Sets of integers from 0 to 63 efficiently implemented using a Word64
fromList :: [Int] -> SmallSet Source #
Construct a set given a list of set members.
>>>
fromList []
fromList []
>>>
fromList [0]
fromList [0]
>>>
fromList [63]
fromList [63]
>>>
fromList [0,10,20]
fromList [0,10,20]
singleton :: Int -> SmallSet Source #
Make a new set with a single element
>>>
singleton 42
fromList [42]
union :: SmallSet -> SmallSet -> SmallSet Source #
Compute the union of two sets
>>>
union (fromList [3,4,5,6]) (fromList [5,6,7,8])
fromList [3,4,5,6,7,8]
unions :: [SmallSet] -> SmallSet Source #
Union of the sets in a list
>>>
unions []
fromList []
>>>
unions [singleton 1, fromList [2,4], fromList [2,3]]
fromList [1,2,3,4]
intersection :: SmallSet -> SmallSet -> SmallSet Source #
Compute the intersection of two sets
>>>
intersection (fromList [3,4,5,6]) (fromList [5,6,7,8])
fromList [5,6]
difference :: SmallSet -> SmallSet -> SmallSet Source #
Subtract the elements of the second set from the first set.
>>>
difference (fromList [3,4,5,6]) (fromList [5,6,7,8])
fromList [3,4]
insert :: Int -> SmallSet -> SmallSet Source #
Add an element to a set
>>>
insert 10 (fromList [3,4,5])
fromList [3,4,5,10]
>>>
insert 5 (fromList [3,4,5])
fromList [3,4,5]
delete :: Int -> SmallSet -> SmallSet Source #
Remove an element from a set
>>>
delete 5 (fromList [3,4,5])
fromList [3,4]
>>>
delete 8 (fromList [3,4,5])
fromList [3,4,5]