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
bd0debdd
Commit
bd0debdd
authored
Dec 16, 2014
by
Giuseppe Castagna
Browse files
added few more operations
parent
e7f93568
Changes
1
Hide whitespace changes
Inline
Side-by-side
tests/poly/red-black.cd
View file @
bd0debdd
...
...
@@ -38,6 +38,7 @@ let balance ( Unbalanced('a) -> Rtree('a) ; 'b & RBtree('a) -> 'b & RBtree('a) )
| x -> x
;;
let balance ( Unbalanced('a) -> Rtree('a) ; 'b\Unbalanced(Any) -> 'b\Unbalanced(Any) )
| (<black (z)>[ <red (y)>[ <red (x)>[ a b ] c ] d ]
| <black (z)>[ <red (x)>[ a <red (y)>[ b c ] ] d ]
...
...
@@ -47,6 +48,7 @@ let balance ( Unbalanced('a) -> Rtree('a) ; 'b\Unbalanced(Any) -> 'b\Unbalanced(
| x -> x
;;
(*
type UTree = <black (Any)>[ <red (Any)>[ <red (Any)>[ Any Any ] Any ] Any ]
| <black (Any)>[ <red (Any)>[ Any <red (Any)>[ Any Any ] ] Any ]
| <black (Any)>[ Any <red (Any)>[ <red (Any)>[ Any Any ] Any ] ]
...
...
@@ -62,6 +64,11 @@ let balance ( Unbalanced('a) -> Rtree('a) ; 'b\UTree -> 'b\UTree )
<red (y)>[ <black (x)>[ a b ] <black (z)>[ c d ] ]
| x -> x
;;
*)
(* Here we start the definition of *)
(* standard operations for red-black trees *)
let insert (x : 'a) (t : Btree('a)) : Btree('a) =
let ins_aux ( [] -> Rtree('a);
...
...
@@ -75,3 +82,20 @@ let insert (x : 'a) (t : Btree('a)) : Btree('a) =
in match ins_aux t with
| <_ (y)>[ a b ] -> <black (y)>[ a b ]
let is_empty ( RBtree('a) -> Bool ) | [] -> `true | _ -> `false
let member (x : 'a) (t : RBtree('a)) : Bool =
match t with
| [] -> `false
| <_ elem=y>[ left right ] ->
(y = x) || ( member x (if x<<y then left else right) )
let singleton (x : 'a): Btree('a) = <black elem=x>[ [] [] ]
let cardinal ( RBtree('a) -> Int )
| [] -> 0
| <_ ..>[ l r ] -> cardinal l + cardinal r
\ 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