Copyright | (c) 2020 Andrew Lelechenko |
---|---|
License | MIT |
Maintainer | Andrew Lelechenko <andrew.lelechenko@gmail.com> |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
A newtype wrapper around IntSet
.
This module is intended to be imported qualified, e. g.,
import Math.NumberTheory.Primes.IntSet (PrimeIntSet) import qualified Math.NumberTheory.Primes.IntSet as PrimeIntSet
Synopsis
- data PrimeIntSet
- unPrimeIntSet :: PrimeIntSet -> IntSet
- singleton :: Prime Int -> PrimeIntSet
- fromList :: [Prime Int] -> PrimeIntSet
- fromAscList :: [Prime Int] -> PrimeIntSet
- fromDistinctAscList :: [Prime Int] -> PrimeIntSet
- insert :: Prime Int -> PrimeIntSet -> PrimeIntSet
- delete :: Int -> PrimeIntSet -> PrimeIntSet
- member :: Prime Int -> PrimeIntSet -> Bool
- notMember :: Prime Int -> PrimeIntSet -> Bool
- lookupEQ :: Int -> PrimeIntSet -> Maybe (Prime Int)
- lookupLT :: Int -> PrimeIntSet -> Maybe (Prime Int)
- lookupGT :: Int -> PrimeIntSet -> Maybe (Prime Int)
- lookupLE :: Int -> PrimeIntSet -> Maybe (Prime Int)
- lookupGE :: Int -> PrimeIntSet -> Maybe (Prime Int)
- null :: PrimeIntSet -> Bool
- size :: PrimeIntSet -> Int
- isSubsetOf :: PrimeIntSet -> PrimeIntSet -> Bool
- isProperSubsetOf :: PrimeIntSet -> PrimeIntSet -> Bool
- disjoint :: PrimeIntSet -> PrimeIntSet -> Bool
- difference :: PrimeIntSet -> IntSet -> PrimeIntSet
- (\\) :: PrimeIntSet -> IntSet -> PrimeIntSet
- symmetricDifference :: PrimeIntSet -> PrimeIntSet -> PrimeIntSet
- intersection :: PrimeIntSet -> IntSet -> PrimeIntSet
- filter :: (Prime Int -> Bool) -> PrimeIntSet -> PrimeIntSet
- partition :: (Prime Int -> Bool) -> PrimeIntSet -> (PrimeIntSet, PrimeIntSet)
- split :: Int -> PrimeIntSet -> (PrimeIntSet, PrimeIntSet)
- splitMember :: Prime Int -> PrimeIntSet -> (PrimeIntSet, Bool, PrimeIntSet)
- splitLookupEQ :: Int -> PrimeIntSet -> (PrimeIntSet, Maybe (Prime Int), PrimeIntSet)
- splitRoot :: PrimeIntSet -> [PrimeIntSet]
- foldr :: forall b. (Prime Int -> b -> b) -> b -> PrimeIntSet -> b
- foldl :: forall a. (a -> Prime Int -> a) -> a -> PrimeIntSet -> a
- foldr' :: forall b. (Prime Int -> b -> b) -> b -> PrimeIntSet -> b
- foldl' :: forall a. (a -> Prime Int -> a) -> a -> PrimeIntSet -> a
- deleteMin :: PrimeIntSet -> PrimeIntSet
- deleteMax :: PrimeIntSet -> PrimeIntSet
- minView :: PrimeIntSet -> Maybe (Prime Int, PrimeIntSet)
- maxView :: PrimeIntSet -> Maybe (Prime Int, PrimeIntSet)
- toAscList :: PrimeIntSet -> [Prime Int]
- toDescList :: PrimeIntSet -> [Prime Int]
Set type
data PrimeIntSet Source #
A set of Prime
integers.
Instances
unPrimeIntSet :: PrimeIntSet -> IntSet Source #
Convert to a set of integers.
Construction
Use mempty
to create an empty set.
fromAscList :: [Prime Int] -> PrimeIntSet Source #
Build a set from an ascending list of primes (the precondition is not checked).
fromDistinctAscList :: [Prime Int] -> PrimeIntSet Source #
Build a set from an ascending list of distinct primes (the precondition is not checked).
Insertion
insert :: Prime Int -> PrimeIntSet -> PrimeIntSet Source #
Insert a prime into the set.
Deletion
delete :: Int -> PrimeIntSet -> PrimeIntSet Source #
Delete an integer from the set.
Query
member :: Prime Int -> PrimeIntSet -> Bool Source #
Check whether the given prime is a member of the set.
notMember :: Prime Int -> PrimeIntSet -> Bool Source #
Check whether the given prime is not a member of the set.
lookupEQ :: Int -> PrimeIntSet -> Maybe (Prime Int) Source #
Find a prime in the set, equal to the given integer, if any exists.
lookupLT :: Int -> PrimeIntSet -> Maybe (Prime Int) Source #
Find the largest prime in the set, smaller than the given integer, if any exists.
lookupGT :: Int -> PrimeIntSet -> Maybe (Prime Int) Source #
Find the smallest prime in the set, greater than the given integer, if any exists.
lookupLE :: Int -> PrimeIntSet -> Maybe (Prime Int) Source #
Find the largest prime in the set, smaller or equal to the given integer, if any exists.
lookupGE :: Int -> PrimeIntSet -> Maybe (Prime Int) Source #
Find the smallest prime in the set, greater or equal to the given integer, if any exists.
null :: PrimeIntSet -> Bool Source #
Check whether the set is empty.
size :: PrimeIntSet -> Int Source #
Cardinality of the set.
isSubsetOf :: PrimeIntSet -> PrimeIntSet -> Bool Source #
Check whether the first argument is a subset of the second one.
isProperSubsetOf :: PrimeIntSet -> PrimeIntSet -> Bool Source #
Check whether the first argument is a proper subset of the second one.
disjoint :: PrimeIntSet -> PrimeIntSet -> Bool Source #
Check whether two sets are disjoint.
Combine
Use <>
for unions.
difference :: PrimeIntSet -> IntSet -> PrimeIntSet Source #
Difference between a set of primes and a set of integers.
(\\) :: PrimeIntSet -> IntSet -> PrimeIntSet infixl 9 Source #
An alias to difference
.
symmetricDifference :: PrimeIntSet -> PrimeIntSet -> PrimeIntSet Source #
Symmetric difference of two sets of primes.
intersection :: PrimeIntSet -> IntSet -> PrimeIntSet Source #
Intersection of a set of primes and a set of integers.
Filter
filter :: (Prime Int -> Bool) -> PrimeIntSet -> PrimeIntSet Source #
Filter primes satisfying a predicate.
partition :: (Prime Int -> Bool) -> PrimeIntSet -> (PrimeIntSet, PrimeIntSet) Source #
Partition primes according to a predicate.
split :: Int -> PrimeIntSet -> (PrimeIntSet, PrimeIntSet) Source #
Split into primes strictly less and strictly greater than the first argument.
splitMember :: Prime Int -> PrimeIntSet -> (PrimeIntSet, Bool, PrimeIntSet) Source #
splitLookupEQ :: Int -> PrimeIntSet -> (PrimeIntSet, Maybe (Prime Int), PrimeIntSet) Source #
splitRoot :: PrimeIntSet -> [PrimeIntSet] Source #
Decompose a set into pieces based on the structure of the underlying tree.
Folds
foldr :: forall b. (Prime Int -> b -> b) -> b -> PrimeIntSet -> b Source #
Fold a set using the given right-associative operator.
foldl :: forall a. (a -> Prime Int -> a) -> a -> PrimeIntSet -> a Source #
Fold a set using the given left-associative operator.
foldr' :: forall b. (Prime Int -> b -> b) -> b -> PrimeIntSet -> b Source #
A strict version of foldr
.
foldl' :: forall a. (a -> Prime Int -> a) -> a -> PrimeIntSet -> a Source #
A strict version of foldl
.
Min/Max
deleteMin :: PrimeIntSet -> PrimeIntSet Source #
Delete the smallest prime in the set.
deleteMax :: PrimeIntSet -> PrimeIntSet Source #
Delete the largest prime in the set.
minView :: PrimeIntSet -> Maybe (Prime Int, PrimeIntSet) Source #
Split a set into the smallest prime and the rest, if non-empty.
maxView :: PrimeIntSet -> Maybe (Prime Int, PrimeIntSet) Source #
Split a set into the largest prime and the rest, if non-empty.
Conversion
toDescList :: PrimeIntSet -> [Prime Int] Source #
Convert the set to a list of descending primes.