简体   繁体   English

在Scala中初始化不可变HashSet的初始容量和负载因子

[英]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? 有没有一种简单的方法可以在Scala中初始化HashSet的初始容量和负载因子? In Java it's very easy, for example: 在Java中,这非常简单,例如:

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

I'd like to know, if there is any equivalent of this in Scala. 我想知道,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 我也知道,仅通过导入java.util.HashSet即可轻松使用Java HashSet,但我很好奇scala.collection.immutable.HashSet是否可以实现

EDIT. 编辑。 I've checked from Scala API and HashSet source code, but didn't find anything useful. 我检查了Scala API和HashSet源代码,但没有发现任何有用的东西。

Hashsets comes with two flawors in scala. Hashsets在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. mutable.HashSet非常类似于java HashSet ,它具有sizeHint方法 ,可用于任何(例如empty )集合以调整当前表的大小。

immutable.HashSet has different approach. immutable.HashSet具有不同的方法。 It is implemented via hash trie algorithm instead of hash table so as JimH mentioned methods like sizeHint are meaningless for it. 它是通过哈希Trie算法而不是哈希表实现的,因此JimH提到的sizeHint类的方法对此毫无意义。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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