java – Spliterator – size vs subsized flags

https://docs.oracle.com/javase/8/docs/api/java/util/Spliterator.html

SIZED Characteristic value signifying that the value returned from
estimateSize() prior to traversal or splitting represents a finite
size that,in the absence of structural source modification,
represents an exact count of the number of elements that would be
encountered by a complete traversal.

SUBSIZED Characteristic value signifying that all Spliterators
resulting from trySplit() will be both SIZED and SUBSIZED.

>是否存在SIZED标志打开但SUBSIZED标志关闭的情况?
>是否存在SUBSIZED标志打开但SIZED标志关闭的情况?

解决方法

Spliterator的典型示例是SIZED但不是SUBSIZED,是从HashMap创建的Spliterator.它将在其内部条目数组中保持一个范围,其中一些数组条目为空,因为容量高于实际大小.要跳过的空条目的确切分布取决于包含的键的哈希码.

因此,Spliterator最初确实知道它的(总)大小,但是当分割范围时,它不知道每个范围中有多少元素. HashMap具有的元素越多,大致平衡分割的可能性就越高,因此这种策略是合理的,但确切的子集是未知的,并且需要对数组进行迭代才能找到.

报告没有SIZED的SUBSIZED特征是没有意义的,据我所知,甚至没有效果.

相关文章

最近看了一下学习资料,感觉进制转换其实还是挺有意思的,尤...
/*HashSet 基本操作 * --set:元素是无序的,存入和取出顺序不...
/*list 基本操作 * * List a=new List(); * 增 * a.add(inde...
/* * 内部类 * */ 1 class OutClass{ 2 //定义外部类的成员变...
集合的操作Iterator、Collection、Set和HashSet关系Iterator...
接口中常量的修饰关键字:public,static,final(常量)函数...