implement 'exists' function on bro-tree as well, and benchmark it compared to string-set
This commit is contained in:
@@ -54,4 +54,14 @@ struct
|
||||
|
||||
fun insert (str, tree) =
|
||||
insRoot (ins (str, tree))
|
||||
|
||||
fun exists (str, tree) =
|
||||
case tree of
|
||||
N0 => false
|
||||
| N1 t => exists (str, t)
|
||||
| N2 (l, k, r) =>
|
||||
if str < k then exists (str, l)
|
||||
else if str > k then exists (str, r)
|
||||
else true
|
||||
| _ => raise Match
|
||||
end
|
||||
|
||||
BIN
bench/build-exists-bro-tree
Executable file
BIN
bench/build-exists-bro-tree
Executable file
Binary file not shown.
10
bench/build-exists-bro-tree.mlb
Normal file
10
bench/build-exists-bro-tree.mlb
Normal file
@@ -0,0 +1,10 @@
|
||||
$(SML_LIB)/basis/basis.mlb
|
||||
|
||||
ann
|
||||
"allowVectorExps true"
|
||||
in
|
||||
words.sml
|
||||
end
|
||||
|
||||
bro-tree.sml
|
||||
build-exists-bro-tree.sml
|
||||
32
bench/build-exists-bro-tree.sml
Normal file
32
bench/build-exists-bro-tree.sml
Normal file
@@ -0,0 +1,32 @@
|
||||
structure BuildExistsBroTree =
|
||||
struct
|
||||
fun helpExists (pos, tree, acc) =
|
||||
if pos = Vector.length WordsList.words then
|
||||
acc
|
||||
else
|
||||
let
|
||||
val word = Vector.sub (WordsList.words, pos)
|
||||
val newAcc = BroTree.exists (word, tree)
|
||||
val acc = newAcc orelse acc
|
||||
in
|
||||
helpExists (pos + 1, tree, acc)
|
||||
end
|
||||
|
||||
fun exists (tree) = helpExists (0, tree, true)
|
||||
|
||||
fun main () =
|
||||
let
|
||||
val endTree = Vector.foldl BroTree.insert BroTree.empty WordsList.words
|
||||
|
||||
val startTime = Time.now ()
|
||||
val wordsExist = exists endTree
|
||||
val finishTime = Time.now ()
|
||||
|
||||
val searchDuration = Time.- (finishTime, startTime)
|
||||
val searchDuration = Time.toString searchDuration ^ "\n"
|
||||
in
|
||||
print searchDuration
|
||||
end
|
||||
end
|
||||
|
||||
val _ = BuildExistsBroTree.main ()
|
||||
BIN
bench/build-exists-string-set
Executable file
BIN
bench/build-exists-string-set
Executable file
Binary file not shown.
10
bench/build-exists-string-set.mlb
Normal file
10
bench/build-exists-string-set.mlb
Normal file
@@ -0,0 +1,10 @@
|
||||
$(SML_LIB)/basis/basis.mlb
|
||||
|
||||
ann
|
||||
"allowVectorExps true"
|
||||
in
|
||||
words.sml
|
||||
end
|
||||
|
||||
../src/string-set.sml
|
||||
build-exists-string-set.sml
|
||||
33
bench/build-exists-string-set.sml
Normal file
33
bench/build-exists-string-set.sml
Normal file
@@ -0,0 +1,33 @@
|
||||
structure BuildExistsStringSet =
|
||||
struct
|
||||
fun helpExists (pos, trie, acc) =
|
||||
if pos = Vector.length WordsList.words then
|
||||
acc
|
||||
else
|
||||
let
|
||||
val word = Vector.sub (WordsList.words, pos)
|
||||
val newAcc = StringSet.exists (word, trie)
|
||||
val acc = newAcc orelse acc
|
||||
in
|
||||
helpExists (pos + 1, trie, acc)
|
||||
end
|
||||
|
||||
fun exists trie = helpExists (0, trie, true)
|
||||
|
||||
fun main () =
|
||||
let
|
||||
val endTrie =
|
||||
Vector.foldl StringSet.insert StringSet.empty WordsList.words
|
||||
|
||||
val startTime = Time.now ()
|
||||
val wordsExist = exists endTrie
|
||||
val finishTime = Time.now ()
|
||||
|
||||
val searchDuration = Time.- (finishTime, startTime)
|
||||
val searchDuration = Time.toString searchDuration ^ "\n"
|
||||
in
|
||||
print searchDuration
|
||||
end
|
||||
end
|
||||
|
||||
val _ = BuildExistsStringSet.main ()
|
||||
Reference in New Issue
Block a user