in reply to Fast Way to find one array in second array
If it is too slow, then I presume that you are repeatedly traversing sequentially the outer array over and over again to look up for data. Depending on what your inner data elements really are, you might consider another data structure.
One possibility is to use a hash instead of an array for your outer "paths" data structure. The idea would be to sort the inner arrays, stringify them (with an appropriate data separator) and use that stringified version as keys for a hash (hash values would probably be insignificant, or they could contain array refs, depending on how you are using your data structure).
The structure might look like this:
Then, when you want to do a look up for some data elements, you just need to sort and stringify your data element list and you'll have instant access to the relevant data.my %paths = ( "A B F G" => 1, "A B" => 1, "A B X" => 1, "A B C D E F G" => 1, "I J K L M" => 1 );
This may or may not be an appropriate solution to your performance problem, it really depends on what you are normally doing with your data structure, on the nature of your data items, and quite a few other things that you did not describe or specify. So much more details would be needed to figure out whether this solution might be workable. If not, there may still be a variation on that solution which would work for your process.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Fast Way to find one array in second array
by melmoth (Acolyte) on Aug 14, 2016 at 16:46 UTC |