src/StateTree.bend relies on unsafe/foreign
raw source on the hub · import ber-core-store@0.1.1.0/src/StateTree.bend as StateTree
5 imports
import Base import ./Reading.bend as Reading import ./ContentHash.bend as ContentHash import ./JsonAdapter.bend as JsonAdapter import bend-kit-json@0.3.0.0/json.bend as Json
Types
type StateTreeNode source · line 14 · raw
Data
Tree hash with sorted entries; children reserved for partitioning.
Make@tree_hash:String -> @entries:List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry> -> @children_hashes:List<&2, String> -> StateTreeNode
Definitions
def tree_entries source · line 18 · raw
@tree_node:StateTreeNode -> List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry>
Projects the entries out of a tree node.
def tree_hash_of source · line 24 · raw
@tree_node:StateTreeNode -> String
Projects the hash out of a tree node.
def flatten_head source · line 30 · raw
@+head_entry:0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry -> @flattened_tail:String -> String
Appends one key=value pair to the flattened text.
def flatten_entries source · line 34 · raw
@sorted_entries:List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry> -> String
Flattens sorted entries into the hashed text.
def compute_tree_hash source · line 42 · raw
@sorted_entries:List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry> -> String
Hashes the flattened entries; the tree address.
def decide_ordering source · line 46 · raw
@ordering:Cmp -> @base_head:0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry -> @base_tail:List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry> -> @staged_head:0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry -> @inserted_tail:List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry> -> List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry>
Merges one step by key order; staged wins ties.
def decide_insert source · line 56 · raw
@cmp_result:Pair(Pair(String, String), Cmp) -> @base_head:0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry -> @base_tail:List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry> -> @staged_head:0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry -> @inserted_tail:List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry> -> List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry>
Unpacks the comparison result into the ordering step.
def insert_single_entry source · line 62 · raw
@base_entries:List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry> -> @+staged_head:0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry -> List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry>
Inserts one staged entry into sorted position.
def merge_sorted_entries source · line 70 · raw
@staged_entries:List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry> -> @base_entries:List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry> -> List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry>
Folds staged entries into the base list, sorted.
def entry_pair_to_json source · line 78 · raw
@+head_entry:0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry -> 0xaaa10a97bf5ac6990143da2c863f8a3f/json.Val
Encodes one entry as a two-item JSON array.
def entry_list_to_json source · line 82 · raw
@sorted_entries:List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry> -> List<&2, 0xaaa10a97bf5ac6990143da2c863f8a3f/json.Val>
Encodes the entry list as a JSON array.
def finalize_tree_document source · line 90 · raw
@hash_field:Sigma<&2, &2, String, _ => 0xaaa10a97bf5ac6990143da2c863f8a3f/json.Val> -> @entries_field:Sigma<&2, &2, String, _ => 0xaaa10a97bf5ac6990143da2c863f8a3f/json.Val> -> @children_field:Sigma<&2, &2, String, _ => 0xaaa10a97bf5ac6990143da2c863f8a3f/json.Val> -> String
Encodes the hash/entries/children document canonically.
def serialize_tree source · line 94 · raw
@+merged_entries:List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry> -> @+tree_hash_value:String -> String
Serializes a merged entry list with its hash.
def prepend_entry_pair source · line 98 · raw
@key_text:String -> @value_text:String -> @parsed_tail:Maybe<&2, List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry>> -> Maybe<&2, List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry>>
Conses a decoded pair onto the tail.
def prepend_value_text source · line 106 · raw
@key_text:String -> @value_maybe:Maybe<&2, String> -> @parsed_tail:Maybe<&2, List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry>> -> Maybe<&2, List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry>>
Unwraps the value text, then prepends.
def prepend_pair_texts source · line 114 · raw
@key_maybe:Maybe<&2, String> -> @value_maybe:Maybe<&2, String> -> @parsed_tail:Maybe<&2, List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry>> -> Maybe<&2, List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry>>
Unwraps the key text, then continues.
def prepend_pair_items source · line 122 · raw
@pair_items:List<&2, 0xaaa10a97bf5ac6990143da2c863f8a3f/json.Val> -> @parsed_tail:Maybe<&2, List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry>> -> Maybe<&2, List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry>>
Decodes one [key, value] array; None on wrong shape.
def prepend_parsed_pair source · line 130 · raw
@pair_maybe:Maybe<&2, List<&2, 0xaaa10a97bf5ac6990143da2c863f8a3f/json.Val>> -> @parsed_tail:Maybe<&2, List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry>> -> Maybe<&2, List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry>>
Unwraps the pair array, then decodes.
def prepend_parsed_entry source · line 138 · raw
@head_item:0xaaa10a97bf5ac6990143da2c863f8a3f/json.Val -> @parsed_tail:Maybe<&2, List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry>> -> Maybe<&2, List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry>>
Decodes one entry item.
def parse_entry_list source · line 142 · raw
@entry_items:List<&2, 0xaaa10a97bf5ac6990143da2c863f8a3f/json.Val> -> Maybe<&2, List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry>>
Decodes the entry array; None on any bad item.
def prepend_child_tail source · line 150 · raw
@head_text:String -> @parsed_tail:Maybe<&2, List<&2, String>> -> Maybe<&2, List<&2, String>>
Conses a decoded hash onto the tail.
def prepend_child_text source · line 158 · raw
@head_maybe:Maybe<&2, String> -> @parsed_tail:Maybe<&2, List<&2, String>> -> Maybe<&2, List<&2, String>>
Unwraps the child hash text, then prepends.
def prepend_child_string source · line 166 · raw
@head_item:0xaaa10a97bf5ac6990143da2c863f8a3f/json.Val -> @parsed_tail:Maybe<&2, List<&2, String>> -> Maybe<&2, List<&2, String>>
Decodes one child-hash item.
def extract_child_strings source · line 170 · raw
@child_items:List<&2, 0xaaa10a97bf5ac6990143da2c863f8a3f/json.Val> -> Maybe<&2, List<&2, String>>
Decodes the children array; None on any non-string.
def finish_tree_node source · line 178 · raw
@tree_hash_text:String -> @parsed_entries:List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry> -> @strings_maybe:Maybe<&2, List<&2, String>> -> Maybe<&2, StateTreeNode>
Reassembles the node once children decode.
def finish_children_strings source · line 186 · raw
@tree_hash_text:String -> @parsed_entries:List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry> -> @items_maybe:Maybe<&2, List<&2, 0xaaa10a97bf5ac6990143da2c863f8a3f/json.Val>> -> Maybe<&2, StateTreeNode>
Unwraps the children array items, then finishes.
def extract_children_array source · line 194 · raw
@tree_hash_text:String -> @parsed_entries:List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry> -> @children_maybe:Maybe<&2, 0xaaa10a97bf5ac6990143da2c863f8a3f/json.Val> -> Maybe<&2, StateTreeNode>
Unwraps the children field, then continues.
def extract_children source · line 202 · raw
@+document:0xaaa10a97bf5ac6990143da2c863f8a3f/json.Val -> @tree_hash_text:String -> @entries_maybe:Maybe<&2, List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry>> -> Maybe<&2, StateTreeNode>
Unwraps parsed entries, then reads children.
def extract_entry_items source · line 210 · raw
@+document:0xaaa10a97bf5ac6990143da2c863f8a3f/json.Val -> @tree_hash_text:String -> @items_maybe:Maybe<&2, List<&2, 0xaaa10a97bf5ac6990143da2c863f8a3f/json.Val>> -> Maybe<&2, StateTreeNode>
Unwraps the entry items, then parses.
def extract_entry_array source · line 218 · raw
@+document:0xaaa10a97bf5ac6990143da2c863f8a3f/json.Val -> @tree_hash_text:String -> @entries_maybe:Maybe<&2, 0xaaa10a97bf5ac6990143da2c863f8a3f/json.Val> -> Maybe<&2, StateTreeNode>
Unwraps the entries field, then continues.
def extract_with_tree_entries source · line 226 · raw
@+document:0xaaa10a97bf5ac6990143da2c863f8a3f/json.Val -> @hash_text_maybe:Maybe<&2, String> -> @entries_maybe:Maybe<&2, 0xaaa10a97bf5ac6990143da2c863f8a3f/json.Val> -> Maybe<&2, StateTreeNode>
Unwraps the hash text, then reads entries.
def extract_with_tree_hash source · line 234 · raw
@+document:0xaaa10a97bf5ac6990143da2c863f8a3f/json.Val -> @hash_maybe:Maybe<&2, 0xaaa10a97bf5ac6990143da2c863f8a3f/json.Val> -> Maybe<&2, StateTreeNode>
Unwraps the hash field, then continues.
def extract_tree_fields source · line 242 · raw
@+document:0xaaa10a97bf5ac6990143da2c863f8a3f/json.Val -> Maybe<&2, StateTreeNode>
Reads the hash field of the document.
def tree_from_parse source · line 246 · raw
@parse_result:Maybe<&2, 0xaaa10a97bf5ac6990143da2c863f8a3f/json.Val> -> Maybe<&2, StateTreeNode>
Builds the node from parsed JSON; None on malformed input.
def parse_tree_document source · line 254 · raw
@stored_text:String -> Maybe<&2, StateTreeNode>
Parses stored tree text into a node.