Safe Haskell | None |
---|---|
Language | Haskell2010 |
- data Index key node = Index !(Vector key) !(Vector node)
- indexNumKeys :: Index key val -> Int
- indexNumVals :: Index key val -> Int
- validIndex :: Ord key => Index key node -> Bool
- validIndexSize :: Ord key => Int -> Int -> Index key node -> Bool
- splitIndexAt :: Int -> Index key val -> (Index key val, key, Index key val)
- extendedIndex :: Int -> (Index k b -> a) -> Index k b -> Index k a
- extendIndexPred :: (a -> Bool) -> (Index k b -> a) -> Index k b -> Maybe (Index k a)
- mergeIndex :: Index key val -> key -> Index key val -> Index key val
- indexFromList :: [key] -> [val] -> Index key val
- singletonIndex :: val -> Index key val
- fromSingletonIndex :: Index key val -> Maybe val
- bindIndex :: Index k a -> (a -> Index k b) -> Index k b
- bindIndexM :: (Functor m, Monad m) => Index k a -> (a -> m (Index k b)) -> m (Index k b)
- data IndexCtx key val = IndexCtx {
- indexCtxLeftKeys :: !(Vector key)
- indexCtxRightKeys :: !(Vector key)
- indexCtxLeftVals :: !(Vector val)
- indexCtxRightVals :: !(Vector val)
- putVal :: IndexCtx key val -> val -> Index key val
- putIdx :: IndexCtx key val -> Index key val -> Index key val
- valView :: Ord key => key -> Index key val -> (IndexCtx key val, val)
- valViewMin :: Index key val -> (IndexCtx key val, val)
- valViewMax :: Index key val -> (IndexCtx key val, val)
- distribute :: Ord k => Map k v -> Index k node -> Index k (Map k v, node)
- leftView :: IndexCtx key val -> Maybe (IndexCtx key val, val, key)
- rightView :: IndexCtx key val -> Maybe (key, val, IndexCtx key val)
Documentation
The Index
encodes the internal structure of an index node.
The index is abstracted over the type node
of sub-trees. The keys and
nodes are stored in separate Vector
s and the keys are sorted in strictly
increasing order. There should always be one more sub-tree than there are
keys. Hence structurally the smallest Index
has one sub-tree and no keys,
but a valid B+-tree index node will have at least two sub-trees and one key.
validIndex :: Ord key => Index key node -> Bool Source #
Validate the key/node count invariant of an Index
.
validIndexSize :: Ord key => Int -> Int -> Index key node -> Bool Source #
Validate the size of an Index
.
splitIndexAt :: Int -> Index key val -> (Index key val, key, Index key val) Source #
Split an index node.
This function splits an index node into two new nodes at the given key
position numLeftKeys
and returns the resulting indices and the key
separating them. Eventually this should take the binary size of serialized
keys and sub-tree pointers into account. See also splitLeaf
in
Data.BTree.Primitives.Leaf.
extendedIndex :: Int -> (Index k b -> a) -> Index k b -> Index k a Source #
Split an index many times.
This function splits an Index
node into smaller pieces. Each resulting
sub-Index
has between maxIdxKeys/2
and maxIdxKeys
inclusive values and
is additionally applied to the function f
.
This is the dual of a monadic bind and is also known as the extended
function of extendable functors. See Data.Functor.Extend in the
"semigroupoids" package.
bindIndex (extendedIndex n id idx) id == idx
mergeIndex :: Index key val -> key -> Index key val -> Index key val Source #
Merge two indices.
Merge two indices leftIndex
, rightIndex
given a discriminating key
middleKey
, i.e. such that '∀ (k,v) ∈ leftIndex. k < middleKey' and
'∀ (k,v) ∈ rightIndex. middleKey <= k'.
mergeIndex
is a partial inverse of splitIndex, i.e.
prop> splitIndex is == (left,mid,right) => mergeIndex left mid right == is
indexFromList :: [key] -> [val] -> Index key val Source #
Create an index from key-value lists.
The internal invariants of the Index
data structure apply. That means
there is one more value than there are keys and keys are ordered in strictly
increasing order.
singletonIndex :: val -> Index key val Source #
Create an index with a single value.
fromSingletonIndex :: Index key val -> Maybe val Source #
Test if the index consists of a single value.
Returns the element if the index is a singleton. Otherwise fails.
fromSingletonIndex (singletonIndex val) == Just val
bindIndex :: Index k a -> (a -> Index k b) -> Index k b Source #
Bind an index
bindIndex idx singletonIndex == idx
data IndexCtx key val Source #
Representation of one-hole contexts of Index
.
Just one val removes. All keys are present.
V.length leftVals == V.length lefyKeys
V.length rightVals == V.length rightKeys
IndexCtx | |
|
valViewMin :: Index key val -> (IndexCtx key val, val) Source #
valViewMax :: Index key val -> (IndexCtx key val, val) Source #