Encodes a block of numbers to a VLQ-sequence

@param int[]|int $numbers
a block of numbers of a single number
@return int[]
161375
public function encode($numbers)
    {
        if (!is_array($numbers)) {
            $numbers = [$numbers];
        }
        if ($this->signed) {
            $numbers = Signed::encodeBlock($numbers);
        }
        $digits = [];
        $bits = $this->bits;
        $cBit = $this->cBit;
        foreach ($numbers as $number) {
            do {
                $digit = ($number % $this->cBit);
                $number >>= $bits;
                $continue = ($number > 0);
                if ($continue) {
                    $digit += $cBit;
                }
                $digits[] = $digit;
            } while ($continue);
        }
        return $digits;
    }
328637
protected function buildElementsByBlock($elements)
    {
        if (empty($elements)) {
            return $elements;
        }

        $output = [];
        foreach ($elements as $element) {
            $output[$element->block_key][] = $element;
        }

        return $output;
    }
591650
public function sequence(array $conditions) {
      $range = new Collection();
      foreach ($conditions as $value) {
        $range[] = $this->checkFromSequence($value);
      }

      return $range;
    }
587278
public function expandBlocks($blocks){

        $decoded = array();
        foreach($blocks as $blockName=>$block){
            $bytes = new GifByteStream($block);
            if(false !== strpos($blockName, 'header')){
                $part = $bytes->bite(3);
                $decoded['signature'] = $this->_hexToAscii($part);
                $part = $bytes->bite(3);
                $decoded['version'] = $this->_hexToAscii($part);
            } else if(false !== strpos($blockName, 'logicalScreenDescriptor')){
                $part = $bytes->bite(2);
                $decoded['canvasWidth'] = hexdec($this->_switchEndian($part));
                $part = $bytes->bite(2);
                $decoded['canvasHeight'] = hexdec($this->_switchEndian($part));
                $part = $bytes->bite(1);
                $bin = $this->_fixSize($this->_hexToBin($part), 8); // Make sure len is correct
                $decoded['globalColorTableFlag'] = bindec(substr($bin, 0 ,1));
                $decoded['colorResolution'] = bindec(substr($bin, 1 ,3));
                $decoded['sortFlag'] = bindec(substr($bin, 4 ,1));
                $decoded['sizeOfGlobalColorTable'] = bindec(substr($bin, 5 ,3));
                $part = $bytes->bite(1);
                $decoded['backgroundColorIndex'] = hexdec($part);
                $part = $bytes->bite(1);
                $decoded['pixelAspectRatio'] = hexdec($part);

            } else if(false !== strpos($blockName, 'globalColorTable')){
                $decoded['globalColorTable'] = $block;
            } else if(false !== strpos($blockName, 'applicationExtension')){
                $index = explode('-', $blockName, 2);
                $index = $index[1];

                $bytes->next(2); // Skip ext intro and label: 21 ff
                $appNameSize = $bytes->bite(1); // 0x0b or 11 according to spec but we check anyways
                $appNameSize = hexdec($appNameSize);
                $appName = $this->_hexToAscii($bytes->bite($appNameSize));
                $subBlocks = array();
                while (!$bytes->isEnd()) { // loop thru all app sub blocks
                    $nextSize = $bytes->bite(1);
                    if($nextSize !== '00'){
                        $size = hexdec($nextSize);
                        $subBlocks[] = $bytes->bite($size);

                    }
                }
                if($appName==='NETSCAPE2.0'){
                    $decoded['applicationExtension'][$index]['appId'] = 'NETSCAPE';
                    $decoded['applicationExtension'][$index]['appCode'] = '2.0';
                    $decoded['applicationExtension'][$index]['subBlocks'] = $subBlocks;
                    $decoded['loopCount'] = hexdec($this->_switchEndian(substr($subBlocks[0], 2, 4)));
                } else {
                    $decoded['applicationExtension'][$index]['appId'] = substr($appName, 0, 8);
                    $decoded['applicationExtension'][$index]['appCode'] = substr($appName, 8, 3);
                    $decoded['applicationExtension'][$index]['subBlocks'] = $subBlocks;
                }
            } else if(false !== strpos($blockName, 'graphicControlExtension')) {
                $index = explode('-', $blockName, 2);
                $index = $index[1];

                $bytes->next(3); // Skip ext intro, label, and block size which is always 4: 21 f9 04
                $part = $bytes->bite(1); // packed field
                $bin = $this->_fixSize($this->_hexToBin($part), 8); // Make sure len is correct
                $decoded['frames'][$index]['disposalMethod'] = bindec(substr($bin, 3 ,3));
                $decoded['frames'][$index]['userInputFlag'] = bindec(substr($bin, 6 ,1));
                $decoded['frames'][$index]['transparentColorFlag'] = bindec(substr($bin, 7 ,1));
                $part = $bytes->bite(2);
                $decoded['frames'][$index]['delayTime'] = hexdec($this->_switchEndian($part));
                $part = $bytes->bite(1);
                $decoded['frames'][$index]['transparentColorIndex'] = hexdec($part);
            } else if(false !== strpos($blockName, 'imageDescriptor')) {
                $index = explode('-', $blockName, 2);
                $index = $index[1];

                $bytes->next(1); // skip separator: 2c
                $part                                               = $bytes->bite(2);
                $decoded['frames'][$index]['imageLeft']             = hexdec($this->_switchEndian($part));
                $part                                               = $bytes->bite(2);
                $decoded['frames'][$index]['imageTop']              = hexdec($this->_switchEndian($part));
                $part                                               = $bytes->bite(2);
                $decoded['frames'][$index]['imageWidth']            = hexdec($this->_switchEndian($part));
                $part                                               = $bytes->bite(2);
                $decoded['frames'][$index]['imageHeight']           = hexdec($this->_switchEndian($part));
                $part                                               = $bytes->bite(1); // packed field
                $bin                                                = $this->_fixSize($this->_hexToBin($part),
                    8);
                $decoded['frames'][$index]['localColorTableFlag']   = bindec(substr($bin, 0, 1));
                $decoded['frames'][$index]['interlaceFlag']         = bindec(substr($bin, 1, 1));
                $decoded['frames'][$index]['sortFlag']              = bindec(substr($bin, 2, 1));
                $decoded['frames'][$index]['sizeOfLocalColorTable'] = bindec(substr($bin, 5, 3));
            } else if(false !== strpos($blockName, 'localColorTable')){
                $index = explode('-', $blockName, 2);
                $index = $index[1];
                $decoded['frames'][$index]['localColorTable'] = $block;
            } else if(false !== strpos($blockName, 'imageData')) {
                $index = explode('-', $blockName, 2);
                $index = $index[1];

                $decoded['frames'][$index]['imageData'] = $block;
            } else if($blockName === 'trailer') {
                $decoded['trailer'] = $block;
            }
            unset($bytes);
        }

        return $decoded;
    }
164800
public function passStatementBlock(array $statements)
    {
        foreach ($statements as $statement) {
            switch ($statement['type']) {
                case 'let':
                    $this->passLetStatement($statement);
                    break;

                case 'echo':
                    if (isset($statement['expressions'])) {
                        foreach ($statement['expressions'] as $expr) {
                            $this->passExpression($expr);
                        }
                    }
                    break;

                case 'declare':
                    $this->declareVariables($statement);
                    break;

                case 'if':
                    if (isset($statement['expr'])) {
                        $this->passExpression($statement['expr']);
                    }
                    if (isset($statement['statements'])) {
                        $this->passStatementBlock($statement['statements']);
                    }
                    if (isset($statement['else_statements'])) {
                        $this->passStatementBlock($statement['else_statements']);
                    }
                    if (isset($statement['elseif_statements'])) {
                        $this->passStatementBlock($statement['elseif_statements']);
                    }
                    break;

                case 'switch':
                    if (isset($statement['expr'])) {
                        $this->passExpression($statement['expr']);
                    }
                    if (isset($statement['clauses'])) {
                        foreach ($statement['clauses'] as $clause) {
                            if (isset($clause['expr'])) {
                                $this->passExpression($clause['expr']);
                            }
                            if (isset($clause['statements'])) {
                                $this->passStatementBlock($clause['statements']);
                            }
                        }
                    }
                    break;

                case 'while':
                case 'do-while':
                    if (isset($statement['expr'])) {
                        $this->passExpression($statement['expr']);
                    }
                    if (isset($statement['statements'])) {
                        $this->passStatementBlock($statement['statements']);
                    }
                    break;

                case 'for':
                    if (isset($statement['expr'])) {
                        $this->passExpression($statement['expr']);
                    }
                    if (isset($statement['value'])) {
                        $this->increaseMutations($statement['value']);
                    }
                    if (isset($statement['key'])) {
                        $this->increaseMutations($statement['key']);
                    }
                    if (isset($statement['statements'])) {
                        $this->passStatementBlock($statement['statements']);
                    }
                    break;

                case 'return':
                    if (isset($statement['expr'])) {
                        $this->passExpression($statement['expr']);
                    }
                    break;

                case 'loop':
                    if (isset($statement['statements'])) {
                        $this->passStatementBlock($statement['statements']);
                    }
                    break;

                case 'try-catch':
                    if (isset($statement['statements'])) {
                        $this->passStatementBlock($statement['statements']);
                    }
                    if (isset($statement['catches'])) {
                        foreach ($statement['catches'] as $catch) {
                            if (isset($catch['variable'])) {
                                $this->increaseMutations($catch['variable']['value']);
                            }
                            if (isset($catch['statements'])) {
                                $this->passStatementBlock($catch['statements']);
                            }
                        }
                    }
                    break;

                case 'throw':
                    if (isset($statement['expr'])) {
                        $this->passExpression($statement['expr']);
                    }
                    break;

                case 'fetch':
                    $this->passExpression($statement['expr']);
                    break;

                case 'mcall':
                case 'scall':
                case 'fcall':
                case 'require':
                    $this->passCall($statement['expr']);
                    break;

                case 'unset':
                    if ('array-access' == $statement['expr']['type']) {
                        if ('variable' == $statement['expr']['left']['type']) {
                            $this->increaseMutations($statement['expr']['left']['value']);
                        }
                    } else {
                        if ('list' == $statement['expr']['type']) {
                            if ('array-access' == $statement['expr']['left']['type']) {
                                if ('variable' == $statement['expr']['left']['left']['type']) {
                                    $this->increaseMutations($statement['expr']['left']['left']['value']);
                                }
                            }
                        }
                    }
                    break;

                case 'break':
                case 'continue':
                case 'empty':
                case 'cblock':
                case 'comment':
                    break;

                default:
                    echo 'MutateGathererPassStatement=', $statement['type'], PHP_EOL;
            }
        }
    }
1217380
public function convertLinesToCode(array $lines) {
        if (0 === count($lines)) {
            return '';
        }

        if (0 !== strlen($this->getTemplate()->getIndentationPrefix())) {
            foreach ($lines as $lineNumber => $line) {
                if (null === $line) {
                    unset($lines[$lineNumber]);
                } elseif ('' === trim($line)) {
                    $lines[$lineNumber] = '';
                }
            }
        }

        return implode($this->getTemplate()->getEol(), $lines) . $this->getTemplate()->getEol();
    }
81450
private function encodeMulticall(array $requests) {

        $composed_requests = [];

    	$this->logger->debug("Performing an XML multicall");

    	$this->logger->debug("Data dump before encoding", $requests);

        foreach ($requests as $request) {

            $composed_requests[] = [
                $request->getMethod(),
                $request->getParameters()
            ];

            foreach ( $request->getSpecialTypes() as $key => $value ) {
                $this->encoder->setValueType($key, $value);
            }

        }

        try {

            $encoded_requests = $this->encoder
                ->setEncoding($this->getEncoding())
                ->encodeMulticall($composed_requests);

        } catch (XmlrpcException $xe) {

            throw $xe;

        }

        $this->logger->debug("Data dump after encoding: ".$encoded_requests);

        return $encoded_requests;

    }
16892
private function createEncodings($points, $dists)
    {
        $plat = 0;
        $plng = 0;
        $encoded_points = '';

        for ($i = 0; $i < count($points); $i++) {
            if (isset($dists[$i]) || $i == 0 || $i == count($points) - 1) {
                $point = $points[$i];
                $lat = $point[0];
                $lng = $point[1];
                $late5 = floor($lat * 1e5);
                $lnge5 = floor($lng * 1e5);
                $dlat = $late5 - $plat;
                $dlng = $lnge5 - $plng;
                $plat = $late5;
                $plng = $lnge5;
                $encoded_points .= $this->encodeSignedNumber($dlat) . $this->encodeSignedNumber($dlng);
            }
        }
        return $encoded_points;
    }
1318351
protected function encode(array $messages)
    {
        if ($this->encode) {
            foreach ($messages as $key => $message) {
                if (($form = mb_detect_encoding($message)) != self::TARGET_ENCODING) {
                    $messages[$key] = mb_convert_encoding($message, self::TARGET_ENCODING, $form);
                }
            }
        }

        return $messages;
    }
205621
public static function withKeys($records, $keys)
    {
        if (!self::iterable($records)) {
            return array();
        }
        
        $out = array();
        foreach ($records as $n => $record) {
            if (!self::iterable($record)) {
                $out[$n] = $record;
                continue;
            }
            $out[$n] = array();
            
            foreach ($record as $k => $v) {
                if (!in_array($k, $keys)) {
                    continue;
                }
                $out[$n][$k] = $v;
            }
        }
        return $out;
    }
356840
public function getDigits(array $decimals)
    {
        $digits = [];

        foreach ($decimals as $decimal) {
            $digits[] = $this->digits->getDigit($decimal);
        }

        return $digits;
    }
1305444
public function writeBlocks( $blocks )
	{
		foreach( $blocks as $name => $content )
		{
			$list[]	= str_replace( "{#name#}", $name, $this->patternSection );
			$list[]	= $content;
			$list[]	= "";
		}
		$file	= new FS_File_Writer( $this->fileName );
		return $file->writeArray( $list );
	}
441564
private String _encode(long... numbers) {
        long numberHashInt = 0;
        for (int i = 0; i < numbers.length; i++) {
            numberHashInt += (numbers[i] % (i + 100));
        }
        String     alphabet = this.alphabet;
        final char ret      = alphabet.charAt((int) (numberHashInt % alphabet.length()));

        long                num;
        long                sepsIndex, guardIndex;
        String              buffer;
        final StringBuilder ret_strB = new StringBuilder(this.minHashLength);
        ret_strB.append(ret);
        char guard;

        for (int i = 0; i < numbers.length; i++) {
            num = numbers[i];
            buffer = ret + this.salt + alphabet;

            alphabet = Hashids.consistentShuffle(alphabet, buffer.substring(0, alphabet.length()));
            final String last = Hashids.hash(num, alphabet);

            ret_strB.append(last);

            if (i + 1 < numbers.length) {
                if (last.length() > 0) {
                    num %= (last.charAt(0) + i);
                    sepsIndex = (int) (num % this.seps.length());
                } else {
                    sepsIndex = 0;
                }
                ret_strB.append(this.seps.charAt((int) sepsIndex));
            }
        }

        String ret_str = ret_strB.toString();
        if (ret_str.length() < this.minHashLength) {
            guardIndex = (numberHashInt + (ret_str.charAt(0))) % this.guards.length();
            guard = this.guards.charAt((int) guardIndex);

            ret_str = guard + ret_str;

            if (ret_str.length() < this.minHashLength) {
                guardIndex = (numberHashInt + (ret_str.charAt(2))) % this.guards.length();
                guard = this.guards.charAt((int) guardIndex);

                ret_str += guard;
            }
        }

        final int halfLen = alphabet.length() / 2;
        while (ret_str.length() < this.minHashLength) {
            alphabet = Hashids.consistentShuffle(alphabet, alphabet);
            ret_str = alphabet.substring(halfLen) + ret_str + alphabet.substring(0, halfLen);
            final int excess = ret_str.length() - this.minHashLength;
            if (excess > 0) {
                final int start_pos = excess / 2;
                ret_str = ret_str.substring(start_pos, start_pos + this.minHashLength);
            }
        }

        return ret_str;
    }
1216710
def vlq_encode(ary)
      result = []
      ary.each do |n|
        vlq = n < 0 ? ((-n) << 1) + 1 : n << 1
        loop do
          digit  = vlq & VLQ_BASE_MASK
          vlq  >>= VLQ_BASE_SHIFT
          digit |= VLQ_CONTINUATION_BIT if vlq > 0
          result << BASE64_DIGITS[digit]

          break unless vlq > 0
        end
      end
      result.join
    end
1266332
protected function getSeqLookup($sequences)
	{
		// First pass, create a lookup of the keys.
		$lookup = array();

		foreach ($sequences as $seq)
		{
			if ($seq instanceof \SimpleXMLElement)
			{
				$sName = (string) $seq['Name'];
			}
			else
			{
				$sName = $seq->Name;
			}

			if (empty($lookup[$sName]))
			{
				$lookup[$sName] = array();
			}

			$lookup[$sName][] = $seq;
		}

		return $lookup;
	}
4053
public function base64Encode($number)
    {
        if ($number < 0 || $number > 63) {
            throw new \Exception(sprintf('Invalid number "%s" given. Must be between 0 and 63.', $number));
        }

        return $this->intToCharMap[$number];
    }
537615
public static function numericOptions($integers): array
    {
        $array = [];
        foreach ($integers as $integer) {
            if ($integer === -1) {
                $array[$integer] = I18N::translate('All');
            } else {
                $array[$integer] = I18N::number($integer);
            }
        }

        return $array;
    }