]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
util: dictutil: add DictOfSets.union(key, values) and DictOfSets.update(otherdictofsets)
authorZooko O'Whielacronx <zooko@zooko.com>
Mon, 12 Jan 2009 17:55:39 +0000 (10:55 -0700)
committerZooko O'Whielacronx <zooko@zooko.com>
Mon, 12 Jan 2009 17:55:39 +0000 (10:55 -0700)
src/allmydata/util/dictutil.py

index 227d2479c3e10fb167ac5682cb7eab9e4188866c..11c0c7438ab4d2d7de755571f7bcf038f5bb99cf 100644 (file)
@@ -40,6 +40,16 @@ class DictOfSets(dict):
         else:
             self[key] = set([value])
 
+    def union(self, key, values):
+        if key in self:
+            self[key].update(values)
+        else:
+            self[key] = set(values)
+
+    def update(self, otherdictofsets):
+        for key, value in otherdictofsets.iteritems():
+            self.union(key, value)
+
     def discard(self, key, value):
         if not key in self:
             return