From: Zooko O'Whielacronx Date: Mon, 12 Jan 2009 17:55:39 +0000 (-0700) Subject: util: dictutil: add DictOfSets.union(key, values) and DictOfSets.update(otherdictofsets) X-Git-Tag: allmydata-tahoe-1.3.0~207 X-Git-Url: https://git.rkrishnan.org/simplejson/frontends?a=commitdiff_plain;h=e449052a177ff3efc94f2ee0d8ce6f3ead7a83ec;p=tahoe-lafs%2Ftahoe-lafs.git util: dictutil: add DictOfSets.union(key, values) and DictOfSets.update(otherdictofsets) --- diff --git a/src/allmydata/util/dictutil.py b/src/allmydata/util/dictutil.py index 227d2479..11c0c743 100644 --- a/src/allmydata/util/dictutil.py +++ b/src/allmydata/util/dictutil.py @@ -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