diff options
author | Vladimir Azarov <avm@intermediate-node.net> | 2025-06-04 20:45:08 +0200 |
---|---|---|
committer | Vladimir Azarov <avm@intermediate-node.net> | 2025-06-04 20:45:08 +0200 |
commit | 9ccb3fce8e390f09fa5b812a77f7a65c10c5e4b1 (patch) | |
tree | bdbbce79c18fdb2e68592ed828f43da0b03ecf8f /tree.sml | |
parent | 546a5861526192a908f2aa2bfc3cfe4f3f3baf43 (diff) |
Registration of declarations
Diffstat (limited to 'tree.sml')
-rw-r--r-- | tree.sml | 38 |
1 files changed, 19 insertions, 19 deletions
@@ -82,28 +82,28 @@ structure Tree: TREE = struct assemble' n buf end - fun lookup' _ _ Empty _ _ g = (g, NONE) - | lookup' buf cmp (Node (k', v', left, right)) k f g = - case cmp k k' of - LESS => lookup' (Left (k', v', right) :: buf) cmp left k f g - | GREATER => lookup' (Right (k', v', left) :: buf) cmp right k f g - | EQUAL => - let - val (newV, result) = f v' - in - case newV of - NONE => (result, NONE) - | SOME v => (result, SOME (assemble (Node (k', v, left, right)) buf)) - end - - fun lookup2 cmp t k (f, g) = + fun lookup' _ _ Empty k f = let - val (result, newTree) = lookup' [] cmp t k f g + val (res, newV) = f NONE in - (result, case newTree of - NONE => t - | SOME t => t) + case newV of + NONE => (res, Empty) + | SOME v => (res, Node (k, v, Empty, Empty)) end + | lookup' buf cmp (T as Node (k', v', left, right)) k f = + case cmp k k' of + LESS => lookup' (Left (k', v', right) :: buf) cmp left k f + | GREATER => lookup' (Right (k', v', left) :: buf) cmp right k f + | EQUAL => + let + val (res, newV) = f $ SOME v' + in + case newV of + NONE => (res, T) + | SOME v => (res, assemble (Node (k', v, left, right)) buf) + end + + fun lookup2 cmp t k f = lookup' [] cmp t k f fun print t key2str value2str = let |