Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
uva
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Taddeüs Kroes
uva
Commits
e052f91d
Commit
e052f91d
authored
13 years ago
by
Taddeus Kroes
Browse files
Options
Downloads
Plain Diff
Merge branch 'master' of
ssh://vo20.nl/git/uva
parents
9aedb141
b629c379
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
funclang-taddeus/series4/ass9.ml
+8
-5
8 additions, 5 deletions
funclang-taddeus/series4/ass9.ml
with
8 additions
and
5 deletions
funclang-taddeus/series4/ass9.ml
+
8
−
5
View file @
e052f91d
...
...
@@ -15,17 +15,17 @@ let rec insert trie key value = match trie with
Empty
->
Node
(
key
,
value
,
[]
)
(* Root *)
|
Node
(
k
,
v
,
c
)
->
if
k
=
key
then
raise
(
Failure
"Inserted key already exists in trie"
)
else
if
not
(
starts_with
key
k
)
then
raise
(
Failure
"Inserted key does not
start
with
node key"
)
else
(* Key already exists, replace its value *
)
Node
(
k
,
value
,
c
)
else
if
start
s_
with
key
k
then
(* Key prefix matches, trye to insert in children *)
let
match_node
node
=
match
node
with
Empty
->
false
|
Node
(
k
,
v
,
c
)
->
starts_with
key
k
in
let
matches
=
map
match_node
c
in
if
fold_left
(
||
)
false
matches
then
(* Match in child node,
do not add new
child *)
(* Match in child node,
insert in matching
child *)
let
apply_match
(
matched
,
node
)
=
if
matched
then
insert
node
key
value
else
node
in
...
...
@@ -33,6 +33,9 @@ let rec insert trie key value = match trie with
else
(* No match in any child node, add new child *)
Node
(
k
,
v
,
c
@
[
Node
(
key
,
value
,
[]
)])
else
(* Key prefix does not match, key cannot be inserted *)
raise
(
Failure
"Inserted key does not start with node key"
)
(* Helper function, checks if a trie is not empty *)
let
non_empty
=
function
|
Empty
->
false
|
_
->
true
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment