Commit fb7a40c2 authored by Hans-Peter Deifel's avatar Hans-Peter Deifel 🐢

SumBag: Implement membership tests

This is not strictly required by copar but allows for easier testing.
parent 58691da0
......@@ -7,9 +7,10 @@ module Data.SumBag
, sum
, insert
, delete
, elem
) where
import Prelude hiding (sum, min)
import Prelude hiding (sum, min, elem)
import qualified Data.List.NonEmpty as NE
type SumBag a = Tree a
......@@ -57,6 +58,13 @@ insert a (Node _ e left right)
| a > value e = balance1 e left (insert a right)
| otherwise = node (addOnce e) left right
elem :: (Ord a) => a -> SumBag a -> Bool
elem _ Leaf = False
elem a (Node _ e left right)
| a < value e = elem a left
| a > value e = elem a right
| otherwise = True
delete :: (Ord a, Monoid a) => a -> SumBag a -> SumBag a
delete _ Leaf = Leaf
delete a (Node _ e left right)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment