stable-tree-0.0.1: Trees whose branches are resistant to change

CopyrightJeremy Groven
LicenseBSD3
Safe HaskellNone
LanguageHaskell2010

Data.StableTree.Types.Key

Description

Tools for working with StableTree keys. Just about anything can be a key, so long as there's a sane way to implement IsKey and the standard Ord class.

Typical users don't need to worry about anything here other than perhaps IsKey.

Synopsis

Documentation

class IsKey k where Source

Type class for anything that we can use as a key. The goal here is to wrap up a function that can generate a high-entropy eight-bit "hash". Speed is somewhat important here, but since we only actually look at four bits of the hash, it really shouldn't be a problem to quickly generate sufficiently random data.

Implementors probably want to use hashSerialize, hashBinary, or hashByteString when writing their hash functions.

Methods

hash :: k -> Word8 Source

Generate an 8-bit hash

data Key t k Source

A wrapper for keys; this has an ephemeral t that will be either Terminal or Nonterminal depending on the result of hash k.

Instances

Eq k => Eq (Key t k) 
Ord k => Ord (Key t k) 
Show k => Show (Key t k) 

data SomeKey k Source

A sum type to contain either a Terminal or a Nonterminal Key

Instances

Eq k => Eq (SomeKey k) 
Ord k => Ord (SomeKey k) 
Show k => Show (SomeKey k) 

data Terminal Source

Used to indicate that a Key is terminal

data Nonterminal Source

Used to indicate that a Key is not terminal

wrap :: IsKey k => k -> SomeKey k Source

Do the magic of wrapping up a key into a SomeKey

unwrap :: SomeKey k -> k Source

Extract the original key from a wrapped one

hashSerialize :: Serialize t => t -> Word8 Source

Calculate a hash for an instance of Serialize

hashBinary :: Binary t => t -> Word8 Source

Calculate a hash for an instance of Binary

hashByteString :: ByteString -> Word8 Source

Calculate a hash for a ByteString