8 # The hash containing non-unique mappings
9 # It can have a->b and a->c together
10 # Also, for every mapping it counts the number of times this mapping was set
12 class NonuniqueCountingHash < Hash
15 alias put_original []=
18 own = self.get_original(key)
19 hash = get_original(key)
21 put_original(key, hash = Hash.new)
23 if hash.has_key?(value)
31 # Number of all mappings (a->b and a->c counted as 2 mappings)
34 values.inject(0) do | rv, hash |
39 def cardinality(key1, key2)
41 hash = get_original(key1)
42 if hash.has_key?(key2)
53 find_all do | key, hash |
54 hash.find_all do | key1, counter |