     %{map_set | map: Map.drop(map1, Map.keys(map2))}
   end
 
-  defp filter_not_in([], _map2, acc), do: Map.new(acc)
-
-  defp filter_not_in([key | rest], map2, acc) do
-    case map2 do
-      %{^key => _} -> filter_not_in(rest, map2, acc)
-      _ -> filter_not_in(rest, map2, [{key, @dummy_value} | acc])
+  defp filter_not_in(:none, _map2, acc), do: Map.new(acc)
+
+  defp filter_not_in({key, _val, iter}, map2, acc) do
+    if :erlang.is_map_key(key, map2) do
+      filter_not_in(:maps.next(iter), map2, acc)
+    else
+      filter_not_in(:maps.next(iter), map2, [{key, @dummy_value} | acc])
     end
   end
 

  """
  @spec subset?(t, t) :: boolean
  def subset?(%MapSet{map: map1}, %MapSet{map: map2}) do
    if map_size(map1) <= map_size(map2) do
      map1
      |> Map.keys()
      |> map_subset?(map2)
    else
      false
    end
  end

  defp map_subset?([], _), do: true

  defp map_subset?([key | rest], map2) do
    match?(%{^key => _}, map2) and map_subset?(rest, map2)
  end

  @doc """

  @spec difference(t(val1), t(val2)) :: t(val1) when val1: value, val2: value
  def difference(map_set1, map_set2)

  # If the first set is less than twice the size of the second map, it is fastest
  # to re-accumulate elements in the first set that are not present in the second set.
  def difference(%MapSet{map: map1}, %MapSet{map: map2})
      when map_size(map1) < map_size(map2) * 2 do
    map =
      map1
      |> :maps.iterator()
      |> :maps.next()
      |> filter_not_in(map2, [])

    %MapSet{map: map}
