Skip to content

Commit 325693c

Browse files
committed
Refactor typer (2)
1 parent 4835802 commit 325693c

File tree

11 files changed

+1298
-235
lines changed

11 files changed

+1298
-235
lines changed

lib/DataTypes/Trie.fs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,20 @@ module Trie =
9999
| Some child -> getLongestMatch ks child
100100
| None -> {| value = trie.value; rest = k :: ks |}
101101

102+
let collectPath (ks: 'k list) (collector: 'k list -> 'v option -> 'a option) (trie: Trie<'k, 'v>) : 'a list =
103+
let rec go acc ks trie =
104+
let acc =
105+
match collector ks trie.value with
106+
| Some a -> a :: acc
107+
| None -> acc
108+
match ks with
109+
| [] -> List.rev acc
110+
| k :: ks ->
111+
match Map.tryFind k trie.children with
112+
| Some child -> go acc ks child
113+
| None -> List.rev acc
114+
go [] ks trie
115+
102116
let fold (f: 'state -> 'k list -> 'v -> 'state) (s: 'state) (t: Trie<'k, 'v>) =
103117
let rec go ksRev state t =
104118
let state =

lib/Extensions.fs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ module List =
6464
) ([], [])
6565
List.rev xs1, List.rev xs2
6666

67+
module Map =
68+
let addNoOverwrite k v m =
69+
m |> Map.change k (function None -> Some v | Some v -> Some v)
70+
6771
type MutableMap<'k, 'v> = Collections.Generic.Dictionary<'k, 'v>
6872
type MutableSet<'v> = Collections.Generic.HashSet<'v>
6973

lib/Parser.fs

Lines changed: 46 additions & 46 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)