summaryrefslogtreecommitdiff
path: root/src/multimap_fn.sml
diff options
context:
space:
mode:
Diffstat (limited to 'src/multimap_fn.sml')
-rw-r--r--src/multimap_fn.sml16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/multimap_fn.sml b/src/multimap_fn.sml
new file mode 100644
index 00000000..3dab68a5
--- /dev/null
+++ b/src/multimap_fn.sml
@@ -0,0 +1,16 @@
+functor MultimapFn (structure KeyMap : ORD_MAP structure ValSet : ORD_SET) = struct
+ type key = KeyMap.Key.ord_key
+ type item = ValSet.item
+ type itemSet = ValSet.set
+ type multimap = ValSet.set KeyMap.map
+ val empty : multimap = KeyMap.empty
+ fun insertSet (kToVs : multimap, k : key, vs : itemSet) : multimap =
+ KeyMap.unionWith ValSet.union (kToVs, KeyMap.singleton (k, vs))
+ fun insert (kToVs : multimap, k : key, v : item) : multimap =
+ insertSet (kToVs, k, ValSet.singleton v)
+ fun findSet (kToVs : multimap, k : key) =
+ case KeyMap.find (kToVs, k) of
+ SOME vs => vs
+ | NONE => ValSet.empty
+ val findList : multimap * key -> item list = ValSet.listItems o findSet
+end