add getPrefixList to bro-tree (just folds over the tree in O(n) time, which is the best we can do for that data structure). Will add a benchmark comparison of this.

This commit is contained in:
2024-09-11 11:25:33 +01:00
parent af504350c7
commit db8fa8ae80
2 changed files with 50 additions and 0 deletions

View File

@@ -64,4 +64,24 @@ struct
else if str > k then exists (str, r)
else true
| _ => raise Match
fun foldr (f, acc, tree: bro) =
case tree of
N0 => acc
| N1 t => foldr (f, acc, t)
| N2 (l, k, r) =>
let
val acc = foldr (f, acc, r)
val acc = f (k, acc)
in
foldr (f, acc, l)
end
| _ => raise Match
fun getPrefixList (prefix, tree) =
foldr
( (fn (k, acc) => if String.isSubstring prefix k then k :: acc else acc)
, []
, tree
)
end