Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix quadratic dict:append/3 behaviour and use more idiomatic Erlang. #14

Merged
merged 2 commits into from Feb 25, 2015

Conversation

pichi
Copy link
Contributor

@pichi pichi commented Feb 24, 2015

dict:append/3 appends value at the end of the list which has quadratic behaviour. As stated in documentation:

For example append/3 could be defined as:

append(Key, Val, D) ->
    update(Key, fun (Old) -> Old ++ [Val] end, [Val], D).

The solution is to prepend value in front of list using dict:update/4.

This version is about 24 times faster than using dict:append/3 for given data on mine computer.

andreaferretti added a commit that referenced this pull request Feb 25, 2015
Fix quadratic dict:append/3 behaviour and use more idiomatic Erlang.
@andreaferretti andreaferretti merged commit 2887a92 into andreaferretti:master Feb 25, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants