Re: What is the best way to search for a set of values within a multi-dimenstional array?

From: Andy Fish (ajfish_at_blueyonder.co.uk)
Date: 06/10/04


Date: Thu, 10 Jun 2004 16:56:15 GMT


"Bill" <webobjectfan@yahoo.com> wrote in message
news:c75ff133.0406100804.37ae7f39@posting.google.com...
> suppose I have a table with 3 columns: A, B, C, and has the following
> values:
>
> A B C
> 1 2 3
> 4 5 6
> 7 8 9
>
> I want to know what is the best way to find whether there is a row in
> a table that contains 3 different values regardless of the orders they
> are entered. For example, if I enter the search values (5,6,4) or
> (4,5,6) or (4,6,5), or (5,4,6), the search should return true (row 2).
>
> Any suggestions?

keep a sorted copy of each row, then you can sort the input criteria and
match it up against each row by checking for equality

If you keep the values as Integer objects rather than primitive 'int's, you
can have an ArrayList for each row, then use collections.sort to sort each
individual row. Keep them all in a hashset then you can use the contains()
method to see if you have a match.

not very efficient in memory use, but saves you writing your own sort and
search logic.

Andy



Relevant Pages

  • Re: Survey: CAD Posts.
    ... explaining what separates UG NX CAM from say Mastercam. ... Bill just started a new job. ... NX CAM Operation Manager is radically better than the approach ... You can sort the operations list with a simple right click. ...
    (alt.machines.cnc)
  • Re: Phone latest... was Weighing the merits of Obama
    ... We *still* have not been able to return the mobile phone that has never ... Incidentily the bill is nearly twice what it should be too. ... I wrote to their complaints department telling them that we had ... solicitor if they didn't sort it out NOW! ...
    (soc.culture.scottish)
  • Re: OT: Funny: Im voting Republican.
    ... I thought I heard some sort of announcement a while ago. ... Lenny Flank ... filibuster the bill. ... If the bill gets past the filibuster, they say they are going to offer ...
    (talk.origins)
  • Re: Phone latest... was Weighing the merits of Obama
    ... We *still* have not been able to return the mobile phone that has never worked nor the totally incompatible 3 foot antennae they later sent us and we've been trying since about August. ... Last friday they sent us a bill for $506 for the mobile-that-has-never-been-used PLUS a final demand for a bill that was paid two months ago. ... I wrote to their complaints department telling them that we had documented every call and we were about to hand over the story to the TV stations (they love this sort of thing) and newpapers via our MP and solicitor if they didn't sort it out NOW! ...
    (soc.culture.scottish)
  • Re: Premature review Book " jamie at home"
    ... Bill wrote: ... except it only has recipes using stuff you can grow. ... Author recommends ... Sort of reflects "Omnivore's Dilemma" ...
    (rec.gardens)