Bucket pagination
197551
def process_bucket_iterator(bid, prefix="", delimiter="", **continuation):
    
    log.info("Iterating keys bucket %s prefix %s delimiter %s",
             bid, prefix, delimiter)

    account, bucket = bid.split(':', 1)
    region = connection.hget('bucket-regions', bid)
    versioned = bool(int(connection.hget('bucket-versions', bid)))
    session = get_session(
        json.loads(connection.hget('bucket-accounts', account)))
    s3 = session.client('s3', region_name=region, config=s3config)

    (contents_key, contents_method, _) = BUCKET_OBJ_DESC[versioned]

    params = dict(Bucket=bucket)
    if prefix:
        params['Prefix'] = prefix
    if delimiter:
        params['Delimiter'] = delimiter
    if continuation:
        params.update({k[4:]: v for k, v in continuation.items()})
    paginator = s3.get_paginator(contents_method).paginate(**params)
    with bucket_ops(bid, 'page'):
        ptime = time.time()
        pcounter = 0
        for page in paginator:
            page = page_strip(page, versioned)
            pcounter += 1
            if page:
                invoke(process_keyset, bid, page)

            if pcounter % 10 == 0:
                with connection.pipeline() as p:
                    nptime = time.time()
                    p.hincrby('bucket-pages', bid, 1)
                    p.hincrby('bucket-pages-time', bid, int(nptime - ptime))
                    ptime = nptime
                    p.execute()

        if pcounter % 10:
            with connection.pipeline() as p:
                nptime = time.time()
                p.hincrby('bucket-pages', bid, 1)
                p.hincrby('bucket-pages-time', bid, int(nptime - ptime))
                p.execute()
1323300
private int checkAndGetTotalCount() throws IllegalStateException {
		int usedBuckets = 0;
		int totalCount = buckets[0].getCount();
		for (int i = 1; i <= bucketNb; i++) {
			int bucketCount = buckets[i].getCount();
			totalCount += bucketCount;
			if (bucketCount > 0) {
				usedBuckets++;
			}
		}
		totalCount += buckets[bucketNb + 1].getCount();
		if (usedBuckets < 3) {
			throw new IllegalStateException("Only " + usedBuckets + " buckets used, not enough for interpolation, consider reconfiguring min/max/nb");
		}
		return totalCount;
	}
1282060
def get_paginator(
        self,
        dataset,
        per_page,
        orphans=0,
        allow_empty_first_page=True,
        **kwargs
    ):
        """"""
        return IndefinitePaginator(
            dataset,
            per_page,
            orphans=orphans,
            allow_empty_first_page=allow_empty_first_page,
            **kwargs
        )
406703
def query_by_bucket(cls, bucket):
        """"""
        return cls.query.filter(cls.bucket_id == as_bucket_id(bucket))
484967
function paginate(reqOptions, link, memo) {
	const links = link.split(/,\s*/);
	let matches;
	links.some(function(link) {
		matches = link.trim().match(/<(.+)>;\s*rel="next"/);
		return matches !== null;
	});
	// End of pagination
	if(!matches) {
		return Promise.resolve(memo);
	}
	return new Promise(function(resolve, reject) {
		reqOptions.url = matches[1];
		request(reqOptions, function(err, res, body) {
			paginate(reqOptions, res.headers.link, memo.concat(JSON.parse(body))).then(resolve);
		});
	});
}
290538
def get_bucket():
    
    args = parser.parse_args()

    bucket = s3_bucket(args.aws_access_key_id, args.aws_secret_access_key, args.bucket_name)
    for b in bucket.list():
        print(''.join([i if ord(i) < 128 else ' ' for i in b.name]))
637801
def local_init(bucket_count, bucket_width, start_priority)
      @width = bucket_width
      old = @buckets
      @buckets = if @cached_buckets == nil
        Array.new(bucket_count) { [] }
      else
        n = @cached_buckets.size
        if bucket_count < n
          # shrink the array
          @cached_buckets.slice!(bucket_count, n)
        else
          # expand the array
          @cached_buckets.fill(n, bucket_count - n) { [] }
        end
        @cached_buckets
      end
      @cached_buckets = old

      @last_priority = start_priority
      i = start_priority / bucket_width # virtual bucket
      @last_bucket = (i % bucket_count).to_i
      @bucket_top = (i+1) * bucket_width + 0.5 * bucket_width

      # set up queue size change thresholds
      @shrink_threshold = bucket_count / 2 - 2
      @expand_threshold = 2 * bucket_count
    end
828633
def get_bucket_list():
    
    args = parser.parse_args()
    for b in s3_conn(args.aws_access_key_id, args.aws_secret_access_key).get_all_buckets():
        print(''.join([i if ord(i) < 128 else ' ' for i in b.name]))
725038
def buckets(self, start, end):
    '''
    
    '''
    start_bucket = self.to_bucket(start)
    end_bucket = self.to_bucket(end)
    return range(start_bucket, end_bucket+1)
720013
def _list_paths(self, bucket, prefix):
        
        s3 = self.s3
        kwargs = {"Bucket": bucket, "Prefix": prefix}
        if self.list_objects:
            list_objects_api = "list_objects"
        else:
            list_objects_api = "list_objects_v2"
        paginator = s3.get_paginator(list_objects_api)
        for page in paginator.paginate(**kwargs):
            contents = page.get("Contents", None)
            if not contents:
                continue
            for item in contents:
                yield item["Key"]
1025107
def will_paginate(collection_or_options = nil, options = {})
      if collection_or_options.is_a? Hash
        options, collection_or_options = collection_or_options, nil
      end
      unless options[:renderer]
        options = options.merge :renderer => MaterializePagination::Rails
      end
      super *[collection_or_options, options].compact
    end
984736
def paginate(self, request, collection):
        
        p = Paginator(request, self, collection)
        return p.paginator and p or UpdatedList(collection)
1360125
function sort(array, bucketSize) {
  if (array.length === 0) {
    return array;
  }

  // Determine minimum and maximum values
  var i;
  var minValue = array[0];
  var maxValue = array[0];
  for (i = 1; i < array.length; i++) {
    if (array[i] < minValue) {
      minValue = array[i];
    } else if (array[i] > maxValue) {
      maxValue = array[i];
    }
  }

  // Initialise buckets
  var DEFAULT_BUCKET_SIZE = 5;
  bucketSize = bucketSize || DEFAULT_BUCKET_SIZE;
  var bucketCount = Math.floor((maxValue - minValue) / bucketSize) + 1;
  var buckets = new Array(bucketCount);
  for (i = 0; i < buckets.length; i++) {
    buckets[i] = [];
  }

  // Distribute input array values into buckets
  for (i = 0; i < array.length; i++) {
    buckets[Math.floor((array[i] - minValue) / bucketSize)].push(array[i]);
  }

  // Sort buckets and place back into input array
  array.length = 0;
  for (i = 0; i < buckets.length; i++) {
    insertionSort(buckets[i]);
    for (var j = 0; j < buckets[i].length; j++) {
      array.push(buckets[i][j]);
    }
  }

  return array;
}
1071482
def all(self, endpoint, *args, **kwargs):
        
        # 1. Initialize the pagination parameters.
        kwargs.setdefault('params', {})['offset'] = 0
        kwargs.setdefault('params', {})['limit'] = self.limit
        kwargs['__method__'] = 'get'
        # 2. Create an initial paginated request.
        payload = self.request(endpoint, *args, **kwargs)
        has_next = payload.get('result', {}).setdefault(
            'meta', {'next': None}
        )['next']
        # 3. Loop until the end
        while has_next:
            # 4. Increment the offset
            kwargs['params']['offset'] += self.limit
            # 5. Query again
            _payload = self.request(endpoint, *args, **kwargs)
            # 6. Add the paginated data to the global one
            payload['result']['data'].extend(_payload['result']['data'])
            # 7. Compute has_next
            has_next = _payload['result']['meta']['next']
        del payload['result']['meta']
        return payload
1061736
public static <T> void bucketSort(final T[] a, final int fromIndex, final int toIndex, final Comparator<? super T> cmp) {
        Array.bucketSort(a, fromIndex, toIndex, cmp);
    }
325622
def list_buckets(self):
        
        details = self._details(
            method=b"GET",
            url_context=self._url_context(),
        )
        query = self._query_factory(details)
        d = self._submit(query)
        d.addCallback(self._parse_list_buckets)
        return d
433014
def with_pagination(&block)
      results = yield
      while next_ref = next_link_ref(@client.last_response.headers["link"])
        uri = URI.parse(next_ref.href)
        next_page = uri.query.split("=")[1]
        results.push(yield page: next_page)
      end
      results.flatten
    end