Custom or vanilla Collection/Map?

Discussion in 'Java' started by VisionSet, Sep 15, 2003.

  1. VisionSet

    VisionSet Guest

    I have a several classes that implement an interface that declares a
    getInteger() method.

    I would like to store objects of this type in some sort of collection

    I require to iterate them in the order inserted and to get them based on
    their Integer key.

    LinkedHashMap I believe is the daddy.

    however I'm thinking this is quite expensive and most of the time my
    Integers will be consecutive, so why not reimplement a custom ArrayList to
    do the job, that has offset ability.

    MyArrayList could even determine as the objects are added if they have
    consecutive integers, thus making it very efficient to find them via get(int
    index). Otherwise it could revert to searching for them by iteration. (or
    even using the LinkedHashMap).

    So I guess my question is, how does this 2nd fall back approach compare to
    LinkedHashMap?

    Also how does a Map work? how does it do get(Object key)? does it iterate
    its contents?

    Another question which relates to testing stuff like this. I've seen in a
    recentish post that it is possible to do unit tests that time very
    accurately, ie better than a simple System.getCurrentTimeMillis() type
    approach. Is the answer - get JUnit? Or can I do this simply without it?


    --
    Mike W
    VisionSet, Sep 15, 2003
    #1
    1. Advertising

  2. VisionSet

    Roedy Green Guest

    On Mon, 15 Sep 2003 00:33:08 +0100, "VisionSet" <>
    wrote or quoted :

    >So I guess my question is, how does this 2nd fall back approach compare to
    >LinkedHashMap?


    Linked HashMap just threads the objects insertion order so you can get
    them in the original order. The lookup is identical to a HashMap.


    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
    Roedy Green, Sep 15, 2003
    #2
    1. Advertising

  3. VisionSet

    Roedy Green Guest

    On Mon, 15 Sep 2003 00:33:08 +0100, "VisionSet" <>
    wrote or quoted :

    >Also how does a Map work? how does it do get(Object key)? does it iterate
    >its contents?


    Map is just an interface. It has nothing to say about how it works
    inside.

    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
    Roedy Green, Sep 15, 2003
    #3
  4. VisionSet

    Harald Hein Guest

    "VisionSet" wrote:

    > however I'm thinking this is quite expensive and most of the time
    > my Integers will be consecutive, so why not reimplement a custom
    > ArrayList to do the job, that has offset ability.


    Do you need the performance? Then do it. If you don't need the
    performance, don't do it. You don't know if you need the performance
    (now)? Don't do it (now).
    Harald Hein, Sep 15, 2003
    #4
    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. VisionSet
    Replies:
    1
    Views:
    324
    Roedy Green
    Jul 3, 2004
  2. Art
    Replies:
    3
    Views:
    460
  3. Neil Benn

    Vanilla python path

    Neil Benn, Jul 25, 2005, in forum: Python
    Replies:
    0
    Views:
    348
    Neil Benn
    Jul 25, 2005
  4. Øyvind Isaksen
    Replies:
    1
    Views:
    964
    Øyvind Isaksen
    May 18, 2007
  5. markritter150

    Vanilla Ice is back!

    markritter150, Jun 3, 2008, in forum: C Programming
    Replies:
    6
    Views:
    304
Loading...

Share This Page