arunhorne has asked for the wisdom of the Perl Monks concerning the following question:
I am writing an object to act as a set (as in the Computer Science description). It main requirement is to be as slim and fast as possible. I have used a hash as the backing data structure because this allows me to enforce the 'no duplicates' property of sets.
So to add an element to the hash I just map it to undef as such:
$set{$item} = undef;One thing I want to do is combine two sets. Obviously this could be a real performance bottleneck and due to its intended use it is essential I combine the two backing hashes as fast as possible. Obviously I could use:
foreach $key (keys %set1) { $set2{$key} = undef; }
Is this the quickest way I can manage... or is there potentially a faster technique that anyone knows?
Thanks...
____________
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Fast Way to Combine Two Hashes
by caedes (Pilgrim) on Jun 18, 2002 at 22:10 UTC | |
Re: Fast Way to Combine Two Hashes
by Zaxo (Archbishop) on Jun 18, 2002 at 22:11 UTC | |
(tye)Re: Fast Way to Combine Two Hashes
by tye (Sage) on Jun 18, 2002 at 22:23 UTC | |
Re: Fast Way to Combine Two Hashes
by shotgunefx (Parson) on Jun 18, 2002 at 22:26 UTC | |
Re: Fast Way to Combine Two Hashes
by tadman (Prior) on Jun 18, 2002 at 22:14 UTC | |
by thelenm (Vicar) on Jun 18, 2002 at 22:22 UTC | |
Re: Fast Way to Combine Two Hashes
by mirod (Canon) on Jun 18, 2002 at 22:13 UTC | |
by runrig (Abbot) on Jun 19, 2002 at 00:01 UTC | |
by mirod (Canon) on Jun 19, 2002 at 13:05 UTC | |
by runrig (Abbot) on Jun 19, 2002 at 16:57 UTC | |
Re: Fast Way to Combine Two Hashes
by Rhandom (Curate) on Nov 11, 2004 at 18:16 UTC |