sorting associative array's keys by values

Jonathan M Davis jmdavisProg at gmx.com
Sat Jun 16 15:47:16 PDT 2012


On Sunday, June 17, 2012 00:28:07 maarten van damme wrote:
> I wanted to catch it because I could not for the life of me understand
> how downloading the exact same page twice could alter it's contents in
> such a way that it causes the program to crash.
> 
> There's something really strange going on (or maybe I'm just too tired
> to see the obvious)
> My code literally reads
> 
> 				if(debugtemp){
> 					writeln(tradeDocument[0..100]);
> 					writeln(tradeDocument.countUntil("<div class=\""));
> 					stdout.flush();
> 				}
> 
> And the output I get is
> 
> P-BODY SHRUG</h1>
>                             <span class="level">Level 1</span><br
> />(Uncraftable )
> 
> 150
> <div class="item unique" id="7088388" data="620,20,6"
> search="level:1;craftable: false;">
> 
> 0
> 
> Now either I'm going crazy or std.algorithm sees ghosts apearing.
> 
> That isn't the worst part, that is
> 
> tradeDocument=tradeDocument[1..$];
> 
> tradeDocument=tradeDocument[tradeDocument.countUntil("<div
> class=\"")..$];//go to the next element
> 
> crashing immediatly after the previous piece of code. So in reality
> std.algorithm sees an ellement that isn't there, says it's at index 0
> and a second later my program crashes on the statement x=x[0..$]
> What on earth is going on?
> 
> I use methods from
> import std.algorithm;
> import std.array;
> import std.stdio;
> import std.string;
> and no pointers, aren't they supposed to be a subset of safeD so we
> can rule out memory corruption?
> (I've confirmed this behaviour on two different machines)

If anything in there is calling @trusted code - either directly or indirectly 
- then it's possible that the @trusted code which is being called is wrong 
(since in that case, it's the programmer guaranteeing that it's @safe, not the 
compiler).

It's also possible that you've run into a code generation bug.

What's the shortest possible code that you have which reproduces the problem 
that you can give? It needs to be narrowed down before it can be determined 
what exactly is going wrong, and I don't think that you've given enough code 
in your posts for anyone else to compile it and see the failure on their 
machine.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list