     reduce(set1, {:cont, true}, fn member, acc ->
       case member?(set2, member) do
         true -> {:cont, acc}
-        _    -> {:halt, false}
+        _ -> {:halt, false}
       end
-    end) |> elem(1)
+    end)
+    |> elem(1)
   end
 
   def disjoint?(%HashSet{} = set1, %HashSet{} = set2) do
     reduce(set2, {:cont, true}, fn member, acc ->
       case member?(set1, member) do
         false -> {:cont, acc}
-        _     -> {:halt, false}
+        _ -> {:halt, false}
       end
-    end) |> elem(1)
+    end)
+    |> elem(1)
   end
 
   def member?(%HashSet{root: root}, term) do


  defp do_member?(node, term, hash) do
    index = key_mask(hash)
    case elem(node, index) do
      []          -> false
      [^term | _] -> true
      [_]         -> false
      [_ | n]     -> do_member?(n, term, key_shift(hash))
    end
  end

  defp do_put(node, term, hash) do
    index = key_mask(hash)
    case elem(node, index) do
      [] ->
        {put_elem(node, index, [term]), 1}
      [^term | _] ->
        {node, 0}
      [t] ->
        n = put_elem(@node_template, key_mask(key_shift(hash)), [term])
        {put_elem(node, index, [t | n]), 1}
      [t | n] ->
        {n, counter} = do_put(n, term, key_shift(hash))
        {put_elem(node, index, [t | n]), counter}

  @compile :inline_list_funcs
  @compile {:inline, key_hash: 1, key_mask: 1, key_shift: 1}

  @spec new :: Set.t()
  def new do
    %HashSet{}
  end

  def union(%HashSet{size: size1} = set1, %HashSet{size: size2} = set2) when size1 <= size2 do
    set_fold(set1, set2, fn v, acc -> put(acc, v) end)
  end

  def union(%HashSet{} = set1, %HashSet{} = set2) do
    set_fold(set2, set1, fn v, acc -> put(acc, v) end)
  end

  def intersection(%HashSet{} = set1, %HashSet{} = set2) do
    set_fold(set1, %HashSet{}, fn v, acc ->
      if member?(set2, v), do: put(acc, v), else: acc
    end)
  end

  def difference(%HashSet{} = set1, %HashSet{} = set2) do
    set_fold(set2, set1, fn v, acc -> delete(acc, v) end)
  end

  def to_list(set) do
    set_fold(set, [], &[&1 | &2]) |> :lists.reverse()
  end

  def equal?(%HashSet{size: size1} = set1, %HashSet{size: size2} = set2) do
    case size1 do
      ^size2 -> subset?(set1, set2)
      _ -> false
    end
  end

