Re: custom sorting of lists ?

2018-10-22 Thread Steven Schveighoffer via Digitalmars-d-learn
On 10/19/18 3:58 PM, Carl Sturtivant wrote: On Friday, 19 October 2018 at 17:53:58 UTC, Stanislav Blinov wrote: On Friday, 19 October 2018 at 17:40:59 UTC, Carl Sturtivant wrote: If we imagine an Ordered Range being a finite Range of some kind with the additional property that its values are

Re: custom sorting of lists ?

2018-10-19 Thread Carl Sturtivant via Digitalmars-d-learn
On Friday, 19 October 2018 at 17:53:58 UTC, Stanislav Blinov wrote: On Friday, 19 October 2018 at 17:40:59 UTC, Carl Sturtivant wrote: If we imagine an Ordered Range being a finite Range of some kind with the additional property that its values are ordered (--- exact definition needed

Re: custom sorting of lists ?

2018-10-19 Thread Stanislav Blinov via Digitalmars-d-learn
On Friday, 19 October 2018 at 17:40:59 UTC, Carl Sturtivant wrote: If we imagine an Ordered Range being a finite Range of some kind with the additional property that its values are ordered (--- exact definition needed ---)... There's already a SortedRange:

Re: custom sorting of lists ?

2018-10-19 Thread Carl Sturtivant via Digitalmars-d-learn
On Wednesday, 17 October 2018 at 19:02:00 UTC, Steven Schveighoffer wrote: On 10/17/18 2:03 PM, Carl Sturtivant wrote: On Monday, 15 October 2018 at 13:39:59 UTC, Steven Schveighoffer wrote: But that's just the thing -- merge sort *does* depend on the container type. It requires the ability

Re: custom sorting of lists ?

2018-10-17 Thread Steven Schveighoffer via Digitalmars-d-learn
On 10/17/18 2:03 PM, Carl Sturtivant wrote: On Monday, 15 October 2018 at 13:39:59 UTC, Steven Schveighoffer wrote: But that's just the thing -- merge sort *does* depend on the container type. It requires the ability to rearrange the elements structurally, since you merge the sets of items

Re: custom sorting of lists ?

2018-10-17 Thread Carl Sturtivant via Digitalmars-d-learn
On Monday, 15 October 2018 at 13:39:59 UTC, Steven Schveighoffer wrote: But that's just the thing -- merge sort *does* depend on the container type. It requires the ability to rearrange the elements structurally, since you merge the sets of items together. This requires making another list

Re: custom sorting of lists ?

2018-10-15 Thread Steven Schveighoffer via Digitalmars-d-learn
On 10/13/18 9:31 PM, Jonathan M Davis wrote: On Saturday, October 13, 2018 6:52:05 PM MDT Steven Schveighoffer via Digitalmars-d-learn wrote: You can't quick-sort a list. You can merge sort it, and it's O(nlgn). I'll work on getting a sort routine into Phobos for it, but I don't know what the

Re: custom sorting of lists ?

2018-10-14 Thread Boris-Barboris via Digitalmars-d-learn
On Sunday, 14 October 2018 at 01:31:26 UTC, Jonathan M Davis wrote: Unless there's something about the implementation that's tied to the list itself, I would think that it would make more sense to make it a generic algorithm, then it will work with any non-random-access range, and it avoids

Re: custom sorting of lists ?

2018-10-14 Thread Codifies via Digitalmars-d-learn
On Sunday, 14 October 2018 at 01:31:26 UTC, Jonathan M Davis wrote: Unless there's something about the implementation that's tied to the list itself, I would think that it would make more sense to make it a generic algorithm, then it will work with any non-random-access range, and it avoids

Re: custom sorting of lists ?

2018-10-13 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, October 13, 2018 6:52:05 PM MDT Steven Schveighoffer via Digitalmars-d-learn wrote: > You can't quick-sort a list. You can merge sort it, and it's O(nlgn). > > I'll work on getting a sort routine into Phobos for it, but I don't know > what the appropriate location for it is, as a

Re: custom sorting of lists ?

2018-10-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On 10/13/18 3:48 AM, Jacob Carlborg wrote: On 2018-10-12 21:40, Codifies wrote: a while ago I wrote a doubly linked list (in C), which has a compare callback to allow custom sorting for example int cmpNodes(cnode_t* n1, cnode_t* n2) {    mapNode_t* rn1 = (mapNode_t*)(n1->data);    mapNode_t*

Re: custom sorting of lists ?

2018-10-13 Thread Codifies via Digitalmars-d-learn
On Saturday, 13 October 2018 at 07:48:04 UTC, Jacob Carlborg wrote: On 2018-10-12 21:40, Codifies wrote: a while ago I wrote a doubly linked list (in C), which has a compare callback to allow custom sorting for example int cmpNodes(cnode_t* n1, cnode_t* n2) {   mapNode_t* rn1 =

Re: custom sorting of lists ?

2018-10-13 Thread Jacob Carlborg via Digitalmars-d-learn
On 2018-10-12 21:40, Codifies wrote: a while ago I wrote a doubly linked list (in C), which has a compare callback to allow custom sorting for example int cmpNodes(cnode_t* n1, cnode_t* n2) {   mapNode_t* rn1 = (mapNode_t*)(n1->data);   mapNode_t* rn2 = (mapNode_t*)(n2->data);   if (rn1->G

Re: custom sorting of lists ?

2018-10-12 Thread Steven Schveighoffer via Digitalmars-d-learn
On 10/12/18 4:59 PM, Codifies wrote: On Friday, 12 October 2018 at 20:29:27 UTC, Steven Schveighoffer wrote: On 10/12/18 3:40 PM, Codifies wrote: [...] Unfortunately, I can't find a way to sort a doubly linked list in phobos, so comparisons are somewhat moot. However, if there *were* a

Re: custom sorting of lists ?

2018-10-12 Thread Codifies via Digitalmars-d-learn
On Friday, 12 October 2018 at 20:29:27 UTC, Steven Schveighoffer wrote: On 10/12/18 3:40 PM, Codifies wrote: [...] Unfortunately, I can't find a way to sort a doubly linked list in phobos, so comparisons are somewhat moot. However, if there *were* a sorting routine, generally the

Re: custom sorting of lists ?

2018-10-12 Thread Steven Schveighoffer via Digitalmars-d-learn
On 10/12/18 3:40 PM, Codifies wrote: a while ago I wrote a doubly linked list (in C), which has a compare callback to allow custom sorting for example int cmpNodes(cnode_t* n1, cnode_t* n2) {   mapNode_t* rn1 = (mapNode_t*)(n1->data);   mapNode_t* rn2 = (mapNode_t*)(n2->data);   if (rn1->G

custom sorting of lists ?

2018-10-12 Thread Codifies via Digitalmars-d-learn
a while ago I wrote a doubly linked list (in C), which has a compare callback to allow custom sorting for example int cmpNodes(cnode_t* n1, cnode_t* n2) { mapNode_t* rn1 = (mapNode_t*)(n1->data); mapNode_t* rn2 = (mapNode_t*)(n2->data); if (rn1->G + rn1->H > rn2->G + rn2->H) return 1;