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

  /// - Returns: The removed element, if any.
  @discardableResult
  public mutating func removeValue(_ v: Value, forKey key: Key) -> Value? {
    return self.dictionary[key, default: []].remove(v)
  }


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