O$ List Intersect for Studio 5 on GitHub

Paul Mulroney pmulroney at logicaldevelopments.com.au
Tue Jan 16 00:50:32 EST 2018

Hi $All,
Here’s another one:

From the ReadMe:
Omnis Lists are powerful constructs that allow us to manipulate data in memory. A common operation is selecting lines in the list, often based on another list. A fairly simple way to do this would be to have two nested loop operations like the following pseudocode:

For vList1.$line from 1 to vList1.$linecount step 1
   For vList2.$line from 1 to vList2.$linecount step 1
      If vList1.field=vList2.field
         Select list line(s) {#L}
   End For
End For

For this code, it executes the inner loop n x m times – where n = list 1 linecount, and m = list 2 linecount. If List 1 or List 2 are large, then you could be executing the inner loop millions of times, and take a significant amount of time to do so.

This is where the $ListIntersect() function comes in. This method has been written so that you only process the smallest list *once*, which results n a significant performance increase.
This is really cool, so if you’re going to pinch it, make sure you acknowledge us ok?

	• plList1 – the larger of the two lists to process. It can have duplicate values in the column that you’re testing
	• plList2 – the smaller of the two lists.
	• psFieldname – the column name in the list that you’re comparing again
	• psFieldtype – options are Char, Int, Num or Date.
OUT: All lines in list1 that exist in list2 will be selected in list1.

Both lists will be sorted by the nominated field name.
The comparison column must be the same name/type in both lists.

See Example1 for a trivial example of this method in operation. For a given list of cities/states in Australia, only select lines for a number of cities
In our software we use it as part of our search filtering process for some reports.

@pmulroney, submitted on behalf of Logical Developments


Television may insult your intelligence, but nothing rubs it in like a computer.
Paul W. Mulroney                                            We Don't Do Simple Pty Ltd 
pmulroney at logicaldevelopments.com.au       Trading as Logical Developments
www.logicaldevelopments.com.au                   ACN 161 009 374 
Ph: +61 8 9458 3889                                       86 Coolgardie Street
                                                                         BENTLEY  WA  6102

More information about the omnisdev-en mailing list