package grenier

  1. Overview
  2. Docs
A collection of various algorithms in OCaml

Install

Dune Dependency

Authors

Maintainers

Sources

grenier-v0.12.tbz
sha256=b08e4c774ef72fc53c4fcee477e739d1beac9702079300daddf51ced9fa9cd26
sha512=984d92c51dac7b3f169cad595969a4fdbeb2be7b420ed1a85618d6adbb64af855cf2618d9bd0834e84d6734b99196944cab04435e1aeacad8cdfbc9a7f73d6d4

doc/grenier.baltree/Bt2/index.html

Module Bt2Source

Sourcetype (+'a, +'b) t = private
  1. | Leaf
  2. | Node of int * ('a, 'b) t * 'a * 'b * ('a, 'b) t
    (*

    Node(size, l, x, r) where:

    • size is the number of elements in the tree,
    • l is the left sub-tree
    • x is a user-defined value
    • r is the right sub-tree.

    Trees are guaranteed balanced by construction, the depth of all branches is O(log size).

    *)

Type of balanced trees with two custom values (more efficient than a pair)

Sourceval leaf : ('a, 'b) t

Leaf constructor, the empty tree

Sourceval node : ('a, 'b) t -> 'a -> 'b -> ('a, 'b) t -> ('a, 'b) t

Smart Node constructor, ensuring that the resulting tree is balanced and has the appropriate size.

Cost of node l x r is expected to be O(log |size l - size r|) amortized, i.e proportional to the logarithm of the disbalance. In particular, if l and r are similarly-sized, it operates in constant time on average. NOT PROVEN

User-values can be moved in different subtrees of the result, but the ordering is preserved (so data stay correct if the operation applied on values is associative or the relation expected between them is transitive).

Convenience functions

Sourceval size : ('a, 'b) t -> int

Accessor to the size

Sourceval join : ('a, 'b) t -> ('a, 'b) t -> ('a, 'b) t

Concatenate two trees. Cost of join l r is O(log (min size l size r)). NOT PROVEN

Sourceval rank : int -> ('a, 'b) t -> 'a * 'b

Return the n'th node in tree order

OCaml

Innovation. Community. Security.