in reply to Search and Remove
You basically want to calculate the intersection of two lists (and the negation of that). The following algorithm will work, assuming relatively small lists and unsorted initial input:
The more general algorithm, above, runs at near-linear time but will consume memory proportional to the number of elements in your DEL list (which is still much better than your solution, which re-reads the entire DEL list for each line of the ORG list!)
Less general option: If your initial files are known to be pre-sorted by your key value, you can traverse each with a pair of list cursors. The advantage of this approach is that it runs in strict linear time on the total number of elements across both lists, and uses a small constant amount of memory (i.e., memory does not increase with the size of the DEL list.)
You might also want to look at List::Compare (specifically, the intersection method) for a reusable solution if your data is small enough where storing both sets in RAM isn't an issue.
Have fun!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Search and Remove
by PyrexKidd (Monk) on Jun 12, 2010 at 21:34 UTC | |
by choroba (Cardinal) on Jun 12, 2010 at 22:07 UTC | |
by rjt (Curate) on Jun 12, 2010 at 22:44 UTC | |
by PyrexKidd (Monk) on Jun 13, 2010 at 02:22 UTC | |
by ww (Archbishop) on Jun 13, 2010 at 03:22 UTC | |
by PyrexKidd (Monk) on Jun 16, 2010 at 01:09 UTC | |
by rjt (Curate) on Jun 17, 2010 at 10:02 UTC | |
by PyrexKidd (Monk) on Jun 26, 2010 at 00:03 UTC | |
by PyrexKidd (Monk) on Jun 26, 2010 at 00:16 UTC | |
|