All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.basking2.sdsai.itrex.iterators.PrefetchingIterator Maven / Gradle / Ivy

There is a newer version: 1.1.23
Show newest version
package com.github.basking2.sdsai.itrex.iterators;

import java.util.Iterator;
import java.util.concurrent.Executor;

import static java.util.Arrays.asList;

/**
 * An iterator that prefetches and caches some number of elements from another iterator.
 *
 * Sometimes it is expensive for an iterator to return a value.
 * In these situations it is sometimes preferable to pre-fetch a few objects, and
 * asynchronously replenish them.
 *
 * Order is preserved, so if there is a particularly slow fetch, it may stall future fetches.
 * 
 * This is just a kind of {@link ParallelIteratorIterator} that uses a single iterator.
 */
public class PrefetchingIterator extends ParallelIteratorIterator {

    public PrefetchingIterator(final Executor executor, final int prefetch, final Iterator iterator) {
        super(executor, prefetch, asList(iterator));
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy