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

Safe HaskellSafe-Inferred

Data.SequentialIndex

Contents

Synopsis

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

zero :: SequentialIndexSource

The lowest possible number: 0.0.

one :: SequentialIndexSource

The highest possible number: 1.0.

root :: SequentialIndexSource

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.