Data structure for fast filtering (Delphi)?

I am optimizing the part of the Delphi application where object lists are often filtered using different criteria. Objects are stored in structures TObjectList, and usually for each filter a very small percentage (for example, 1%) of the entire set is allocated. The total number of objects can be in the range of 100 thousand. And during the calculations, the main set does not change. Although filters are applied to only a few properties, lists cannot be sorted in such a way as to optimize all possible criteria.

I am looking for suggestions on how to organize objects (data structures) or an algorithm that can be used to solve this problem. Thank!

Filter example:

  ((Object.A between 5 and 15) AND
  (Object.B < 20) AND
  (Object.C(AParam) > 0)) OR
  (Object.IsRoot(...))
+3
source share
6 answers

Idea number 1

Run your code in the profiler. Find out if there are slow places.

Idea number 2

Perhaps you could take advantage of cache effects by storing your objects in memory in sequence. (I assume that you continue your list sequentially from start to finish.)

One way to do this could be to use an array of records instead of a list of objects. If possible in your case. Remember that records in Delphi 2006 can have methods (but not virtual ones).

- . , , . , TObjectList.

+2

, , /, , / .

: A - , 5 15, () ( ), (B, C IsRoot).

Delphi (2009+) : DeHL.Collections.SortedList

+4

, , , , , .

, SQL . , . DBISAM ElevateDB, . , , .

+1

, , ? 4 . , , . 2 , ...

+1

. , , SQL: , SQL, , (), , , , , . , , , SQL- .

, , , :

(1) , , . : "boolean", , , ( ) !

(2) ( ).

: "A" "B". "C", -, , . "IsRoot", , , .

The data structures used for your data are completely dependent on your data. If performance is critical, do a few and run the tests. If it's not critical, just your favorite list sorting algorithm and do it!

+1
source

Source: https://habr.com/ru/post/1734660/


All Articles