identifiers-0.4.3.0: Numeric identifiers for values.

Copyright(c) Adam Wagner 2017
Safe HaskellNone
LanguageHaskell2010

Data.Identifiers.Hashable

Contents

Description

Identifiers for Hashable values.

Example usage:

>>> xs = fromList ["foo", "bar", "baz", "foo"]
>>> lookupId xs "baz"
Just 2
>>> lookupKey xs 2
Just "baz"

Synopsis

Documentation

data Identifiers i a Source #

Instances

(Eq i, Eq a) => Eq (Identifiers i a) Source # 

Methods

(==) :: Identifiers i a -> Identifiers i a -> Bool #

(/=) :: Identifiers i a -> Identifiers i a -> Bool #

Show a => Show (Identifiers i a) Source # 

Methods

showsPrec :: Int -> Identifiers i a -> ShowS #

show :: Identifiers i a -> String #

showList :: [Identifiers i a] -> ShowS #

(Binary i, Eq a, Hashable a, Binary a) => Binary (Identifiers i a) Source # 

Methods

put :: Identifiers i a -> Put #

get :: Get (Identifiers i a) #

putList :: [Identifiers i a] -> Put #

(Serialize i, Eq a, Hashable a, Serialize a) => Serialize (Identifiers i a) Source # 

Methods

put :: Putter (Identifiers i a) #

get :: Get (Identifiers i a) #

(NFData i, NFData a) => NFData (Identifiers i a) Source # 

Methods

rnf :: Identifiers i a -> () #

Construction

empty :: Identifiers i a Source #

The empty Identifiers

fromList :: (Integral i, Hashable a, Eq a) => [a] -> Identifiers i a Source #

New Identifiers from list

combine :: (Integral i, Hashable a, Eq a) => Identifiers i a -> Identifiers i a -> (Identifiers i a, Map i i) Source #

Combine two identifier sets into one. Because the ids will change while combining two sets, a map is also returned that identifies the new location of old ids for the second set passed in.

Insertion

insert :: (Integral i, Hashable a, Eq a) => Identifiers i a -> a -> Identifiers i a Source #

Insert item into set (given it a new id)

insertMany :: (Integral i, Hashable a, Eq a) => Identifiers i a -> [a] -> Identifiers i a Source #

Insert many items into set

Info

size :: Identifiers i a -> Int Source #

Number of items in Identifiers value

Extraction

toList :: Identifiers i a -> [a] Source #

New List from Identifiers

Lookups

lookupId :: (Hashable a, Eq a) => Identifiers i a -> a -> Maybe i Source #

Find id for given key

lookupKey :: Integral i => Identifiers i a -> i -> Maybe a Source #

Find key for given id

lookupKeys :: Integral i => Identifiers i a -> [i] -> [a] Source #

Given many ids, return many keys

unsafeLookupId :: (Hashable a, Eq a) => Identifiers i a -> a -> i Source #

Find numeric id for given value. Will error when the value is not a member of the Identifiers map.

unsafeLookupKey :: Integral i => Identifiers i a -> i -> a Source #

Find id for given value. Will error when the id has no associated value.

(!) :: Integral i => Identifiers i a -> i -> a Source #

Infix version of unsafeLookupKey

Properties

prop_hasId :: String -> Bool Source #

Items inserted are given ids

prop_stableId :: String -> Bool Source #

Inserted items have stable ids

prop_keyRetrieval :: [String] -> Bool Source #

Given id can be used to fetch inserted item

prop_keyRetrievalUnsafe :: [String] -> Bool Source #

Given id can be used to fetch inserted item

prop_idempotent :: String -> Bool Source #

Inserting something more than once does not change the set

prop_stableCombine :: [String] -> [String] -> Bool Source #

Ids for the first set passed to combine remain unchanged

prop_properMigration :: [String] -> [String] -> Bool Source #

Ensure the migration points to the same value in both old and new sets