trySplit() 尝试进行分割
/** * If this spliterator can be partitioned, returns a Spliterator * covering elements, that will, upon return from this method, not * be covered by this Spliterator. 如果这个分割迭代器能够被进行分割。就会返回一个 涵盖这个元素的Spliterator, 分割出来的新的Spliterator可能会被继续分割,剩下的继续又当前的Spliterator涵盖 * * <p>If this Spliterator is {@link #ORDERED}, the returned Spliterator * must cover a strict prefix of the elements. 如果 Spliterator is {@link #ORDERED}。返回的必须是ORDERED的 * * <p>Unless this Spliterator covers an infinite number of elements, * repeated calls to {@code trySplit()} must eventually return {@code null}. 除非这个 Spliterator 涵盖的事一个无限的元素。 否则,必须被确认返回个数是确定的。 重复的去继续分割,分割到不能再分割。 (一定会有这样的情况。) * Upon non-null return: * <ul> * <li>the value reported for {@code estimateSize()} before splitting, * must, after splitting, be greater than or equal to {@code estimateSize()} * for this and the returned Spliterator; and</li> * <li>if this Spliterator is {@code SUBSIZED}, then {@code estimateSize()} * for this spliterator before splitting must be equal to the sum of * {@code estimateSize()} for this and the returned Spliterator after * splitting.</li> * </ul> 如果不会空: 分割前的 estimateSize()的返回值,必须大于等于分割之后estimateSize()的返回值。 如果 Spliterator is {@code SUBSIZED},那么 分割之前 estimateSize()的大小,必须等于 分割之后的 estimateSize() 和返回来的值的大小。(分割前后:必须 8 = 4+4.) * * <p>This method may return {@code null} for any reason, * including emptiness, inability to split after traversal has * commenced, data structure constraints, and efficiency * considerations. 这个放个出于以下原因,都会返回Null值 1. emptiness * * @apiNote * An ideal {@code trySplit} method efficiently (without * traversal) divides its elements exactly in half, allowing * balanced parallel computation. Many departures from this ideal * remain highly effective; for example, only approximately * splitting an approximately balanced tree, or for a tree in * which leaf nodes may contain either one or two elements, * failing to further split these nodes. However, large * deviations in balance and/or overly inefficient {@code * trySplit} mechanics typically result in poor parallel * performance. @API文档 一种理想的trySplit()方法,会恰好将元素分为两半。允许平衡的并行计算。 很多情况下违背了这种理想的情况。 比如说:只是分割一个嫉妒不平衡的一个数,数中只有两个节点。等。不能再次进行分割。 然而,很不平衡的这种机制,会导致并发效率的极度降低。 * * @return a {@code Spliterator} covering some portion of the * elements, or {@code null} if this spliterator cannot be split 返回一个Spliterator */ Spliterator<T> trySplit();JAVA8学习——Stream底层的实现(学习过程) (6)
内容版权声明:除非注明,否则皆为本站原创文章。