Re: Keeping a dynamic sorted range

2014-11-10 Thread bearophile via Digitalmars-d
Andrei Alexandrescu: One possibility is a function sortedChain that takes two or more sorted ranges and returns a lazy sorted range. -- Andrei Perhaps you are answering another thread and another problem. In this problem there is only one range. Bye, bearophile

Re: Keeping a dynamic sorted range

2014-11-10 Thread Vladimir Panteleev via Digitalmars-d
On Monday, 10 November 2014 at 02:19:33 UTC, Andrei Alexandrescu wrote: One possibility is a function sortedChain that takes two or more sorted ranges and returns a lazy sorted range. -- Andrei setUnion? http://dlang.org/phobos/std_algorithm.html#.setUnion

Re: Keeping a dynamic sorted range

2014-11-10 Thread Andrei Alexandrescu via Digitalmars-d
On 11/10/14 5:06 AM, Vladimir Panteleev wrote: On Monday, 10 November 2014 at 02:19:33 UTC, Andrei Alexandrescu wrote: One possibility is a function sortedChain that takes two or more sorted ranges and returns a lazy sorted range. -- Andrei setUnion?

Re: Keeping a dynamic sorted range

2014-11-10 Thread bearophile via Digitalmars-d
Andrei Alexandrescu: http://dlang.org/phobos/std_algorithm.html#.setUnion That's right! -- Andrei Still, this is very far from what I asked for... Bye, bearophile

Re: Keeping a dynamic sorted range

2014-11-10 Thread Sean Kelly via Digitalmars-d
It doesn't really address your question, but if you're mostly inserting you may want to store it as a heap and sort before lookup.

Re: Keeping a dynamic sorted range

2014-11-10 Thread Sean Kelly via Digitalmars-d
To address your question a bit more fully, it seems like this is something the range proposal for C++ is better suited for. Then appending would just be a special case of inserting at a specific position. I've got to say, if I had the time I'd implement the C++ ranges in D. They seem more

Re: Keeping a dynamic sorted range

2014-11-10 Thread Andrei Alexandrescu via Digitalmars-d
On 11/10/14 7:42 AM, Sean Kelly wrote: To address your question a bit more fully, it seems like this is something the range proposal for C++ is better suited for. Then appending would just be a special case of inserting at a specific position. I've got to say, if I had the time I'd implement the

Re: Keeping a dynamic sorted range

2014-11-10 Thread Sean Kelly via Digitalmars-d
On Monday, 10 November 2014 at 19:59:02 UTC, Andrei Alexandrescu wrote: On 11/10/14 7:42 AM, Sean Kelly wrote: To address your question a bit more fully, it seems like this is something the range proposal for C++ is better suited for. Then appending would just be a special case of inserting at

Re: Keeping a dynamic sorted range

2014-11-09 Thread Andrei Alexandrescu via Digitalmars-d
On 11/7/14 7:54 AM, bearophile wrote: Max Klyga: Ranges are not container. They are meant for traversing. If you want a sorted range - use an underlying container that preserves ordering (trees, heaps) Let's asssume that the underlying container is a sorted built-in dynamic array (that has

Re: Keeping a dynamic sorted range

2014-11-08 Thread bearophile via Digitalmars-d
Jakob Ovrum: Of course, positional container primitives like `insertFront` and `insertBack` will not be supported. Sometimes (or often) insertBack (or better the ~= operator) is what I want, because I add items larger than ones already present. insertBack has to verify the array is empty,

Keeping a dynamic sorted range

2014-11-07 Thread bearophile via Digitalmars-d
(This is a partial repost from a recent D.learn thread.) In Phobos we have SortedRange and assumeSorted, but I do find them not very good for a common enough use case. The use case is to keep a sorted array, keep adding items to it (adding larger and larger items at the end. Or sometimes

Re: Keeping a dynamic sorted range

2014-11-07 Thread Max Klyga via Digitalmars-d
On 2014-11-07 14:11:30 +, bearophile said: (This is a partial repost from a recent D.learn thread.) In Phobos we have SortedRange and assumeSorted, but I do find them not very good for a common enough use case. The use case is to keep a sorted array, keep adding items to it (adding

Re: Keeping a dynamic sorted range

2014-11-07 Thread bearophile via Digitalmars-d
Max Klyga: Ranges are not container. They are meant for traversing. If you want a sorted range - use an underlying container that preserves ordering (trees, heaps) Let's asssume that the underlying container is a sorted built-in dynamic array (that has more locality than a tree and allows

Re: Keeping a dynamic sorted range

2014-11-07 Thread bearophile via Digitalmars-d
Let's asssume that the underlying container is a sorted built-in dynamic array (that has more locality than a tree and allows very fast binary searches, unlike a heap). An array, a sorted array, is a simple data structure that often wins in terms of memory, simplicity, and efficiency.

Re: Keeping a dynamic sorted range

2014-11-07 Thread Ali Çehreli via Digitalmars-d
On 11/07/2014 06:11 AM, bearophile wrote: (This is a partial repost from a recent D.learn thread.) In Phobos we have SortedRange and assumeSorted, but I do find them not very good for a common enough use case. The use case is to keep a sorted array, keep adding items to it (adding larger and

Re: Keeping a dynamic sorted range

2014-11-07 Thread bearophile via Digitalmars-d
Ali Çehreli: If an array is sorted every time an element is added, Items are most times added at the end, and they respect the sortness of the whole array. The array never gets sorted. On the other hand, array wins if the insertions are batched and Insertions are not batched, and they

Re: Keeping a dynamic sorted range

2014-11-07 Thread Jakob Ovrum via Digitalmars-d
On Friday, 7 November 2014 at 14:11:32 UTC, bearophile wrote: (This is a partial repost from a recent D.learn thread.) In Phobos we have SortedRange and assumeSorted, but I do find them not very good for a common enough use case. The use case is to keep a sorted array, keep adding items to