nephrotoma

Nephrotoma is a library for creating a tree and querying whether a node exists at a path.
The head of a tree contains only a dictionary of child nodes. Each node contains a boolean that signifies that this is an endpoint and a dictionary of child nodes. This tree:

      +---------------+
      | children:     |
      | 1, 4          |
      +-+--+----------+
        |  |
        |  +---------------+
        |                  |
+---------------+  +---------------+
| exists: True  |  | exists: False |
| children:     |  | children:     |
| (none)        |  | 8             |
+---------------+  +-+-------------+
                     |
             +---------------+
             | exists: True  |
             | children:     |
             | 11, 12        |
             +-+---+---------+
               |   |
       +-------+   +-------+
       |                   |
+---------------+  +---------------+
| exists: True  |  | exists: True  |
| children:     |  | children:     |
| (none)        |  | (none)        |
+---------------+  +---------------+

could be created with:

let tree = nephrotoma.from_list([1])
|> nephrotoma.append_list([4, 8])
|> nephrotoma.append_list([4, 8, 11])
|> nephrotoma.append_list([4, 8, 12])

and could be checked with:

tree |> nephrotoma.exists([4, 8])
// -> True
tree |> nephrotoma.exists([4, 8, 11])
// -> True
tree |> nephrotoma.exists([1, 9])
// -> False
tree |> nephrotoma.exists([4])
// -> False
tree |> nephrotoma.exists([])
// -> False

Types

The start of a tree, containing only a dictionary of child nodes.

pub type OrderedTree(key) {
  OrderedTree(children: Dict(key, OrderedTreeNode(key)))
}

Constructors

  • OrderedTree(children: Dict(key, OrderedTreeNode(key)))

Functions

pub fn append_list(
  tree: OrderedTree(a),
  list: List(a),
) -> OrderedTree(a)

Add a path as existing to a tree.

new()
|> append_list([1, 2, 3])
|> exists([1, 2, 3])
// -> True
pub fn exists(tree: OrderedTree(a), path: List(a)) -> Bool

Check whether a path exists in a node. Always returns false if either the node or inputted path are empty.

let tree = from_list([1, 2, 3])
tree |> exists([1, 2, 3])
// -> True
tree |> exists([1, 2])
// -> False
tree |> exists([1, 2, 3, 4])
// -> False
tree |> exists([])
// -> False
pub fn from_list(list: List(a)) -> OrderedTree(a)

Equivalent to creating a new tree and adding a path.

from_list([1, 2, 3])
|> exists([1, 2, 3])
// -> True
pub fn new() -> OrderedTree(a)

Create an empty ordered tree.

let tree = new()
Search Document