-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1.fc
31 lines (25 loc) · 849 Bytes
/
1.fc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
{-
TASK 1 - Find branch of the cell tree
Write the method that will find a branch of the tree by comparing its
hash with the hash received in the first parameter. When the algorithm finds
the subtree (branch) whose hash equals the received hash, the root cell of
this branch should be returned. Return empty cell if the branch is not found.
-}
forall X -> int is_null(X x) asm "ISNULL";
() recv_internal() {
}
;; testable
(cell) find_branch_by_hash(int hash, cell tree) method_id {
tuple lst = cons(tree, null());
while (~ is_null(lst)) {
cell node = lst~list_next();
if (cell_hash(node) == hash) {
return node;
}
slice s = node.begin_parse();
while (~ slice_refs_empty?(s)) {
lst = cons(s~load_ref(), lst);
}
}
return begin_cell().end_cell();
}