Welcome to the Monastery | |
PerlMonks |
Re: Building Networks of Matchesby hv (Prior) |
on Dec 23, 2004 at 14:20 UTC ( [id://417091]=note: print w/replies, xml ) | Need Help?? |
I didn't fully understand your suggestion for how you might go about it, but below is the simplistic approach I'd use as a starting point. The key features of the scan are a) to build two data structures simultaneously: one to contain known sets of equivalences, and the second to contain the elements that those sets match; b) when new equivalences are found, the data structures for the equivalent sets are merged.
If this isn't fast enough, my first thought to improve it would be to find some way of using bit vectors to represent the elements, so that matches can be checked with a bitwise-and of two strings. To do that, you'd need to find a way to translate elements into numbers that you can use as a bit offset. However, if there are lots of elements most of which appear only once, it may be better to do a prepass to get a list of repeated elements, and then consider only those repeats in the main loop. Hope this helps, Hugo
In Section
Seekers of Perl Wisdom
|
|