fast way to filter a list of objects

Discussion in 'Java' started by Sascha Lauterbach, Sep 8, 2004.

  1. 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
    Sascha Lauterbach, Sep 8, 2004
    #1
    1. Advertising

  2. Sascha Lauterbach

    Paul Lutus Guest

    Sascha Lauterbach wrote:

    > 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).

    --
    Paul Lutus
    http://www.arachnoid.com
    Paul Lutus, Sep 8, 2004
    #2
    1. Advertising

  3. "Sascha Lauterbach" <> wrote in message news:<413e6621$0$24841$>...
    > 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
    Jesper Nordenberg, Sep 8, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    646
  2. Michele Simionato

    Python is darn fast (was: How fast is Python)

    Michele Simionato, Aug 23, 2003, in forum: Python
    Replies:
    13
    Views:
    552
  3. Fortepianissimo

    fast way to filter a set?

    Fortepianissimo, Sep 17, 2003, in forum: Python
    Replies:
    4
    Views:
    329
    Peter Otten
    Sep 17, 2003
  4. lars_woetmann

    filter list fast

    lars_woetmann, Mar 18, 2006, in forum: Python
    Replies:
    9
    Views:
    353
    Paddy
    Mar 18, 2006
  5. Juha Nieminen
    Replies:
    22
    Views:
    996
    Kai-Uwe Bux
    Oct 12, 2007
Loading...

Share This Page