Mercurial > hg > Members > Moririn
changeset 417:24c98ca207f4
add RedBlackTree.agda
author | mir3636 |
---|---|
date | Thu, 05 Oct 2017 17:52:06 +0900 |
parents | 6f873aad1b06 |
children | 3789144f972e |
files | src/parallel_execution/RedBlackTree.agda |
diffstat | 1 files changed, 30 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/parallel_execution/RedBlackTree.agda Thu Oct 05 17:52:06 2017 +0900 @@ -0,0 +1,30 @@ +module RedBlackTree where + +open import stack + +record Tree {a t : Set} (treeImpl : Set) : Set where + field + tree : treeImpl + put : treeImpl -> a -> (treeImpl -> t) -> t + get : treeImpl -> (treeImpl -> Maybe a -> t) -> t + +record RedBlackTree (a : Set) : Set where + field + top : Maybe (Element a) + stack : Stack +open RedBlackTree + +putRedBlackTree : {Data t : Set} -> RedBlackTree Data -> Data -> (Code : RedBlackTree Data -> t) -> t +putRedBlackTree stack datum next = next newtree + where + element = cons datum (top stack) + newtree = record {top = Just element} + +getRedBlackTree : {a t : Set} -> RedBlackTree a -> (Code : RedBlackTree a -> (Maybe a) -> t) -> t +getRedBlackTree tree cs with (top tree) +... | Nothing = cs tree Nothing +... | Just d = cs stack1 (Just data1) + where + data1 = datum d + stack1 = record { top = (next d) } +