-
Notifications
You must be signed in to change notification settings - Fork 31
tail-recursive keys and values #132
base: master
Are you sure you want to change the base?
tail-recursive keys and values #132
Conversation
Rewrite `keys` and `values` to use the stack-safe `toAscUnfoldable` functions.
Note that this has a knock-on effect of speeding up some conversions of |
This looks great, but instead of exposing new functions I think I would rather just generalise the existing Does the behaviour of the current |
Also I would like to set a convention of avoiding use of |
This all sounds very reasonable to me. I'll replace the Regarding behavior/ordering: I believe the old behavior also had results in order of ascending key. From reading the code, it looks like the old behavior is identical to the new, it just used a BFS rather than a DFS approach and incurred a huge penalty on list concatenation. Please do have a look yourself to confirm this for me. |
92d80d4
to
dd04c36
Compare
My inclination is to say that Travis is lying and needs to be kicked :) |
Actually I am wondering here if it makes sense to expose both ascending-order and non-ascending order |
Refactor toAscUnfoldable, keys, and values functions to use toAscUnfoldableWith
I've now cleaned this up with some refactoring and added appropriate tests. @hdgarrood I think this is ready for review. Because it doesn't change ordering, I believe it's non-breaking. I'd like to get this merged in, if possible, before proceeding to some of the breaking changes/refactors that we've discussed in other issues. |
Whoops, actually this is breaking due to the generalization of the signatures on |
This PR exposes the functions
toAscUnfoldableKeys
andtoAscUnfoldableValues
, and rewrites thekeys
andvalues
functions to use them. They are stack-safe, drastically faster, and guarantee ascending order according to the keys'Ord
instance.Benchmarks are included. To compare to the implementations on
master
, check out this branch: https://github.com/matthewleon/purescript-maps/tree/bench-keys-valuesHighlight:
keys
andvalues
for aMap
of 1000000 pairs reduced from 3.80 seconds (!) to 712.57 ms.