Allegedly the solution to a common headache I had recently: save control points to a curve path where order of insertion is important - shape depends on it. But also delete a control point in the middle of the path (by key): meaning retain insertion order and at the same time search/insert/delete O(1) by key ... hmmm
kikuchiyo please prepare a test case to prove your hack's worth (especially when memory is not large - as others here said already).
Here is a thought:
#!/usr/bin/perl use strict; use warnings; use feature qw/say/; my %hoh = ( foo => { value => 'second', time => time}, bar => { value => 'first', time => time}, baz => { value => 'third', time => time}, ); for my $elem (sort {$a->{time} <=> $b->{time}} values %hoh) { say "value => " . $elem->{value}; }
which does not work because time() granularity is too thick/un-fine. Using DateTime::HiRes is not a guarantee either.
Should one be using instruction-based counting?
Perhaps Perl has a monotonically increasing counter, sort of like an incrementing-only program counter/instruction pointer? Alas, even than can not guarantee one instruction to insert only one hash element (can it?).
A very interesting problem which has solutions but not EFFICIENT solutions. This is one of the most ingenious I have seen.
bw, bliako
(edit: aesthetical edits a minute after posting)In reply to Re: Hashes do preserve insertion order after all
by bliako
in thread Hashes do preserve insertion order after all
by kikuchiyo
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |