/* Optimize SelectLimit() by using OCIFetch() instead of OCIFetchInto()
186841
function GetArrayLimit($nrows,$offset=-1)
	{
		if ($offset <= 0) {
			$arr = $this->GetArray($nrows);
			return $arr;
		}
		for ($i=1; $i < $offset; $i++)
			if (!@OCIFetch($this->_queryID)) {
				$arr = array();
				return $arr;
			}
		$ret = @oci_fetch_array($this->_queryID,$this->fetchMode);
		if ($ret === false) {
			$arr = array();
			return $arr;
		}
		$this->fields = $ret;
		$this->_updatefields();
		$results = array();
		$cnt = 0;
		while (!$this->EOF && $nrows != $cnt) {
			$results[$cnt++] = $this->fields;
			$this->MoveNext();
		}

		return $results;
	}
574326
@GuardedBy("mLock")
  private void updateFileCacheSizeLimit() {
    // Test if mCacheSizeLimit can be set to the high limit
    boolean isAvailableSpaceLowerThanHighLimit;
    StatFsHelper.StorageType storageType =
        mStorage.isExternal()
            ? StatFsHelper.StorageType.EXTERNAL
            : StatFsHelper.StorageType.INTERNAL;
    isAvailableSpaceLowerThanHighLimit =
        mStatFsHelper.testLowDiskSpace(
            storageType,
            mDefaultCacheSizeLimit - mCacheStats.getSize());
    if (isAvailableSpaceLowerThanHighLimit) {
      mCacheSizeLimit = mLowDiskSpaceCacheSizeLimit;
    } else {
      mCacheSizeLimit = mDefaultCacheSizeLimit;
    }
  }
991563
public void setLimits(int softLimit, int hardLimit) {
    if ((softLimit > 0 && hardLimit > softLimit) || (softLimit == 0 && hardLimit == 0)) {
      this.softLimit = softLimit;
      this.hardLimit = hardLimit;
      garbageCollect();
    } else {
      throw new IllegalArgumentException();
    }
  }
1091785
public TableOperation createLimitWithFetch(int fetch, TableOperation child) {
		SortTableOperation previousSort = validateAndGetChildSort(child);

		if (fetch < 0) {
			throw new ValidationException("Fetch should be greater or equal 0");
		}

		int offset = Math.max(previousSort.getOffset(), 0);

		return new SortTableOperation(previousSort.getOrder(), previousSort.getChild(), offset, fetch);
	}
1064197
@Deprecated
    protected int handleGetLimit(int field, int limitType) {
        if (isAmeteAlemEra() && field == ERA) {
            return 0; // Only one era in this mode, era is always 0
        }
        return super.handleGetLimit(field, limitType);
    }
36158
private boolean incSlotLimit(JobInfo info, TaskType type, LimitType limit) {
    switch (limit) {
      case MIN:
        if (type == TaskType.MAP) {
          if (info.minMaps < runnableTasks(info, type)) {
            info.minMaps += 1;
            return true;
          }
        } else {
          if (info.minReduces < runnableTasks(info, type)) {
            info.minReduces += 1;
            return true;
          }
        }
        return false;
      case MAX:
        if (type == TaskType.MAP) {
          if (info.maxMaps < runnableTasks(info, type)) {
            info.maxMaps += 1;
            return true;
          }
        } else {
          if (info.maxReduces < runnableTasks(info, type)) {
            info.maxReduces += 1;
            return true;
          }
        }
        return false;
    }
    // Never come here
    return false;
  }
155985
protected function _setLimit()
    {
        if (
            is_null($this->_sql->getLimit()) ||
            intval($this->_sql->getLimit()) < 1
        ) {
            return $this;
        }

        if ($this->_sql->getOffset() > 0) {
            return $this->_setLimitWithOffset();
        }
        return  $this->_setSimpleLimit();
    }
1250660
public AbucoinsFills getAbucoinsFills(String afterCursor, Integer limit) throws IOException {
    try {
      AbucoinsFills fills =
          abucoinsAuthenticated.getFills(
              exchange.getExchangeSpecification().getApiKey(),
              signatureCreator,
              exchange.getExchangeSpecification().getPassword(),
              timestamp(),
              afterCursor,
              limit);
      return fills;
    } catch (HttpStatusIOException initialException) {
      // in case of error Abucoins returns HTTP status 200 with a single property JSON
      try {
        AbucoinsError error =
            ObjectMapperHelper.readValue(initialException.getHttpBody(), AbucoinsError.class);
        throw new ExchangeException(error.getMessage());
      } catch (IOException finalException) {
        throw new ExportException(
            "Response neither expected DTO nor error message", finalException);
      }
    }
  }
159486
private void onLimit(StringBuilder builder)
    {
        builder.append(CQLTranslator.LIMIT);
        builder.append(this.maxResult);
    }
740211
int refreshAndGetMax() {
		int max = 0;

		for (ResultSubpartition part : partition.getAllPartitions()) {
			int size = part.unsynchronizedGetNumberOfQueuedBuffers();
			max = Math.max(max, size);
		}

		return max;
	}
969962
def select(read_streams, write_streams, timeout=0):
    

    exception_streams = []

    try:
        return builtin_select.select(
            read_streams,
            write_streams,
            exception_streams,
            timeout,
        )[0:2]
    except builtin_select.error as e:
        # POSIX signals interrupt select()
        no = e.errno if six.PY3 else e[0]
        if no == errno.EINTR:
            return ([], [])
        else:
            raise e
716766
function SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false, $secs=0)
	{
		$nrows = (integer) $nrows;
		$offset = (integer) $offset;
		$str = 'SELECT ';
		if ($nrows >= 0) $str .= "FIRST $nrows ";
		$str .=($offset>=0) ? "SKIP $offset " : '';

		$sql = preg_replace('/^[ \t]*select/i',$str,$sql);
		if ($secs)
			$rs = $this->CacheExecute($secs,$sql,$inputarr);
		else
			$rs = $this->Execute($sql,$inputarr);

		return $rs;
	}
1339847
public SearchOptions setLimit(int limit) {
    if (limit <= 0) {
      this.limit = MAX_LIMIT;
    } else {
      this.limit = Math.min(limit, MAX_LIMIT);
    }
    return this;
  }
125635
private function getLimit(?int $limit = null): ?int
    {
        if (is_int($limit) && $limit >= 0) {
            return $limit;
        }

        return null;
    }
544168
public OutputContext getSlice(int limit) {
        List<ByteBuffer> newBufs = new LinkedList<ByteBuffer>();
        ByteBuffer buf = ByteBuffer.allocate(limit);
        Iterator<ByteBuffer> iter = buffers.iterator();

        while (iter.hasNext() && buf.position() < buf.limit()) {
            ByteBuffer cur = iter.next();
            int diff = buf.limit() - buf.position();
            if (diff > cur.limit()) {
                buf.put(cur);
                iter.remove();
            } else {
                ByteBuffer slice = cur.duplicate();
                slice.limit(diff);
                buf.put(slice);
            }
        }
        return new OutputContext(newBufs);
    }
200371
def get_select(self, ret_dict=False, qnodes=None, memory_policy=None):
        
        hw, mem_per_proc = self.hw, int(self.mem_per_proc)
        #dist = self.distribute(self.mpi_procs, self.omp_threads, mem_per_proc)
        """
        if self.pure_mpi:
            num_nodes, rest_cores = hw.divmod_node(self.mpi_procs, self.omp_threads)

            if num_nodes == 0:
                logger.info("IN_CORE PURE MPI: %s" % self.run_info)
                chunks = 1
                ncpus = rest_cores
                mpiprocs = rest_cores
                mem = mem_per_proc * ncpus
                ompthreads = 1

            elif rest_cores == 0:
                # Can allocate entire nodes because self.mpi_procs is divisible by cores_per_node.
                logger.info("PURE MPI run commensurate with cores_per_node %s" % self.run_info)
                chunks = num_nodes
                ncpus = hw.cores_per_node
                mpiprocs = hw.cores_per_node
                mem = ncpus * mem_per_proc
                ompthreads = 1

            else:
                logger.info("OUT-OF-CORE PURE MPI (not commensurate with cores_per_node): %s" % self.run_info)
                chunks = self.mpi_procs
                ncpus = 1
                mpiprocs = 1
                mem = mem_per_proc
                ompthreads = 1

        elif self.pure_omp:
            # Pure OMP run.
            logger.info("PURE OPENMP run: %s" % self.run_info)
            assert hw.can_use_omp_threads(self.omp_threads)
            chunks = 1
            ncpus = self.omp_threads
            mpiprocs = 1
            mem = mem_per_proc
            ompthreads = self.omp_threads

        elif self.hybrid_mpi_omp:
            assert hw.can_use_omp_threads(self.omp_threads)
            num_nodes, rest_cores = hw.divmod_node(self.mpi_procs, self.omp_threads)
            #print(num_nodes, rest_cores)
            # TODO: test this

            if rest_cores == 0 or num_nodes == 0:
                logger.info("HYBRID MPI-OPENMP run, perfectly divisible among nodes: %s" % self.run_info)
                chunks = max(num_nodes, 1)
                mpiprocs = self.mpi_procs // chunks

                chunks = chunks
                ncpus = mpiprocs * self.omp_threads
                mpiprocs = mpiprocs
                mem = mpiprocs * mem_per_proc
                ompthreads = self.omp_threads

            else:
                logger.info("HYBRID MPI-OPENMP, NOT commensurate with nodes: %s" % self.run_info)
                chunks=self.mpi_procs
                ncpus=self.omp_threads
                mpiprocs=1
                mem= mem_per_proc
                ompthreads=self.omp_threads

        else:
            raise RuntimeError("You should not be here")
        """
        if memory_policy is None:
            memory_policy = self.memory_policy
        if qnodes is None:
            qnodes = self.qnodes
        else:
            if qnodes not in ["standard", "shared", "exclusive"]:
                raise ValueError("Nodes must be either in standard, shared or exclusive mode "
                                 "while qnodes parameter was {}".format(self.qnodes))
        if qnodes == "standard":
            return self._get_select_standard(ret_dict=ret_dict, memory_policy=memory_policy)
        else:
            return self._get_select_with_master_mem_overhead(ret_dict=ret_dict, qnodes=qnodes,
                                                             memory_policy=memory_policy)
756590
private boolean eligibleToFetch(List<String> columnsToSelect, String columnName)
    {
        return (columnsToSelect != null && !columnsToSelect.isEmpty() && columnsToSelect.contains(columnName))
                || (columnsToSelect == null || columnsToSelect.isEmpty());
    }