in reply to Re: constructing large hashes
in thread constructing large hashes

Ah Ha! Of course. I guess that I should have thought of that. Anyway, after trying several different separators (',', ' ', '_', '-', '.', '0') and even trying padding with zeroes (01, 02, ..., 08), the only solution that works well is no separator which makes it more difficult when we move to permutations of 10 or more things. Although from blssu's results below it looks as though some of this was fixed in perl 5.8 (I'm still limping along at 5.6.1).

Thanks!
    Dean


If we didn't reinvent the wheel, we wouldn't have rollerblades.

Replies are listed 'Best First'.
Re: Re: Re: constructing large hashes
by jsprat (Curate) on Oct 01, 2002 at 01:08 UTC
    I had another thought on the way home from work. You don't need the temp array, just build the hash in the code block for permute!

    permute { $temp = join(',',@n); $arrangement{$temp} = undef;} @n; # create the hash here --^^^^

    That should save some memory - and on my system, about a minute. As far as the separators, maybe pack the permutation into the key?

    permute {  $arrangements{pack "C*", @n} =1 } @n;

    is almost instantaneous. Won't help with 10 or more...

Re: Re: Re: constructing large hashes
by thor (Priest) on Oct 02, 2002 at 11:23 UTC
    Ah Ha! Of course. I guess that I should have thought of that. Anyway, after trying several different separators (',', ' ', '_', '-', '.', '0') and even trying padding with zeroes (01, 02, ..., 08), the only solution that works well is no separator which makes it more difficult when we move to permutations of 10 or more things. Although from blssu's results below it looks as though some of this was fixed in perl 5.8 (I'm still limping along at 5.6.1).
    As I'm now (attempting to) learn C, maybe this is obvious to me because it's a common idiom in C: use letters instead. You can use the ord function to get a mapping between the letters and the numbers, and you can even normalize the set [a-z] -> [0-25] by subtracting ord("a"). Also, you wouldn't have to change much else (from what I can see, anyways). For instance:
    $n = 8; @n = (1..$n);
    becomes
    $n = ord("a")+8; @n = ("a"..$n);
    Of course, this all assumes that you don't do many explicit aritmetic calculations on your set of permutations. If you do, the repeated calls to ord and char my be prohibitive.

    thor