in reply to Re^10: In-place sort with order assignment
in thread In-place sort with order assignment

BrowserUk,
I cannot see what would prevent this loop copying everything from %hash into both %known and the heap?

next if defined $val; will skip any keys from %hash that we have previously assigned a value to.

$hash{$key} = $known{$key};next; will assign any values we learned from the last run and then move on to the next record.

$heap->insert($key); will only insert records into the heap for keys that we have not assigned a value to (either in a previous run or this run). Update: According to the documentation, max_count => $at_once will throw out items from the heap beyond that point. If that doesn't work as advertised, that may be the source of the additional memory.

Cheers - L~R

Replies are listed 'Best First'.
Re^12: In-place sort with order assignment
by BrowserUk (Patriarch) on Sep 20, 2010 at 13:39 UTC

    I was thinking that on the first pass, no values would be set, therefore everything would end up in the heap. Whilst everything gets added, I was unaware that things were discarded beyond the specified maximum.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.