Commit 17d59940 authored by Steffen Michels's avatar Steffen Michels

add '<' & 'gLexOrd' instance for Data.Map

parent 9be2048e
Pipeline #8764 failed with stage
in 1 minute and 26 seconds
......@@ -11,6 +11,7 @@ from StdBool import not
from StdFunc import id
from Text.JSON import generic JSONEncode, generic JSONDecode, :: JSONNode
from Data.Generics.GenEq import generic gEq
from Data.Generics.GenLexOrd import generic gLexOrd, :: LexOrd
from Data.Monoid import class Monoid, class Semigroup
import qualified StdList as SL
from Data.List import foldr
......@@ -31,7 +32,8 @@ import StdClass
instance Monoid (Map k v) | < k
instance == (Map k v) | == k & == v
instance == (Map k v) | Eq k & Eq v
instance < (Map k v) | Ord k & Ord v
//Basic functions
......@@ -170,6 +172,7 @@ fromList :: !u:[v:(!a, !b)] -> Map a b | == a & < a, [u <= v]
derive JSONEncode Map
derive JSONDecode Map
derive gEq Map
derive gLexOrd Map
/**
* Check if a key exists in a Map.
......
......@@ -6,10 +6,10 @@ from StdBool import &&, ||
from StdFunc import id, flip, o, const
from StdTuple import snd
from StdMisc import abort, undef
import StdString
import StdString, StdTuple
from Data.Generics.GenEq import generic gEq
import qualified StdList as SL
import Data.Maybe, Text.JSON
import Data.Maybe, Text.JSON, Data.Generics.GenLexOrd
from Data.Set import :: Set
import qualified Data.Set as DS
import Data.Monoid, Data.Functor, Control.Applicative
......@@ -56,8 +56,6 @@ mapSize :: !(Map k a) -> Int
mapSize Tip = 0
mapSize (Bin sz _ _ _ _) = sz
:: LexOrd = LT | GT | EQ
//lexOrd :: !a !a -> LexOrd | < a
lexOrd x y :== if (x < y) LT (if (x > y) GT EQ)
......@@ -1891,11 +1889,11 @@ bin k x l r = Bin (mapSize l + mapSize r + 1) k x l r
// actually seems one of the faster methods to gLexOrd{|*|} two trees
// and it is certainly the simplest :-)
////////////////////////////////////////////////////////////////////
instance == (Map k a) | == k & == a where
instance == (Map k a) | Eq k & Eq a where
(==) t1 t2 = (mapSize t1 == mapSize t2) && (toAscList t1 == toAscList t2)
instance == (a, b) | == a & == b where
(==) (x1, y1) (x2, y2) = x1 == x2 && y1 == y2
instance < (Map k v) | Ord k & Ord v where
(<) t1 t2 = toAscList t1 < toAscList t2
////////////////////////////////////////////////////////////////////
// Functor
......@@ -2526,4 +2524,5 @@ gEq{|Map|} fk fv mx my = length mxl == length myl && and [fk kx ky && fv vx vy \
where
mxl = toList mx
myl = toList my
gLexOrd{|Map|} kLexOrd vLexOrd x y = gLexOrd{|* -> *|} (gLexOrd{|* -> * -> *|} kLexOrd vLexOrd) (toAscList x) (toAscList y)
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