The opposite of intersect array?

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
edgore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 197
Joined: Wed Jun 14, 2006 8:40 pm

The opposite of intersect array?

Post by edgore » Tue Aug 06, 2013 3:37 pm

I am trying to figure out how to get a list of items that are in one list, but not in another list. Since I am dealing with a very long lists going through and checking each line and matching things up is very time consuming, and I am trying to find a faster way.

What I really want is something that works like intersect array, but instead of discarding the non-matching items, I just want that list of non-matching items.

Any way to do something like this (or just anything that is fast than what I am doing right now, which involves for each-ing through one of the variables...
Last edited by edgore on Wed Aug 07, 2013 1:22 am, edited 1 time in total.

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4177
Joined: Sun Jan 07, 2007 9:12 pm

Re: The opposite of intersect array?

Post by bn » Tue Aug 06, 2013 8:17 pm

Hi Ed,

could you give an example of the list and the items, what exactly are the criteria, what defines a non-matching item. An item (in the Livecode sense) or what? Or do you want to test for non-identical lines?

Best would be an example of a matching line and a non-matching line.

Kind regards
Bernd

edgore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 197
Joined: Wed Jun 14, 2006 8:40 pm

Re: The opposite of intersect array?

Post by edgore » Wed Aug 07, 2013 1:35 am

Here is an example

I have one with one item per line (currently they are all numbers, but that might not always be true in the future.

Let's say the list is:

1234567
1234568
1234569
1234560
1234561

I have another list that contains, say:

1234567,value one,123-1234
1234568,value two,345-4567
1234569,value one,765-4567
1234560,value three,765-8664

I want the result of the operation (which is basically the equivalent of an SQL "except" operation) to be:
1234561

Basically, the one line from the first list that doesn't appear in the second list.

I don't care about retaining any values in the second list, so I could do a split on the second list by comma and get back the keys of the array that created to make a list of just the first items if needed. I know that I could do this by popping everything in database tables and actually doing a select except, but for various reasons (multi-user server environment, desire to not create and drop a bunch of tables, or sqllite files) I would prefer to handle this in a script if it's possible. It surprised me that I could do a union or a intersect of the keys of arrays, but not an except....

rkriesel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 119
Joined: Thu Apr 13, 2006 6:25 pm

Re: The opposite of intersect array?

Post by rkriesel » Wed Aug 07, 2013 3:21 am

edgore --
Here's one way.
-- Dick

Code: Select all

    split tList1 by cr as set
    repeat for each line tLine in tList2
        delete variable tList1[ item 1 of tLine ]
    end repeat
    combine tList1 by cr as set

edgore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 197
Joined: Wed Jun 14, 2006 8:40 pm

Re: The opposite of intersect array?

Post by edgore » Wed Aug 07, 2013 12:03 pm

Yep - that works, and it's very fast! I had run into so many problems with the other "for each" based methods (they were all very slow) that it would never have occurred to me that deleting keys was a very fast option! Have to remember from now on - try every array based way you can of doing something first, it's going to be the fastest.

Post Reply