Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
cduce
cduce
Commits
8b04fb93
Commit
8b04fb93
authored
Dec 16, 2014
by
Giuseppe Castagna
Browse files
deleted old version of red-black
parent
bd0debdd
Changes
1
Hide whitespace changes
Inline
Side-by-side
tests/poly/red-black-non-constructed.cd
deleted
100644 → 0
View file @
bd0debdd
type RBtree = Btree | Rtree
(* Black rooted RB tree: *)
type Btree = [] | <black elem='a>[ RBtree RBtree ]
(* Red rooted RB tree: *)
type Rtree = <red elem='a>[ Btree Btree ]
type Wrongtree = <red elem='a>( [ Rtree Btree ]
| [ Btree Rtree ])
type Unbalanced = <black elem='a>( [ Wrongtree RBtree ]
| [ RBtree Wrongtree ])
let balance ( Unbalanced -> Rtree ; 'b\Unbalanced -> 'b\Unbalanced )
| <black (z)>[ <red (y)>[ <red (x)>[ a b ] c ] d ]
| <black (z)>[ <red (x)>[ a <red (y)>[ b c ] ] d ]
| <black (x)>[ a <red (z)>[ <red (y)>[ b c ] d ] ]
| <black (x)>[ a <red (y)>[ b <red (z)>[ c d ] ] ] ->
<red (y)>[ <black (x)>[ a b ] <black (z)>[ c d ] ]
| x -> x
let insert (x : 'a) (t : Btree) : Btree =
let ins_aux ( [] -> Rtree;
Btree\[] -> RBtree\[];
Rtree -> Rtree|Wrongtree )
| [] -> <red elem=x>[ [] [] ]
| (<(color) elem=y>[ a b ]) & z ->
if x << y then balance <(color) elem=y>[ (ins_aux a) b ]
else if x >> y then balance <(color) elem=y>[ a (ins_aux b) ]
else z
in match ins_aux t with
| <_ (y)>[ a b ] -> <black (y)>[ a b ]
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment