DanielStutzbach / blist

A list-like type with better asymptotic performance and similar performance on small lists
Other
310 stars 36 forks source link

sortedlist should support an extend() operation #19

Closed fmark closed 14 years ago

fmark commented 14 years ago

As far as I can tell, there is no way to concatenate two sortedlist's. Neither the list style extend() nor the set style union() are present.

DanielStutzbach commented 14 years ago

Currently you can concatenate them using | or |=, which sortedlist inherits from the MutableSet abstract base class. I admit that's not very intuitive.

I worry that .extend() may sound like it will add things on at the end (when in fact each item will be inserted in the correct spot), and .union() may sound like duplicates will not be added (but they will be). How do you feel?

DanielStutzbach commented 14 years ago

By the way, I should be able to address the issues you've been raising and push out a new version sometime within the next week at the latest.

fmark commented 14 years ago

Yet again, I didn't find the |= operator. Maybe all that is need is some better documentation.

I agree about the implied semantics of "union()" and "extend()". If you do add it as function, perhaps a name like "merge()" or "combine()" might be appropriate.

DanielStutzbach commented 14 years ago

Yes, I've been putting off documentation for much too long. I'll get on that (opened as Issue #21). I'll also pour over the methods for list and set and make sure sortedlist has all the methods one might expect it to (Issue #20).

fmark commented 14 years ago

Awesome :) Thanks for the great module by the way!

mikegraham commented 14 years ago

Other options for a name include "update" and "add_all". "add_all" is probably the clearest. "update" is the name used by sortedlist's third cousin collections.Counter (2.7+).

DanielStutzbach commented 14 years ago

"update" is also used by dict and set, but the handling of duplicate items is quite different from sortedlist's. "add_all" is a good suggestion. I'm leaning toward that.

mikegraham commented 14 years ago

Right, I appealed to Counter because it is very similar to sortedlist in that they are both sort of bags. I wonder to an extent if PriorityDeque or SortedBag wouldn't have been more telling—if not less obvious—names for sortedlist. sortedlist does implement the Sequence API, though I do sort of wonder why; has this been useful?

DanielStutzbach commented 14 years ago

Good pointer about Counter. I couldn't remember if it's update method added or replaced, but I see now that it adds. In that case, I'm leaning toward "update". ;-)

DanielStutzbach commented 14 years ago

Oh, and to answer your question: yes, the Sequence API has been useful (to me, at any rate). I rely pretty heavily on the ability to take an arbitrary slice.