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

Portabilityportable
Stabilityprovisional
Maintainerjohan.tibell@gmail.com
Safe HaskellNone

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

Typeable1 HashSet 
Foldable HashSet 
(Hashable a, Eq a) => Eq (HashSet a) 
(Data a, Eq a, Hashable a) => Data (HashSet a) 
Show a => Show (HashSet a) 
(Hashable a, Eq a) => Monoid (HashSet a) 
NFData a => NFData (HashSet a) 

Construction

empty :: HashSet aSource

O(1) Construct an empty set.

singleton :: Hashable a => a -> HashSet aSource

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

Combine

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

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 aSource

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

Basic interface

null :: HashSet a -> BoolSource

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

size :: HashSet a -> IntSource

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

member :: (Eq a, Hashable a) => a -> HashSet a -> BoolSource

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

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

O(min(n,W)) Add the specified value to this set.

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

O(min(n,W)) Remove the specified value from this set if present.

Transformations

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

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 aSource

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 aSource

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

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

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 aSource

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

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 aSource

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