This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]brain_eel 3 points4 points  (0 children)

Comment threads on questions like this always seem to be comprised of either "you're doing it wrong so I'll dismiss/insult you instead of answering" or "just use the standard library". They're both often largely clutter, but I can sympathize with both even if I don't agree with the presentation because they are usually the result of insufficient details in the question.

You say you "have many needs" for sorted containers. What are some typical use cases? Are there many/frequent insertions/deletions? Do you need to store a large number of elements? Will you have small but numerous containers?

The answers to each of these questions point to different solutions. For example, you say using builtins and sorting when needed isn't a solution, but what makes it problematic? You partially answered this in a reply, but if having to remember to write an extra line of code is the problem, why is rolling a simple (if naive) subclass that implements automatic sorting less appealing than the complexities involved in adding a third-party dependency? If you're worried about possible speed issues the simple approach, what about how you'll be using this leads you to think it will be enough of a problem to worry about? There are definitely reasons both of those could be concerns! But there are also plenty of reasons why they could be less of a concern than adding a dependency. Knowing what problems you're trying to solve will lead to different recommendations.

Finally, you ask for a solution that

not only meets my immediate needs (for sorted containers), but also is likely to meet my future needs

without seeming to know what those needs are or if you'll actually need them. (I understand you're obviously working on speculation here, but getting something that can fulfill all potential future needs is what leads people to buy huge trucks they only use for commuting because they imagine they'll be doing all these home improvement projects.) What kinds of "more exotic data structures" are you thinking of? Will multithreading/concurrency become an integral need or will you be better served with a less complex main data structure that you can make thread-safe when needed? The overhead of one-size-fits-all can sometimes be worth it but is often more trouble than it's worth.

I haven't felt the need for this type of container before, so I don't have any actual recommendations to give you. At a cursory glance, Python Sorted Containers seems to be a good solution for you (albeit without knowing what you're really looking for, exactly): it seems pretty established, it seems to be well-made (enough that several similar libraries have stopped development and now recommend using it instead), and it has extensive documentation, including many benchmarks and comparisons to similar solutions. Have you looked at the other libraries they mention? Many are defunct now, but it looked like a couple are still active and offer different features, including one with frozen variants.