Results 1 to 3 of 3
- 12-18-2011, 02:15 AM #1
Member
- Join Date
- Dec 2011
- Posts
- 30
- Rep Power
- 0
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.
- 12-18-2011, 02:30 AM #2
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,619
- Rep Power
- 5
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)
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)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 listLast edited by doWhile; 12-18-2011 at 02:32 AM.
- 12-18-2011, 03:51 AM #3
Member
- Join Date
- Dec 2011
- Posts
- 30
- Rep Power
- 0
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
-
Maps and Sets
By darkblue24 in forum New To JavaReplies: 19Last Post: 03-25-2010, 06:13 PM -
Maps and Sets
By RedKMan in forum New To JavaReplies: 3Last Post: 02-16-2010, 09:36 AM -
Duplicates in more than two sets
By JavaJ in forum New To JavaReplies: 8Last Post: 12-03-2009, 04:07 PM -
Trouble maximizing tab
By dragonwitch in forum New To JavaReplies: 2Last Post: 09-12-2008, 06:24 PM -
JFrame maximizing
By Java Tip in forum Java TipReplies: 0Last Post: 03-12-2008, 11:19 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks