1 import "Prelude" as Prelude
2 import "JavaBuiltin" as Java
4 import "MList" as MList
5 import "Iterator" as Iterator
7 importJava "java.util.Map$Entry" where
11 keyOf :: Entry a b -> a
13 valueOf :: Entry a b -> b
15 importJava "java.util.Map" where
18 containsKey :: T a b -> a -> <Proc> Boolean
19 containsValue :: T a b -> b -> <Proc> Boolean
20 size :: T a b -> <Proc> Integer
21 isEmpty :: T a b -> <Proc> Boolean
22 entrySet :: T a b -> <Proc> MSet.T (Entry a b)
23 get :: T a b -> a -> <Proc> Maybe b
25 unsafeGet :: T a b -> a -> <Proc> b
27 // needs no <Proc>, because this is a view
28 keySet :: T a b -> MSet.T a
32 values_ :: T a b -> Iterator.Iterable b
34 put :: T a b -> a -> b -> <Proc> (Maybe b)
35 remove :: T a b -> a -> <Proc> (Maybe b)
36 clear :: T a b -> <Proc> ()
39 iter :: (a -> b -> <e> ()) -> T a b -> <e,Proc> ()
40 iter f m = MSet.iter (\entry -> f (keyOf entry) (valueOf entry)) (entrySet m)
43 iterB :: (a -> b -> <e> Boolean) -> T a b -> <e,Proc> Boolean
44 iterB f m = MSet.iterB (\entry -> f (keyOf entry) (valueOf entry)) (entrySet m)
47 fold :: (a -> b -> c -> <e> a) -> a -> T b c -> <Proc,e> a
48 fold f init m = MSet.fold (\cur entry -> f cur (keyOf entry) (valueOf entry)) init (entrySet m)
50 importJava "gnu.trove.map.hash.THashMap" where
52 create :: () -> <Proc> T a b
54 createC :: Integer -> <Proc> T a b
56 fromEntryList :: [(a,b)] -> <Proc> T a b
58 result = createC (Prelude.length l)
59 Prelude.iter (\(k,v) -> Prelude.ignore (put result k v)) l
62 putM :: (b -> b -> b) -> T a b -> a -> b -> <Proc> ()
63 putM merge m k v = match get m k with
64 Just v2 -> Prelude.ignore (put m k (merge v v2))
65 Nothing -> Prelude.ignore (put m k v)
68 map :: (b -> <e> c) -> T a b -> <Proc,e> T a c
70 result = createC (size m)
71 iter (\k v -> Prelude.ignore (put result k (f v))) m
74 keys :: T a b -> <Proc> [a]
75 keys m = MSet.toList (keySet m)
77 values :: T a b -> <Proc> [b]
79 result = MList.createC (size m)
80 Iterator.iter (MList.add result) (Iterator.iterator (values_ m))
83 entries :: T a b -> <Proc> [(a,b)]
85 result = MList.createC (size m)
86 iter (Prelude.curry (MList.add result)) m