[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl-Modules] More about Tie::SubstrHash in MacPerl



I revised my sample code slightly to see how widespread the problem 
is. I kept my default values of key length = 13 and value length = 
86, but varied the size of the hash. NOTE: I don't recommend running 
this entire script, as it takes up to several seconds per iteration. 
A full day is only 86,400 seconds, so I picked some subranges.

#-----------------------------------------------------------------------
#! /usr/local/bin/perl5

require Tie::SubstrHash;
$least = 1;
$most = 100_000;

print "\n\nHere we go!\n";

for ($hashsize = $least; $hashsize <= $most; $hashsize++) {
	tie %test, "Tie::SubstrHash", 13, 86, $hashsize;

	for ($i = 1; $i <= $hashsize; $i++) {
		$key1 = sprintf "%06d", $i;
		$key2 = "abcdefg$key1";
		$test{$key2} = ("abcde" x 16) . "$key1";
	}

	$j = scalar(keys %test);
	print "hashsize = $hashsize = $j\n" unless ($hashsize == $j);
	untie %test;
	undef %test;
}
print "Done.\n";
#-----------------------------------------------------------------------

A few selected bits of output...
hashsize = 1 = 0
hashsize = 2 = 0
hashsize = 3 = 0
hashsize = 4 = 0
hashsize = 5 = 1
hashsize = 6 = 0
hashsize = 7 = 0
hashsize = 11 = 0
hashsize = 12 = 0
hashsize = 15 = 14
hashsize = 16 = 0
hashsize = 17 = 0
hashsize = 18 = 0
...
hashsize = 102 = 8
hashsize = 103 = 0
hashsize = 115 = 0
hashsize = 116 = 0
hashsize = 119 = 3
hashsize = 124 = 0
hashsize = 125 = 48
hashsize = 126 = 0
hashsize = 127 = 0
hashsize = 135 = 72
hashsize = 136 = 0
hashsize = 137 = 0
hashsize = 138 = 0
hashsize = 142 = 0
hashsize = 143 = 0
hashsize = 148 = 0
hashsize = 149 = 1
...
hashsize = 1002 = 6
hashsize = 1003 = 0
hashsize = 1008 = 3
hashsize = 1009 = 0
hashsize = 1015 = 538
hashsize = 1016 = 0
hashsize = 1021 = 0
hashsize = 1026 = 0
hashsize = 1027 = 64
hashsize = 1046 = 0
hashsize = 1047 = 0
hashsize = 1048 = 0
hashsize = 1049 = 0
hashsize = 1057 = 52
hashsize = 1058 = 0
hashsize = 1064 = 0
hashsize = 1065 = 290
hashsize = 1073 = 5
hashsize = 1074 = 0
hashsize = 1079 = 3
hashsize = 1084 = 0
hashsize = 1085 = 497
hashsize = 1091 = 9
hashsize = 1092 = 0

I also found that the specifics of how I compose the keys in my 
example code make a difference. For example, with the original code 
"$key1 = $i + 100_000;" a hashsize of 97 produces 0 output values, 
but with the code above, "$key1 = sprintf "%06d", $i;" the hashsize 
of 97 produces 7 output values.

The values that are visible to "keys" may be sprinkled through the 
hash: for a hashsize of 64, you get back records 37, 27, 38, 39, 41, 
42, 43, 44, 45, 2, 3, 4, 5, 6, 7, 8, 9, 28, 64, 51, 53, and 11.

The bottom line: it isn't only for very large hashes that 
Tie::SubstrHash fails.

-- 
Linc Madison  *  San Francisco, CA  *  LincPerl@LincMad.com
NO SPAM: California Bus & Prof Code Section 17538.45 applies!

==== Want to unsubscribe from this list?
==== Send mail with body "unsubscribe" to macperl-modules-request@macperl.org