Re: Iterate/sort associative array by value?

2019-04-10 Thread Robert M. Münch via Digitalmars-d-learn
On 2019-04-08 08:31:33 +, Dennis said: As Sebastian said, you can do `import std.experimental.all;` or from version 2.086 `import std;` to import the entire standard library. Well, that's more like a brute force approach. So it would be always best to use "import *" :-) I like

Re: Iterate/sort associative array by value?

2019-04-10 Thread Robert M. Münch via Digitalmars-d-learn
On 2019-04-08 08:29:24 +, Julian said: It does do this, so the question should be: why aren't its warnings more extensive? Ok, I had the impression that I saw such a message in the past but wasn't sure about it... -- Robert M. Münch http://www.saphirion.com smarter | better | faster

Re: Iterate/sort associative array by value?

2019-04-08 Thread Seb via Digitalmars-d-learn
On Monday, 8 April 2019 at 18:04:28 UTC, kdevel wrote: On Sunday, 7 April 2019 at 17:16:12 UTC, Seb wrote: --- ["a": 1].byPair.array.sort!((a, b) => a.value < a.value).release.each!writeln; --- What's the purpose of .release? The documentation in

Re: Iterate/sort associative array by value?

2019-04-08 Thread Dennis via Digitalmars-d-learn
On Monday, 8 April 2019 at 18:04:28 UTC, kdevel wrote: What's the purpose of .release? The documentation in https://dlang.org/phobos/std_range.html#.SortedRange.release is rather monosyllabic. The sort function returns a SortedRange, which is usually an array wrapper with the extra type

Re: Iterate/sort associative array by value?

2019-04-08 Thread Julian via Digitalmars-d-learn
On Monday, 8 April 2019 at 17:13:32 UTC, Seb wrote: On Monday, 8 April 2019 at 08:31:33 UTC, Dennis wrote: On Monday, 8 April 2019 at 07:53:23 UTC, Robert M. Münch wrote: Why does DMD not give a hint, that an import from the standard lib might be missing? I find these explicit import

Re: Iterate/sort associative array by value?

2019-04-08 Thread kdevel via Digitalmars-d-learn
On Sunday, 7 April 2019 at 17:16:12 UTC, Seb wrote: --- ["a": 1].byPair.array.sort!((a, b) => a.value < a.value).release.each!writeln; --- What's the purpose of .release? The documentation in https://dlang.org/phobos/std_range.html#.SortedRange.release is rather monosyllabic.

Re: Iterate/sort associative array by value?

2019-04-08 Thread Seb via Digitalmars-d-learn
On Monday, 8 April 2019 at 08:31:33 UTC, Dennis wrote: On Monday, 8 April 2019 at 07:53:23 UTC, Robert M. Münch wrote: Why does DMD not give a hint, that an import from the standard lib might be missing? I find these explicit import statements very annyoing. There currently are a few

Re: Iterate/sort associative array by value?

2019-04-08 Thread diniz via Digitalmars-d-learn
Le 07/04/2019 à 19:16, Seb via Digitalmars-d-learn a écrit : Then you can do: --- ["a": 1].byPair.array.sort!((a, b) => a.value < a.value).release.each!writeln; --- You'll have a sorted array with key and value props. That's what I would do: just operating on an array of {k,v} pairs. --

Re: Iterate/sort associative array by value?

2019-04-08 Thread Dennis via Digitalmars-d-learn
On Monday, 8 April 2019 at 07:53:23 UTC, Robert M. Münch wrote: Why does DMD not give a hint, that an import from the standard lib might be missing? I find these explicit import statements very annyoing. There currently are a few hard-coded import hints for common functions:

Re: Iterate/sort associative array by value?

2019-04-08 Thread Julian via Digitalmars-d-learn
On Monday, 8 April 2019 at 07:53:23 UTC, Robert M. Münch wrote: On 2019-04-07 19:28:02 +, Dennis said: Did you import it? import std.algorithm; :-/ of course not... Why does DMD not give a hint, that an import from the standard lib might be missing? It does do this, so the question

Re: Iterate/sort associative array by value?

2019-04-08 Thread Robert M. Münch via Digitalmars-d-learn
On 2019-04-07 19:28:02 +, Dennis said: Did you import it? import std.algorithm; :-/ of course not... Why does DMD not give a hint, that an import from the standard lib might be missing? I find these explicit import statements very annyoing. DMD should build up a database of stuff it

Re: Iterate/sort associative array by value?

2019-04-07 Thread Ali Çehreli via Digitalmars-d-learn
On 04/07/2019 08:41 AM, Robert M. Münch wrote: > I have an AA int[ulong] and would like to traverse the AA from biggest > to smallest by value. Is there an elegant way to do this? Because associative array is a data structure to use when the order is not important, it comes down to getting the

Re: Iterate/sort associative array by value?

2019-04-07 Thread Seb via Digitalmars-d-learn
On Sunday, 7 April 2019 at 18:22:00 UTC, Robert M. Münch wrote: On 2019-04-07 17:16:12 +, Seb said: Then you can do: --- ["a": 1].byPair.array.sort!((a, b) => a.value < a.value).release.each!writeln; --- You'll have a sorted array with key and value props. This seems to be really

Re: Iterate/sort associative array by value?

2019-04-07 Thread Seb via Digitalmars-d-learn
On Sunday, 7 April 2019 at 20:02:15 UTC, Seb wrote: On Sunday, 7 April 2019 at 18:22:00 UTC, Robert M. Münch wrote: On 2019-04-07 17:16:12 +, Seb said: Then you can do: --- ["a": 1].byPair.array.sort!((a, b) => a.value < a.value).release.each!writeln; --- You'll have a sorted array

Re: Iterate/sort associative array by value?

2019-04-07 Thread Dennis via Digitalmars-d-learn
On Sunday, 7 April 2019 at 18:22:00 UTC, Robert M. Münch wrote: Error: no property sort for type Tuple!(uint, "key", int, "value")[] Did you import it? import std.algorithm;

Re: Iterate/sort associative array by value?

2019-04-07 Thread Robert M. Münch via Digitalmars-d-learn
On 2019-04-07 17:16:12 +, Seb said: Then you can do: --- ["a": 1].byPair.array.sort!((a, b) => a.value < a.value).release.each!writeln; --- You'll have a sorted array with key and value props. This seems to be really tricky: int[uint] myArray; foreach(key, value;

Re: Iterate/sort associative array by value?

2019-04-07 Thread Robert M. Münch via Digitalmars-d-learn
On 2019-04-07 17:35:23 +, bauss said: Import std.array :-/ Thanks... -- Robert M. Münch http://www.saphirion.com smarter | better | faster

Re: Iterate/sort associative array by value?

2019-04-07 Thread bauss via Digitalmars-d-learn
On Sunday, 7 April 2019 at 16:44:01 UTC, Robert M. Münch wrote: On 2019-04-07 16:24:52 +, Cym13 said: You could use sort to gather the indexes in order then traverse from there: aa.byKey.array.sort!((a, b) => aa[a] That doesn't work: Error: no property array for type Result With

Re: Iterate/sort associative array by value?

2019-04-07 Thread Seb via Digitalmars-d-learn
On Sunday, 7 April 2019 at 16:44:01 UTC, Robert M. Münch wrote: On 2019-04-07 16:24:52 +, Cym13 said: You could use sort to gather the indexes in order then traverse from there: aa.byKey.array.sort!((a, b) => aa[a] That doesn't work: Error: no property array for type Result With

Re: Iterate/sort associative array by value?

2019-04-07 Thread Robert M. Münch via Digitalmars-d-learn
On 2019-04-07 16:24:52 +, Cym13 said: You could use sort to gather the indexes in order then traverse from there: aa.byKey.array.sort!((a, b) => aa[a] That doesn't work: Error: no property array for type Result With a wrapper caching that order and making it transparent as well as

Re: Iterate/sort associative array by value?

2019-04-07 Thread Cym13 via Digitalmars-d-learn
On Sunday, 7 April 2019 at 15:41:51 UTC, Robert M. Münch wrote: I have an AA int[ulong] and would like to traverse the AA from biggest to smallest by value. Is there an elegant way to do this? The only way I can imagine is to create an "reverse" AA of the form ulong[int] and than sort by

Iterate/sort associative array by value?

2019-04-07 Thread Robert M. Münch via Digitalmars-d-learn
I have an AA int[ulong] and would like to traverse the AA from biggest to smallest by value. Is there an elegant way to do this? The only way I can imagine is to create an "reverse" AA of the form ulong[int] and than sort by keys. Traverse this AA and use the value as the lookup key in the