java – Spliterator – size vs subsized flags

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

>Is there a case where the sized flag is on but the subsized flag is off? > Is there a case where the subsized flag is on but the sized flag is off?

Solution

A typical example of a splitter is a splitter created from HashMap, which is sized but not subsized It will maintain a range in its internal array of entries, some of which are empty because the capacity is higher than the actual size The exact distribution of empty entries to skip depends on the hash code of the included key

Therefore, the splitter does know its (total) size at first, but when dividing ranges, it does not know how many elements are in each range The more elements a HashMap has, the higher the possibility of roughly balanced segmentation. Therefore, this strategy is reasonable, but the exact subset is unknown, and the array needs to be iterated to find it

It is meaningless to report the subsized feature without size. As far as I know, it has no effect

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>