Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. COYes, I did try, but unfortunately when I know the size of a `HashSet` and tell it `new HashSet(n / 2)` it gives worse performance than without that capacity... Very strange, I guessed that it creates big arrays and spends a lot of time when doing lookup (during contains possibly), well, at least Bruce Eckel in Thinking in Java said something like that. Thank you for the answer anyway, I kind of accept it :)
      singulars
    2. COWhy would you do n / 2? If you know you are going to have exactly n elements, then use n. In an optimal case, each bucket will have exactly one element, but in case there happens to be a collision (unlikely if your data set is not very large) perfomance will not suffer much as long as you don't recalculate and reassign the hashtable (i.e. insert more than n elements, in your case, n/2). As per the hashtable doc (http://docs.oracle.com/javase/6/docs/api/java/util/Hashtable.html)
      singulars
    3. CO" "The initial capacity controls a tradeoff between wasted space and the need for rehash operations, which are time-consuming. No rehash operations will ever occur if the initial capacity is greater than the maximum number of entries the Hashtable will contain divided by its load factor. However, setting the initial capacity too high can waste space." So, if you are only holding ints, then the wasted space problem shouldn't be an issue. Try setting it to at least n, or even better, try n+1:
      singulars
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload