unordered-containers-0.2.10.0: Efficient hashing-based container types

Copyright2011 Bryan O'Sullivan
LicenseBSD-style
Maintainerjohan.tibell@gmail.com
Stabilityprovisional
Portabilityportable
Safe HaskellSafe
LanguageHaskell2010

Data.HashSet

Contents

Description

A set of hashable values. A set cannot contain duplicate items. A HashSet makes no guarantees as to the order of its elements.

The implementation is based on hash array mapped trie. A HashSet is often faster than other tree-based set types, especially when value comparison is expensive, as in the case of strings.

Many operations have a average-case complexity of O(log n). The implementation uses a large base (i.e. 16) so in practice these operations are constant time.

Synopsis

Documentation

data HashSet a Source #

A set of values. A set cannot contain duplicate values.

Instances
Foldable HashSet Source # 
Instance details

Defined in Data.HashSet.Base

Methods

fold :: Monoid m => HashSet m -> m Source #

foldMap :: Monoid m => (a -> m) -> HashSet a -> m Source #

foldr :: (a -> b -> b) -> b -> HashSet a -> b Source #

foldr' :: (a -> b -> b) -> b -> HashSet a -> b Source #

foldl :: (b -> a -> b) -> b -> HashSet a -> b Source #

foldl' :: (b -> a -> b) -> b -> HashSet a -> b Source #

foldr1 :: (a -> a -> a) -> HashSet a -> a Source #

foldl1 :: (a -> a -> a) -> HashSet a -> a Source #

toList :: HashSet a -> [a] Source #

null :: HashSet a -> Bool Source #

length :: HashSet a -> Int Source #

elem :: Eq a => a -> HashSet a -> Bool Source #

maximum :: Ord a => HashSet a -> a Source #

minimum :: Ord a => HashSet a -> a Source #

sum :: Num a => HashSet a -> a Source #

product :: Num a => HashSet a -> a Source #

Eq1 HashSet Source # 
Instance details

Defined in Data.HashSet.Base

Methods

liftEq :: (a -> b -> Bool) -> HashSet a -> HashSet b -> Bool Source #

Ord1 HashSet Source # 
Instance details

Defined in Data.HashSet.Base

Methods

liftCompare :: (a -> b -> Ordering) -> HashSet a -> HashSet b -> Ordering Source #

Show1 HashSet Source # 
Instance details

Defined in Data.HashSet.Base

Methods

liftShowsPrec :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> HashSet a -> ShowS Source #

liftShowList :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> [HashSet a] -> ShowS Source #

Hashable1 HashSet Source # 
Instance details

Defined in Data.HashSet.Base

Methods

liftHashWithSalt :: (Int -> a -> Int) -> Int -> HashSet a -> Int

(Eq a, Hashable a) => IsList (HashSet a) Source # 
Instance details

Defined in Data.HashSet.Base

Associated Types

type Item (HashSet a) :: Type Source #

Methods

fromList :: [Item (HashSet a)] -> HashSet a Source #

fromListN :: Int -> [Item (HashSet a)] -> HashSet a Source #

toList :: HashSet a -> [Item (HashSet a)] Source #

Eq a => Eq (HashSet a) Source # 
Instance details

Defined in Data.HashSet.Base

Methods

(==) :: HashSet a -> HashSet a -> Bool Source #

(/=) :: HashSet a -> HashSet a -> Bool Source #

(Data a, Eq a, Hashable a) => Data (HashSet a) Source # 
Instance details

Defined in Data.HashSet.Base

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> HashSet a -> c (HashSet a) Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (HashSet a) Source #

toConstr :: HashSet a -> Constr Source #

dataTypeOf :: HashSet a -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (HashSet a)) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (HashSet a)) Source #

gmapT :: (forall b. Data b => b -> b) -> HashSet a -> HashSet a Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> HashSet a -> r Source #

gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> HashSet a -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> HashSet a -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> HashSet a -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> HashSet a -> m (HashSet a) Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> HashSet a -> m (HashSet a) Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> HashSet a -> m (HashSet a) Source #

Ord a => Ord (HashSet a) Source # 
Instance details

Defined in Data.HashSet.Base

(Eq a, Hashable a, Read a) => Read (HashSet a) Source # 
Instance details

Defined in Data.HashSet.Base

Show a => Show (HashSet a) Source # 
Instance details

Defined in Data.HashSet.Base

(Hashable a, Eq a) => Semigroup (HashSet a) Source # 
Instance details

Defined in Data.HashSet.Base

Methods

(<>) :: HashSet a -> HashSet a -> HashSet a Source #

sconcat :: NonEmpty (HashSet a) -> HashSet a Source #

stimes :: Integral b => b -> HashSet a -> HashSet a Source #

(Hashable a, Eq a) => Monoid (HashSet a) Source # 
Instance details

Defined in Data.HashSet.Base

NFData a => NFData (HashSet a) Source # 
Instance details

Defined in Data.HashSet.Base

Methods

rnf :: HashSet a -> () Source #

Hashable a => Hashable (HashSet a) Source # 
Instance details

Defined in Data.HashSet.Base

Methods

hashWithSalt :: Int -> HashSet a -> Int

hash :: HashSet a -> Int

type Item (HashSet a) Source # 
Instance details

Defined in Data.HashSet.Base

type Item (HashSet a) = a

Construction

empty :: HashSet a Source #

O(1) Construct an empty set.

singleton :: Hashable a => a -> HashSet a Source #

O(1) Construct a set with a single element.

Combine

union :: (Eq a, Hashable a) => HashSet a -> HashSet a -> HashSet a Source #

O(n+m) Construct a set containing all elements from both sets.

To obtain good performance, the smaller set must be presented as the first argument.

unions :: (Eq a, Hashable a) => [HashSet a] -> HashSet a Source #

Construct a set containing all elements from a list of sets.

Basic interface

null :: HashSet a -> Bool Source #

O(1) Return True if this set is empty, False otherwise.

size :: HashSet a -> Int Source #

O(n) Return the number of elements in this set.

member :: (Eq a, Hashable a) => a -> HashSet a -> Bool Source #

O(log n) Return True if the given value is present in this set, False otherwise.

insert :: (Eq a, Hashable a) => a -> HashSet a -> HashSet a Source #

O(log n) Add the specified value to this set.

delete :: (Eq a, Hashable a) => a -> HashSet a -> HashSet a Source #

O(log n) Remove the specified value from this set if present.

Transformations

map :: (Hashable b, Eq b) => (a -> b) -> HashSet a -> HashSet b Source #

O(n) Transform this set by applying a function to every value. The resulting set may be smaller than the source.

Difference and intersection

difference :: (Eq a, Hashable a) => HashSet a -> HashSet a -> HashSet a Source #

O(n) Difference of two sets. Return elements of the first set not existing in the second.

intersection :: (Eq a, Hashable a) => HashSet a -> HashSet a -> HashSet a Source #

O(n) Intersection of two sets. Return elements present in both the first set and the second.

Folds

foldl' :: (a -> b -> a) -> a -> HashSet b -> a Source #

O(n) Reduce this set by applying a binary operator to all elements, using the given starting value (typically the left-identity of the operator). Each application of the operator is evaluated before before using the result in the next application. This function is strict in the starting value.

foldr :: (b -> a -> a) -> a -> HashSet b -> a Source #

O(n) Reduce this set by applying a binary operator to all elements, using the given starting value (typically the right-identity of the operator).

Filter

filter :: (a -> Bool) -> HashSet a -> HashSet a Source #

O(n) Filter this set by retaining only elements satisfying a predicate.

Conversions

Lists

toList :: HashSet a -> [a] Source #

O(n) Return a list of this set's elements. The list is produced lazily.

fromList :: (Eq a, Hashable a) => [a] -> HashSet a Source #

O(n*min(W, n)) Construct a set from a list of elements.

HashMaps

toMap :: HashSet a -> HashMap a () Source #

O(1) Convert to the equivalent HashMap.

fromMap :: HashMap a () -> HashSet a Source #

O(1) Convert from the equivalent HashMap.