The paginator keeps track of a position index in a list
and returns a subset of the choices if the list is too
long.
342251
function Paginator(options) {
  debug('initializing from <%s>', __filename);
  this.options = options || {};
  this.footer = this.options.footer;
  if (typeof this.footer !== 'string') {
    this.footer = '(Move up and down to reveal more choices)';
  }
  this.firstRender = true;
  this.lastIndex = 0;
  this.position = 0;
}
827765
def links(self):
        
        links = super(OffsetLimitPaginatedList, self).links
        if self._page.offset + self._page.limit < self.count:
            links["next"] = Link.for_(
                self._operation,
                self._ns,
                qs=self._page.next_page.to_items(),
                **self._context
            )
        if self.offset > 0:
            links["prev"] = Link.for_(
                self._operation,
                self._ns,
                qs=self._page.prev_page.to_items(),
                **self._context
            )
        return links
1153963
def paginate_results(self, results, options):
        ""
        limit = options.get('limit', settings.SELECTABLE_MAX_LIMIT)
        paginator = Paginator(results, limit)
        page = options.get('page', 1)
        try:
            results = paginator.page(page)
        except (EmptyPage, InvalidPage):
            results = paginator.page(paginator.num_pages)
        return results
813942
function() {
		var displayCount = this.getDisplayCount();
    var page = this.state.page;

    // Check position of cursor, zero based
    var idx = (page - 1) % displayCount;

    // list should not move if cursor isn't passed this part of the range
    var start = page - idx;

    // remaining pages
    var remaining = this.props.numPages - page;

    // Don't move cursor right if the range will exceed the number of pages
    // in other words, we've reached the home stretch
    if (page > displayCount && remaining < displayCount) {
      // add 1 due to the implementation of `range`
      start = this.props.numPages - displayCount + 1;
    }

    return range(start, start + displayCount);
  }
702853
def get_pages(self, label=None):
        """"""
        return (
            page for page in sorted(
                self._pages.values(), key=lambda i: i.created, reverse=True
            ) if ((not label or label in page.labels) and page.visible)
        )
398763
private void checkList(List<FileLockReference> list, long position, long size)
        throws OverlappingFileLockException
    {
        assert Thread.holdsLock(list);
        for (FileLockReference ref: list) {
            FileLock fl = ref.get();
            if (fl != null && fl.overlaps(position, size))
                throw new OverlappingFileLockException();
        }
    }
70735
def needs_pagination(self):
        """"""
        if self.objects_per_page == 0:
            return False
        if len(self.items) > self.objects_per_page \
                or len(self.get_pages[0]) > self.objects_per_page:
            return True
        return False
461347
private static int findGroupEnd(PagesIndex pagesIndex, PagesHashStrategy pagesHashStrategy, int startPosition)
    {
        checkArgument(pagesIndex.getPositionCount() > 0, "Must have at least one position");
        checkPositionIndex(startPosition, pagesIndex.getPositionCount(), "startPosition out of bounds");

        return findEndPosition(startPosition, pagesIndex.getPositionCount(), (firstPosition, secondPosition) -> pagesIndex.positionEqualsPosition(pagesHashStrategy, firstPosition, secondPosition));
    }
1216507
def pagination(title, options, collection, &block)
      start_line, options[:limit], options[:header] = pagination_limit(title, options)
      if collection.size > (options[:limit] - options[:header]) # minus pagination header
        key   = Device::IO.back_key
        pages = pagination_page(collection, options[:limit] - options[:header]) # minus pagination header
        page  = 1
        while(key == Device::IO.back_key || key == Device::IO.forward_key)
          Device::Display.clear
          pagination_header(title, page, pages.size, start_line, options[:default], options[:header])
          values = pages[page].to_a
          block.call(values, start_line + options[:header])
          key  = try_key(pagination_keys(values.size, true))
          page = pagination_key_page(page, key, pages.size)
        end
      else
        Device::Display.clear
        print_title(title, options[:default]) if title
        values = collection.to_a
        block.call(values, start_line)
        key = try_key(pagination_keys(collection.size, false))
      end
      result = values[key.to_i-1] if key.integer?
      if result.is_a? Array
        [key, result[1]]
      else
        [key, result]
      end
    end
1342274
function SubsetIterator() {
    var items = Array.prototype.slice.call(arguments, 0);

    this.items = (items.length == 1 && Array.isArray(items[0])) ? items[0] : items;

    // since we're using a bit mask, we can't have more than 32 elements. That's 2^32-1
    // subsets so that should be reasonable

    if (this.items.length > 32) {
        throw new Error("SubsetIterators cannot work with more than 32 elements");
    }

    this.max = Math.pow(2, this.items.length);
    this.reset();
}
887136
private void computeFullEndPositionList(int position) throws IOException {
    if (ignoreSpans != null && !fullEndPositionList.containsKey(position)) {
      // initial fill
      moveTo(position);
      HashSet<Integer> list = baseEndPositionList.get(position);
      if (list != null && !list.isEmpty()) {
        int maxEndPosition = maxBaseEndPosition.get(position);
        HashSet<Integer> checkList = new HashSet<>();
        HashSet<Integer> subCheckList = new HashSet<>();
        checkList.addAll(list);
        int depth = 1;
        while (!checkList.isEmpty()) {
          if (depth > maximumIgnoreLength) {
            checkList.clear();
            subCheckList.clear();
            throw new IOException("too many successive ignores, maximum is "
                + maximumIgnoreLength);
          } else {
            for (Integer checkItem : checkList) {
              if (fullEndPositionList.get(checkItem) != null) {
                list.addAll(fullEndPositionList.get(checkItem));
                maxEndPosition = Math.max(maxEndPosition,
                    maxFullEndPosition.get(checkItem));
              } else {
                moveTo(checkItem);
                if (baseEndPositionList.containsKey(checkItem)) {
                  list.addAll(baseEndPositionList.get(checkItem));
                  maxEndPosition = Math.max(maxEndPosition,
                      maxBaseEndPosition.get(checkItem));
                  subCheckList.addAll(baseEndPositionList.get(checkItem));
                } else {
                  // ready for checkItem
                }
              }
            }
            checkList.clear();
            checkList.addAll(subCheckList);
            subCheckList.clear();
            depth++;
          }
        }
        fullEndPositionList.put(position, list);
        maxFullEndPosition.put(position, (maxEndPosition - position));
      } else {
        fullEndPositionList.put(position, null);
        maxFullEndPosition.put(position, 0);
      }
    }
  }
385293
def sort(self):
        
        if self.is_guaranteed_sorted:
            self.log(u"Already sorted, returning")
            return
        self.log(u"Sorting...")
        self.__fragments = sorted(self.__fragments)
        self.log(u"Sorting... done")
        self.log(u"Checking relative positions...")
        for i in range(len(self) - 1):
            current_interval = self[i].interval
            next_interval = self[i + 1].interval
            if current_interval.relative_position_of(next_interval) not in self.ALLOWED_POSITIONS:
                self.log(u"Found overlapping fragments:")
                self.log([u"  Index %d => %s", i, current_interval])
                self.log([u"  Index %d => %s", i + 1, next_interval])
                self.log_exc(u"The list contains two fragments overlapping in a forbidden way", None, True, ValueError)
        self.log(u"Checking relative positions... done")
        self.__sorted = True
357890
private void seek(List<TopicPartition> seekList) {
        for (TopicPartition tp : seekList) {
            AtomicLong lastCommittedOffset = m_lastCommittedOffSets.get().get(tp);
            if (lastCommittedOffset != null && lastCommittedOffset.get() > -1L) {
                AtomicLong lastSeeked = m_lastSeekedOffSets.get(tp);

                //eliminate duplicate seek
                if (lastSeeked != null && lastSeeked.get() == lastCommittedOffset.get()) {
                    continue;
                }
                m_consumer.seek(tp, lastCommittedOffset.longValue());
                m_lastSeekedOffSets.put(tp, new AtomicLong(lastCommittedOffset.get()));

                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("Moves offset for group " +  m_config.getGroupId() + " -" + tp + " to " + lastCommittedOffset);
                }
            }
        }
    }
903757
def item_lister(command, _connection, page_size, page_number, sort_by,
    sort_order, item_class, result_set, **kwargs):
    
    # pylint: disable=R0913
    page = page_number
    while True:
        item_collection = _connection.get_list(command,
                                             page_size=page_size,
                                             page_number=page,
                                             sort_by=sort_by,
                                             sort_order=sort_order,
                                             item_class=item_class,
                                             **kwargs)
        result_set.total_count = item_collection.total_count
        result_set.page_number = page
        for item in item_collection.items:
            yield item
        if item_collection.total_count < 0 or item_collection.page_size == 0:
            break
        if len(item_collection.items) > 0:
            page += 1
        else:
            break
812136
void updateCount() {
		if (this.hasChanged) {
			this.positionArray = ArrayUtils.toPrimitive(getPositionList()
					.toArray(new Long[0]));
			this.hasChanged = false;
		}
	}
541476
synchronized List<PageWrapper> getPagesSortedByOffset() {
        return this.pageByOffset
                .values().stream()
                .sorted(Comparator.comparingLong(PageWrapper::getOffset))
                .collect(Collectors.toList());
    }
1022509
public List<ENTITY> page(List<Match> matches, List<Order> order, int curPage, int pageSize) {

        if (curPage < 0 || pageSize < 0) {
            return find(matches, order);
        }

        int offset = (curPage) * pageSize;
        int limit = pageSize;
        return find(matches, order, offset, limit);
    }