]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.runtime/scl/MMultiMap.scl
Fixed multiple issues causing dangling references to discarded queries
[simantics/platform.git] / bundles / org.simantics.scl.runtime / scl / MMultiMap.scl
1 import "Prelude" as Prelude
2 import "MMap" as MMap
3 import "MList" as MList
4
5 type T a b = MMap.T a (MList.T b)
6
7 add :: MMap.T a (MList.T b) -> a -> b -> <Proc> ()
8 add m k v = match MMap.get m k with
9     Just l -> MList.add l v
10     Nothing -> Prelude.ignore (MMap.put m k (MList.singleton v))
11
12 get :: MMap.T a (MList.T b) -> a -> <Proc> [b]
13 get m k = match MMap.get m k with
14     Just l -> MList.freeze l
15     Nothing -> []
16
17 indexBy :: (v -> <e> k) -> [v] -> <Proc,e> MMap.T k (MList.T v)
18 indexBy f l = do
19     result = MMap.createC (Prelude.length l)
20     Prelude.iter (\v -> add result (f v) v) l
21     result