src/Comparison.bend fails
raw source on the hub · import ber-core-store@0.1.1.0/src/Comparison.bend as Comparison
6 imports
import Base import ./Reading.bend as Reading import ./LogicalKey.bend as LogicalKey import ./StateTree.bend as StateTree import ./History.bend as History import ./Store.bend as Store
Types
type ModifiedEntry source · line 16 · raw
Data
One changed key with its before/after hashes.
Changed@changed_key:0xf481b310e24036f2ebffda42e94b3b4c/src/LogicalKey.LogicalKey -> @before_hash:String -> @after_hash:String -> ModifiedEntry
type CompareResult source · line 20 · raw
Data
Added, removed and modified sets plus prune/compare counts.
Make@added_keys:List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/LogicalKey.LogicalKey> -> @removed_keys:List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/LogicalKey.LogicalKey> -> @modified_entries:List<&2, ModifiedEntry> -> @pruned_subtree_count:Nat -> @compared_entry_count:Nat -> CompareResult
Definitions
def added_keys_of source · line 24 · raw
@compare_result:CompareResult -> List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/LogicalKey.LogicalKey>
Projects the added keys out of a compare result.
def removed_keys_of source · line 30 · raw
@compare_result:CompareResult -> List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/LogicalKey.LogicalKey>
Projects the removed keys out of a compare result.
def modified_entries_of source · line 36 · raw
@compare_result:CompareResult -> List<&2, ModifiedEntry>
Projects the modified entries out of a compare result.
def pruned_count_of source · line 42 · raw
@compare_result:CompareResult -> Nat
Projects the pruned-subtree count out of a compare result.
def compared_entry_count_of source · line 48 · raw
@compare_result:CompareResult -> Nat
Projects the compared-entry count out of a compare result.
def entry_to_logical_key source · line 54 · raw
@head_entry:0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry -> 0xf481b310e24036f2ebffda42e94b3b4c/src/LogicalKey.LogicalKey
Splits an entry key into namespace and record.
def decide_member_found source · line 58 · raw
@head_matches:Bool -> @recursive_result:Bool -> Bool
True short-circuits the membership scan.
def key_in_entries source · line 66 · raw
@+target_key:String -> @entries:List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry> -> Bool
Scans entries for the target key.
def decide_member_keep source · line 74 · raw
@is_member:Bool -> @+head_entry:0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry -> @tail_keys:List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/LogicalKey.LogicalKey> -> List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/LogicalKey.LogicalKey>
Keeps the entry only when absent from the other side.
def second_only_entries source · line 82 · raw
@+first_entries:List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry> -> @second_entries:List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry> -> List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/LogicalKey.LogicalKey>
Keys of second absent from first: the added set.
def first_only_entries source · line 90 · raw
@+second_entries:List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry> -> @first_entries:List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry> -> List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/LogicalKey.LogicalKey>
Keys of first absent from second: the removed set.
def decide_value_found source · line 98 · raw
@head_matches:Bool -> @head_value:String -> @tail_result:Maybe<&2, String> -> Maybe<&2, String>
Some on match, otherwise the tail result.
def value_of_key source · line 106 · raw
@+target_key:String -> @entries:List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry> -> Maybe<&2, String>
Finds the value stored under the key.
def decide_modified_value source · line 114 · raw
@values_equal:Bool -> @+head_entry:0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry -> @+second_value:String -> @tail_modified:List<&2, ModifiedEntry> -> List<&2, ModifiedEntry>
Records a change only when values differ.
def decide_modified_member source · line 122 · raw
@second_value_maybe:Maybe<&2, String> -> @+head_entry:0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry -> @tail_modified:List<&2, ModifiedEntry> -> List<&2, ModifiedEntry>
Records a change when the key exists on both sides.
def changed_pairs source · line 130 · raw
@+second_entries:List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry> -> @first_entries:List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry> -> List<&2, ModifiedEntry>
Shared keys with different values: the modified set.
def compare_sorted_entries source · line 138 · raw
@+first_entries:List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry> -> @+second_entries:List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry> -> CompareResult
Membership diff core; counts cover both inputs.
def split_step source · line 142 · raw
@entries:List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry> -> @take_head:Bool -> @evens_accum:List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry> -> @odds_accum:List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry> -> Pair(List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry>, List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry>)
Alternates entries into even/odd accumulators, then reverses.
def split_entries source · line 154 · raw
@+source_entries:List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry> -> Pair(List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry>, List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry>)
Splits into balanced halves for any key distribution.
def decide_linear_value source · line 158 · raw
@values_equal:Bool -> @+first_head:0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry -> @+second_head:0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry -> @+tail_diff:CompareResult -> CompareResult
Copies the spine so each lane scans a private list without atomics.
def merge_dispatch source · line 179 · raw
@cmp_result:Pair(Pair(String, String), Cmp) -> @first_head:0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry -> @first_tail:List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry> -> @second_head:0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry -> @second_tail:List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry> -> List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry>
Unpacks the key comparison into the ordering step.
def sort_fuel source · line 208 · raw
@remaining_fuel:Nat -> @unsorted_entries:List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry> -> List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry>
Merge sort with Nat fuel; fuel bounds recursion depth, not size.
def sort_entries_by_key source · line 222 · raw
@+unsorted_entries:List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry> -> List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry>
Sorts entries by key; fuel starts at the entry count.
def prepend_linear_removed source · line 239 · raw
@+head_entry:0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry -> @+tail_diff:CompareResult -> CompareResult
Prepends a removed key to a computed tail diff; one entry consumed.
def prepend_linear_added source · line 243 · raw
@+head_entry:0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry -> @+tail_diff:CompareResult -> CompareResult
Prepends an added key to a computed tail diff; one entry consumed.
def dispatch_linear_diff source · line 247 · raw
@cmp_result:Pair(Pair(String, String), Cmp) -> @+first_head:0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry -> @first_tail:List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry> -> @+second_head:0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry -> @second_tail:List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry> -> CompareResult
Unpacks the key comparison into the linear-diff step.
def linear_diff_heads source · line 253 · raw
@+first_head:0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry -> @first_tail:List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry> -> @+second_head:0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry -> @second_tail:List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry> -> CompareResult
Decides one linear-diff step over sorted heads.
def merge_sorted_diff source · line 257 · raw
@+first_sorted:List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry> -> @+second_sorted:List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry> -> CompareResult
Linear diff over two sorted lists; counts cover both inputs.
def compare_entries_sorted source · line 269 · raw
@+first_entries:List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry> -> @+second_entries:List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry> -> CompareResult
Sorted-path diff: sorts both lists, then linear-diffs.
def compare_entries_auto source · line 273 · raw
@+first_entries:List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry> -> @+second_entries:List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry> -> CompareResult
Routes every compare through the sorted path; fastest at all sizes.
def entries_or_empty source · line 277 · raw
@tree_maybe:Maybe<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/StateTree.StateTreeNode> -> List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry>
Missing trees read as empty entry lists.
def hash_or_empty source · line 285 · raw
@tree_maybe:Maybe<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/StateTree.StateTreeNode> -> String
Missing trees hash as the empty string.
def pruned_result source · line 293 · raw
@first_entries:List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry> -> @second_entries:List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry> -> CompareResult
Equal hashes yield an empty delta with one prune counted.
def pruned_or_present source · line 297 · raw
@second_maybe:Maybe<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/StateTree.StateTreeNode> -> @first_entries:List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry> -> CompareResult
Missing second tree degrades to a one-sided diff.
def pruned_or_empty source · line 305 · raw
@first_maybe:Maybe<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/StateTree.StateTreeNode> -> @second_maybe:Maybe<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/StateTree.StateTreeNode> -> CompareResult
Missing first tree degrades to a one-sided diff.
def dispatch_tree_hashes source · line 313 · raw
@hashes_equal:Bool -> @+first_maybe:Maybe<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/StateTree.StateTreeNode> -> @+second_maybe:Maybe<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/StateTree.StateTreeNode> -> CompareResult
Equal hashes prune; different hashes diff.
def compare_loaded_trees source · line 321 · raw
@+first_maybe:Maybe<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/StateTree.StateTreeNode> -> @+second_maybe:Maybe<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/StateTree.StateTreeNode> -> CompareResult
Diffs two loaded trees with hash pruning.
def compare_commits source · line 325 · raw
@+first_identifier:String -> @+second_identifier:String -> 0xf481b310e24036f2ebffda42e94b3b4c/src/Store.Op<&2, CompareResult>
Shell: loads both trees and diffs them.
Unsafe
unsafe merge_order source · line 169 · raw
@ordering:Cmp -> @first_head:0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry -> @first_tail:List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry> -> @second_head:0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry -> @second_tail:List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry> -> List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry>
Merges one step by key order; both sides kept on ties (stable). @unsafe: calls merge_by_key below (branch-dependent recursion needs the forward reference); terminates in practice (one side always shrinks).
unsafe merge_by_key source · line 188 · raw
@first_sorted:List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry> -> @second_sorted:List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry> -> List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry>
Linear merge of two sorted lists by entry key. @unsafe: the greater-side branch recurses on a reconstructed list, which the termination checker cannot see through; one side always shrinks.
unsafe sort_split_halves source · line 202 · raw
@split_pair:Pair(List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry>, List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry>) -> @+remaining_fuel:Nat -> List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry>
Merges the sorted halves of one split pair. @unsafe: calls sort_fuel below (split halves are computed, not structural).
unsafe decide_linear_order source · line 229 · raw
@ordering:Cmp -> @+first_head:0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry -> @first_tail:List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry> -> @+second_head:0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry -> @second_tail:List<&2, 0xf481b310e24036f2ebffda42e94b3b4c/src/Reading.ChainEntry> -> CompareResult
Decides one linear-diff step by key order. @unsafe: calls merge_sorted_diff below (branch-dependent recursion needs the forward reference); one side always shrinks.