Mikan
Safe HaskellNone
LanguageHaskell2010

Mikan.Utils.HashSet.Ordered

Description

Mutable hash sets that preserve insertion order.

Synopsis

Documentation

data HashSet a Source #

A hash set that preserves insertion order.

Size and capacity

size :: HashSet a -> IO Int Source #

Get the number of elements currently stored in the HashSet.

capacity :: HashSet a -> IO Int Source #

Get the current capacity of an HashSet.

Creation

new :: Int -> IO (HashSet a) Source #

Create an HashSet with a specified starting capacity.

Insertion

insertingIfAbsent Source #

Arguments

:: Eq a 
=> HashSet a

The HashSet to operate on

-> a

The element to insert.

-> Int

Its precomputed hash.

-> (a -> Int -> IO r)

Continuation to invoke if the element was already present in the table.

-> (Int -> IO r)

Continuation to invoke if the element was not present in the table.

-> IO r 

Insert a a pre-hashed element in the HashSet, calling one of the continuations depending on whether the element has been newly added or whether it was already present. Both continuations receive an Int index for the element in that HashSet (see index).

This function is lazy in the element to insert, the assumption being that computing the hash should already have forced it.

Indexing

index :: HashSet a -> Int -> IO (Maybe a) Source #

Get the nth element inserted into the hash set.

Conversion

toArray :: HashSet a -> IO (Array a) Source #

Make an immutable copy of the entries in a HashSet.

The elements of toArray hs are ordered by insertion time, with the first element inserted at index 0.