X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.scl.runtime%2Fscl%2FMMap.scl;h=0f050ca7695d724b3f938a75c8fd71c2837aa2b6;hb=d9856d2391ee17f815a43dad74d9dc6318a1878c;hp=18e5866c080c05d35a6598c16e5382b63baa1a3f;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.scl.runtime/scl/MMap.scl b/bundles/org.simantics.scl.runtime/scl/MMap.scl index 18e5866c0..0f050ca76 100644 --- a/bundles/org.simantics.scl.runtime/scl/MMap.scl +++ b/bundles/org.simantics.scl.runtime/scl/MMap.scl @@ -35,6 +35,15 @@ importJava "java.util.Map" where remove :: T a b -> a -> (Maybe b) clear :: T a b -> () +@inline +getOrCreate :: T a b -> (a -> b) -> a -> b +getOrCreate m f k = match get m k with + Just v -> v + Nothing -> do + v = f k + put m k v + v + @inline iter :: (a -> b -> ()) -> T a b -> () iter f m = MSet.iter (\entry -> f (keyOf entry) (valueOf entry)) (entrySet m) @@ -53,6 +62,9 @@ importJava "gnu.trove.map.hash.THashMap" where @JavaName "" createC :: Integer -> T a b + @JavaName "" + clone :: T a b -> T a b + fromEntryList :: [(a,b)] -> T a b fromEntryList l = do result = createC (Prelude.length l)