fast way to filter a list of objects

  • Thread starter Sascha Lauterbach
  • Start date
S

Sascha Lauterbach

How can I fast filter a list of objects?
The objects definied as

public class DataClass
{
public String name;
public int Value1;
public boolean Value2;
public Date TimeStamp1;
public Date TimeStamp2;
}

and the filter can e.g. definie as

name < 'data1' and value1 = 20 and not value2

or
value2 xor name = 'data2' and value1 > 30 or timestamp = now()

and so on (the filter will define by the user)

Two DataClass could define with on and the same datas.
I calculate with round about max 5000 data class.
How can I filter this on the fastest way without use a database.

Thanks a lot in advance,
Sascha
 
P

Paul Lutus

Sascha said:
How can I fast filter a list of objects?
The objects definied as

public class DataClass
{
public String name;
public int Value1;
public boolean Value2;
public Date TimeStamp1;
public Date TimeStamp2;
}

and the filter can e.g. definie as

name < 'data1' and value1 = 20 and not value2

or
value2 xor name = 'data2' and value1 > 30 or timestamp = now()

and so on (the filter will define by the user)

Two DataClass could define with on and the same datas.
I calculate with round about max 5000 data class.
How can I filter this on the fastest way without use a database.

The fastest way without a database is to create a hash that combines all the
relevant values and select on that basis (assuming the hash algorithm
creates a unique result for each record). But this may not be practical,
especially if the data are not exactly matched in the dataset by the search
terms.

The second best way is perhaps to match the relevant fields as a database
does, using as many time-saving methods as possible (like sorted lists for
each relevant field and binary searches where possible).
 
J

Jesper Nordenberg

Sascha Lauterbach said:
How can I fast filter a list of objects?
The objects definied as

public class DataClass
{
public String name;
public int Value1;
public boolean Value2;
public Date TimeStamp1;
public Date TimeStamp2;
}

and the filter can e.g. definie as

name < 'data1' and value1 = 20 and not value2

or
value2 xor name = 'data2' and value1 > 30 or timestamp = now()

and so on (the filter will define by the user)

Two DataClass could define with on and the same datas.
I calculate with round about max 5000 data class.
How can I filter this on the fastest way without use a database.

Is the data on disk or in RAM? If they are on disk you have to use
some indexing method similar to those available in databases. This is
not easy to implement yourself, use a database instead. If your
objects are located in RAM I don't see why you should have to optimize
the code, just iterating through the objects will be very fast. Still,
if that's not fast enough, index the data using B-Trees or similar
data structures.

/Jesper Nordenberg
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,527
Members
44,998
Latest member
MarissaEub

Latest Threads

Top