Sha256: db53ac463e2e8d8446c06e969544713cf477fa1253bb7e9d190026c5ce53050c
Contents?: true
Size: 1.83 KB
Versions: 327
Compression:
Stored size: 1.83 KB
Contents
defmodule BinTree do import Inspect.Algebra @moduledoc """ A node in a binary tree. `value` is the value of a node. `left` is the left subtree (nil if no subtree). `right` is the right subtree (nil if no subtree). """ @type t :: %BinTree{ value: any, left: BinTree.t | nil, right: BinTree.t | nil } defstruct value: nil, left: nil, right: nil # A custom inspect instance purely for the tests, this makes error messages # much more readable. # # BT[value: 3, left: BT[value: 5, right: BT[value: 6]]] becomes (3:(5::(6::)):) def inspect(%BinTree{value: v, left: l, right: r}, opts) do concat ["(", to_doc(v, opts), ":", (if l, do: to_doc(l, opts), else: ""), ":", (if r, do: to_doc(r, opts), else: ""), ")"] end end defmodule Zipper do @doc """ Get a zipper focused on the root node. """ @spec from_tree(BT.t) :: Z.t def from_tree(bt) do end @doc """ Get the complete tree from a zipper. """ @spec to_tree(Z.t) :: BT.t def to_tree(z) do end @doc """ Get the value of the focus node. """ @spec value(Z.t) :: any def value(z) do end @doc """ Get the left child of the focus node, if any. """ @spec left(Z.t) :: Z.t | nil def left(z) do end @doc """ Get the right child of the focus node, if any. """ @spec right(Z.t) :: Z.t | nil def right(z) do end @doc """ Get the parent of the focus node, if any. """ @spec up(Z.t) :: Z.t def up(z) do end @doc """ Set the value of the focus node. """ @spec set_value(Z.t, any) :: Z.t def set_value(z, v) do end @doc """ Replace the left child tree of the focus node. """ @spec set_left(Z.t, BT.t) :: Z.t def set_left(z, l) do end @doc """ Replace the right child tree of the focus node. """ @spec set_right(Z.t, BT.t) :: Z.t def set_right(z, r) do end end
Version data entries
327 entries across 327 versions & 1 rubygems