in reply to Re: H of A optimization
in thread H of A optimization
I think abitkin wants to make sure that $b isn't in any of the lists in %edgeHash, not to make sure that this specific edge didn't already exist.
I think a better answer is:
If the values are $b are densely packed small positive integers, an array may be a better choice of data structures for already_seennext if $already_seen{$b}++;
The new code:
I hope this helps.my %edgeHash; my %countHash; my %already_seen; while(<stdin>){ # Reading an edge list if(/^\s*([0-9]+)\s+([0-9]+)\S*$/){ my $a = "$1"; my $b = "$2"; # Eliminate loops next if $already_seen{$b}; push @{$edgeHash{$a}}, $b; } }
Alan
In Section
Seekers of Perl Wisdom