B
bpatton
I'm trying to generate a unique integer from a string. It must
generate the same integer each time it has the same string. I'm
trying to use unpack to do this.
Here is a small sample. My real version now has @ 2000 strings, but
his is only going up.
my $s1 = '-Dfull_drc=true -Dgds_file=gds.VIA4T -Dgds_layer=VIA4T -
Dstore_layer=VIA4T';
my $s2 = '-Dfull_drc=true -Dgds_file=gds.VIA1T -Dgds_layer=VIA1T -
Dstore_layer=VIA1T';
my ($u1,$u2);
($u1) = unpack("%J*",$s1);
($u2) = unpack("%J*",$s2);
print "u1 = $u1\n";
print "u2 = $u2\n";
If I change the J to an A this example works ok, but hunderds other
one fail.
I'm checking these by creating a perl hash where the $U# is the key
and the string is the value.
So that I check for the existance of a key, if it exists the I compare
the values. if the are equal then it is an error
Here is my actual code : (less genRppPermutations too large) $s1 and
$s2 are examples from genRppPerrmutations.
my @switchList;
my ($rpp,%hash,$key,$string);
foreach $rpp ( qw ( COMBINE GEN_STORE L2G.gatet L2G.met L2G.primary
L2G.umc MASTER_RPP PG_PASS1 PG_PASS2 PG_PASS2.SPLITPOL PG_PASS2.met
PG_PASS3) ) {
@switchList = genRppPermutations($rpp);
foreach $string (@switchList) {
($key) = unpack("%A*",$string);
if (exists $hash{$key}) {
unless ($hash{$key} eq $string) {
print "collision between strings, both generated '$key'\n";
print " s1 : $string\n";
print " s2 : $hash{$key}\n";
}
} else {
$hash{$key} = $string;
}
}
}
generate the same integer each time it has the same string. I'm
trying to use unpack to do this.
Here is a small sample. My real version now has @ 2000 strings, but
his is only going up.
my $s1 = '-Dfull_drc=true -Dgds_file=gds.VIA4T -Dgds_layer=VIA4T -
Dstore_layer=VIA4T';
my $s2 = '-Dfull_drc=true -Dgds_file=gds.VIA1T -Dgds_layer=VIA1T -
Dstore_layer=VIA1T';
my ($u1,$u2);
($u1) = unpack("%J*",$s1);
($u2) = unpack("%J*",$s2);
print "u1 = $u1\n";
print "u2 = $u2\n";
If I change the J to an A this example works ok, but hunderds other
one fail.
I'm checking these by creating a perl hash where the $U# is the key
and the string is the value.
So that I check for the existance of a key, if it exists the I compare
the values. if the are equal then it is an error
Here is my actual code : (less genRppPermutations too large) $s1 and
$s2 are examples from genRppPerrmutations.
my @switchList;
my ($rpp,%hash,$key,$string);
foreach $rpp ( qw ( COMBINE GEN_STORE L2G.gatet L2G.met L2G.primary
L2G.umc MASTER_RPP PG_PASS1 PG_PASS2 PG_PASS2.SPLITPOL PG_PASS2.met
PG_PASS3) ) {
@switchList = genRppPermutations($rpp);
foreach $string (@switchList) {
($key) = unpack("%A*",$string);
if (exists $hash{$key}) {
unless ($hash{$key} eq $string) {
print "collision between strings, both generated '$key'\n";
print " s1 : $string\n";
print " s2 : $hash{$key}\n";
}
} else {
$hash{$key} = $string;
}
}
}