Safe Haskell | Safe-Inferred |
---|

- data SequentialIndex
- mantissa :: SequentialIndex -> Integer
- exponent :: SequentialIndex -> Int
- zero :: SequentialIndex
- one :: SequentialIndex
- root :: SequentialIndex
- sequentialIndex :: Integer -> Int -> SequentialIndex
- unsafeSequentialIndex :: Integer -> Int -> SequentialIndex
- tryFromBools :: [Bool] -> Maybe SequentialIndex
- between :: SequentialIndex -> SequentialIndex -> SequentialIndex
- prefixBits :: Int -> Integer -> SequentialIndex -> SequentialIndex
- build :: Int -> [Integer] -> SequentialIndex
- buildBits :: (Bits a, Integral a) => [a] -> SequentialIndex
- leftChild :: SequentialIndex -> Maybe SequentialIndex
- rightChild :: SequentialIndex -> Maybe SequentialIndex
- parent :: SequentialIndex -> Maybe SequentialIndex
- toByteString :: SequentialIndex -> ByteString
- fromByteString :: ByteString -> Maybe SequentialIndex

# Type

data SequentialIndex Source

An arbitrary-precision number between 0.0 and 1.0. To create new numbers,
use `between`

.

Each number consist of a `mantissa`

(>= 0) and an `exponent`

(> 0), so that
its numeric value equals `mantissa x * 2 ^ (1 - exponent x)`

. The constraint
that it must lie between 0.0 and 1.0 is enforced in the constructors.

It is possible to span a hypothetical tree in this number scheme. Discarding
the last binary digit of the mantissa, which has to be a 1, each digit of
the mantissa denotes a branch in this hypothetical binary tree. So a whole
`SequentialIndex`

(if it ends with 1) corresponds with a path in a binary
tree.

# Extractors

mantissa :: SequentialIndex -> IntegerSource

Extracts the mantissa.

exponent :: SequentialIndex -> IntSource

Extracts the exponent.

# Constructors

The lowest possible number: 0.0.

The highest possible number: 1.0.

The root of a hypothetical binary tree.

sequentialIndex :: Integer -> Int -> SequentialIndexSource

Construct a `SequentialIndex`

from its `mantissa`

and `exponent`

.

Errors are checked and result in a run-time error.

unsafeSequentialIndex :: Integer -> Int -> SequentialIndexSource

Construct a `SequentialIndex`

from its `mantissa`

and `exponent`

.

Errors are not checked.

tryFromBools :: [Bool] -> Maybe SequentialIndexSource

Construct a `SequentialIndex`

from a list of boolean digits. The exponent
equals the number of digits.

# Operations

## Arithmetical operations

between :: SequentialIndex -> SequentialIndex -> SequentialIndexSource

Compute a number right in the middle of the arguments.

(x + y) / 2

prefixBits :: Int -> Integer -> SequentialIndex -> SequentialIndexSource

Add digits in front of the mantissa.

## Tree operations

build :: Int -> [Integer] -> SequentialIndexSource

Build a number from a list of fixed-width mantissa segments.

buildBits :: (Bits a, Integral a) => [a] -> SequentialIndexSource

Build a number from a list of fixed-width mantissa segments.

leftChild :: SequentialIndex -> Maybe SequentialIndexSource

Get the left child of the current path in the hypothetical tree.

rightChild :: SequentialIndex -> Maybe SequentialIndexSource

Get the right child of the current path in the hypothetical tree.

parent :: SequentialIndex -> Maybe SequentialIndexSource

Get the parent of the current path in the hypothetical tree.

# Conversion

toByteString :: SequentialIndex -> ByteStringSource

Convert a `SequentialIndex`

to a binary representation.

fromByteString :: ByteString -> Maybe SequentialIndexSource

Convert a `SequentialIndex`

from its binary representation.