Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Re: H of A optimization

by ferrency (Deacon)
on Aug 30, 2002 at 20:36 UTC ( #194245=note: print w/replies, xml ) Need Help??


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:

next if $already_seen{$b}++;
If the values are $b are densely packed small positive integers, an array may be a better choice of data structures for already_seen

The new code:

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; } }
I hope this helps.

Alan

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://194245]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2019-11-16 02:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Strict and warnings: which comes first?



    Results (85 votes). Check out past polls.

    Notices?