   ///                this dictionary.
   /// - Returns: The set of keys associated with the given value.
   public func keysContainingValue(_ v: Value) -> Set<Key> {
-    return self.dictionary.reduce(into: Set<Key>()) { acc, next in
-      guard next.value.contains(v) else {
-        return
-      }
-      acc.insert(next.key)
-    }
+    return self.reverseIndex[v, default: []]
   }
 
   /// Inserts the given value in the set of values associated with the given key.

  ///
  /// - Parameter v: The value to remove.
  public mutating func removeOccurrences(of v: Value) {
    for k in self.dictionary.keys {
      self.dictionary[k]!.remove(v)
    }
  }
}

/// A collection that associates keys with one or more values.
@_spi(Testing) public struct Multidictionary<Key: Hashable, Value: Hashable>: Collection, Equatable {
  private var dictionary: Dictionary<Key, Set<Value>> = [:]

  /// Reverse index used to make value removal more efficient.
  private var reverseIndex: Dictionary<Value, Set<Key>> = [:]
  
  public typealias Element = (Key, Set<Value>)
  public typealias Index = Dictionary<Key, Set<Value>>.Index
