Skip to content

Commit

Permalink
Rename "initial" argument to "default" in Dic and HashDict (elixir-la…
Browse files Browse the repository at this point in the history
…ng#10233)

To be consistent with recently introduced changes: elixir-lang#10228, elixir-lang#10223
  • Loading branch information
eksperimental committed Jul 27, 2020
1 parent 9cd30ce commit cebfb83
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions lib/elixir/lib/dict.ex
Expand Up @@ -155,13 +155,13 @@ defmodule Dict do
end

@deprecated message
def update(dict, key, initial, fun) do
def update(dict, key, default, fun) do
case fetch(dict, key) do
{:ok, value} ->
put(dict, key, fun.(value))

:error ->
put(dict, key, initial)
put(dict, key, default)
end
end

Expand Down Expand Up @@ -378,8 +378,8 @@ defmodule Dict do

@deprecated message
@spec update(t, key, value, (value -> value)) :: t
def update(dict, key, initial, fun) do
target(dict).update(dict, key, initial, fun)
def update(dict, key, default, fun) do
target(dict).update(dict, key, default, fun)
end

@deprecated message
Expand Down
12 changes: 6 additions & 6 deletions lib/elixir/lib/hash_dict.ex
Expand Up @@ -48,8 +48,8 @@ defmodule HashDict do
end

@deprecated message
def update(%HashDict{root: root, size: size}, key, initial, fun) when is_function(fun, 1) do
{root, counter} = do_update(root, key, fn -> initial end, fun, key_hash(key))
def update(%HashDict{root: root, size: size}, key, default, fun) when is_function(fun, 1) do
{root, counter} = do_update(root, key, fn -> default end, fun, key_hash(key))
%HashDict{root: root, size: size + counter}
end

Expand Down Expand Up @@ -135,25 +135,25 @@ defmodule HashDict do
end
end

defp do_update(node, key, initial, fun, hash) do
defp do_update(node, key, default, fun, hash) do
index = key_mask(hash)

case elem(node, index) do
[] ->
{put_elem(node, index, [key | initial.()]), 1}
{put_elem(node, index, [key | default.()]), 1}

[^key | value] ->
{put_elem(node, index, [key | fun.(value)]), 0}

[k | v] ->
n = put_elem(@node_template, key_mask(key_shift(hash)), [key | initial.()])
n = put_elem(@node_template, key_mask(key_shift(hash)), [key | default.()])
{put_elem(node, index, {k, v, n}), 1}

{^key, value, n} ->
{put_elem(node, index, {key, fun.(value), n}), 0}

{k, v, n} ->
{n, counter} = do_update(n, key, initial, fun, key_shift(hash))
{n, counter} = do_update(n, key, default, fun, key_shift(hash))
{put_elem(node, index, {k, v, n}), counter}
end
end
Expand Down

0 comments on commit cebfb83

Please sign in to comment.