Results 1 to 3 of 3
  1. #1
    salmontres is offline Member
    Join Date
    Dec 2011
    Posts
    30
    Rep Power
    0

    Default Maximizing efficiency with sets and lists

    Hi guys,

    I want to store objects in a collection with very fast lookups but that maintains some sort of queue order. (Theoretically, I may be storing about 300 million members in the collection.) I read into the LinkedHashSet in Java, but I didn't know if in creating the double linked list for the structure, performance would suffer.

    Have you guys used the LinkedHashSet? Is it much slower than the HashSet in lookups? If it is, would it be easier to create to objects (a HashSet and a LinkedList) to store my information?

    Last question, how do I mark a thread as solved? I've received great help from some of my other questions, I leave reputation marks, but I don't see any way to close or mark the thread as solved.

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,641
    Rep Power
    7

    Default Re: Maximizing efficiency with sets and lists

    I would recommend reviewing the API which might answer your questions more thoroughly
    LinkedHashSet (Java Platform SE 6)
    Like HashSet, it provides constant-time performance for the basic operations (add, contains and remove), assuming the hash function disperses elements properly among the buckets. Performance is likely to be just slightly below that of HashSet, due to the added expense of maintaining the linked list
    I would presume the last sentence refers to the add/remove (and other) methods, but doesn't apply to the contains method which should be independent of the internal LinkedList (and in fact, LinkedHashSet extends HashSet and doesn't override the contains method)
    Last edited by doWhile; 12-18-2011 at 02:32 AM.

  3. #3
    salmontres is offline Member
    Join Date
    Dec 2011
    Posts
    30
    Rep Power
    0

    Default Re: Maximizing efficiency with sets and lists

    You're correct on all points, doWhile. This is the exact information I was looking for. Thanks!

    Another question came up, which I couldn't find in the reading. Although the LinkedHashSet has predictable ordering, I couldn't find a method which simply lets me remove the last element. Right now, I'm iterating through the entire list with an iterator, and when (iter.hasNext() == false), I simply do iter.remove(). (Which takes care of the last element.)

    Did I miss something? How can I remove the last element of the set, without knowing explicitly the last element, nor iterating through the entire list every time? (If possible.)

Similar Threads

  1. Maps and Sets
    By darkblue24 in forum New To Java
    Replies: 19
    Last Post: 03-25-2010, 06:13 PM
  2. Maps and Sets
    By RedKMan in forum New To Java
    Replies: 3
    Last Post: 02-16-2010, 09:36 AM
  3. Duplicates in more than two sets
    By JavaJ in forum New To Java
    Replies: 8
    Last Post: 12-03-2009, 04:07 PM
  4. Trouble maximizing tab
    By dragonwitch in forum New To Java
    Replies: 2
    Last Post: 09-12-2008, 06:24 PM
  5. JFrame maximizing
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 03-12-2008, 11:19 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •