sequential-index-0.2.0.1: Sequential numbers that allow arbitrarily inserting numbers - for containers

Safe Haskell Safe-Inferred

Data.SequentialIndex

Synopsis

# Type

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

Extracts the mantissa.

Extracts the exponent.

# Constructors

The lowest possible number: 0.0.

The highest possible number: 1.0.

The root of a hypothetical binary tree.

Construct a `SequentialIndex` from its `mantissa` and `exponent`.

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

Construct a `SequentialIndex` from its `mantissa` and `exponent`.

Errors are not checked.

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

# Operations

## Arithmetical operations

Compute a number right in the middle of the arguments.

`(x + y) / 2`

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.

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

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

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

# Conversion

Convert a `SequentialIndex` to a binary representation.

Convert a `SequentialIndex` from its binary representation.