commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Andrew M" <and...@oc384.net>
Subject RE: Collections LinkedMap question
Date Fri, 05 Jun 2009 19:44:49 GMT
>I expect that the linked map will be very, very fast.

I just wanted to confirm that what I think I know about the LinkedMap is correct.   I believe
it should be using the map to do the indexOf(object) lookup and not iterating like Vector.indexOf(object).
 But LinkedMap.java has it using this loop which makes me think it's slow relative to a hashmap
lookup.  I'm looking for a collection like a Vector but with an indexOf(object) method which
uses a map of object->index instead of iterating like a Vector does.

/**
* Gets the index of the specified key.
* 
* @param key  the key to find the index of
* @return the index, or -1 if not found
*/
    public int indexOf(Object key) {
        key = convertKey(key);
        int i = 0;
        for (LinkEntry entry = header.after; entry != header; entry = entry.after, i++) {
            if (isEqualKey(key, entry.key)) {
                return i;
            }
        }
        return -1;
    }


Thanks,
Andrew
 


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message