简体   繁体   中英

Initializing initial capacity and load factor of immutable HashSet in Scala

Is there an easy way to initialize initial capacity and load factor of HashSet in Scala? In Java it's very easy, for example:

public HashSet set = new HashSet(1 << 8, 0.6f)

I'd like to know, if there is any equivalent of this in Scala.

I also know that it's easy to use Javas HashSet instead simply by importing java.util.HashSet, but I'm curious if same is possible with scala.collection.immutable.HashSet

EDIT. I've checked from Scala API and HashSet source code, but didn't find anything useful.

Hashsets comes with two flawors in scala.

mutable.HashSet is pretty like java HashSet and it has sizeHint method which could be used on any (eg empty ) collection to resize current table.

immutable.HashSet has different approach. It is implemented via hash trie algorithm instead of hash table so as JimH mentioned methods like sizeHint are meaningless for it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM