 /// 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

  ///            other values for the given key. Else, returns `false.
  @discardableResult
  public mutating func insertValue(_ v: Value, forKey key: Key) -> Bool {
    return self.dictionary[key, default: []].insert(v).inserted
  }


  ///                this dictionary.
  /// - Returns: The set of keys associated with the given value.
  public func keysContainingValue(_ v: Value) -> Set<Key> {
    return self.reverseIndex[v, default: []]
  }

  /// Inserts the given value in the set of values associated with the given key.
