当前位置: 首页>>代码示例>>PHP>>正文


PHP lookupType函数代码示例

本文整理汇总了PHP中lookupType函数的典型用法代码示例。如果您正苦于以下问题:PHP lookupType函数的具体用法?PHP lookupType怎么用?PHP lookupType使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了lookupType函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: CreateView

function CreateView($args, $targs)
{
    grokit_assert(\count($args) == 1, 'CreateView supports exactly 1 input');
    $type = $args[0];
    grokit_assert($type->is('array'), 'CreateView cannot create view on non-array type');
    $innerType = $type->get('type');
    $size = $type->get('size');
    $viewType = lookupType('BASE::FixedArrayView', ['type' => $innerType, 'size' => $size]);
    $funcname = generate_name('CreateView_');
    ?>

<?php 
    echo $viewType;
    ?>
 <?php 
    echo $funcname;
    ?>
( const <?php 
    echo $type;
    ?>
 &array ) {
	return <?php 
    echo $viewType;
    ?>
(array.data());
}

<?php 
    return ['kind' => 'FUNCTION', 'name' => $funcname, 'input' => $args, 'result' => $viewType, 'deterministic' => false];
}
开发者ID:gokulp,项目名称:grokit,代码行数:30,代码来源:CreateView.h.php

示例2: _defineStdMathFunction

function _defineStdMathFunction($name, $args, $ret, $lib)
{
    $f = function () use($name, $args, $ret, $lib) {
        $inputs = [];
        $count = 0;
        foreach ($args as $arg) {
            $inputs['arg' . $count] = lookupType($arg);
            $count += 1;
        }
        $retType = lookupType($ret);
        $hash = \grokit\hashComplex(['BASE::' . $name, $args, $ret]);
        ?>
inline <?php 
        echo $retType;
        ?>
 <?php 
        echo $name;
        ?>
( <?php 
        echo typed_args($inputs);
        ?>
 ) {
    return std::<?php 
        echo $name;
        ?>
(<?php 
        echo args($inputs);
        ?>
);
}
<?php 
        return ['kind' => 'FUNCTION', 'name' => $name, 'input' => $inputs, 'result' => $retType, 'deterministic' => true, 'system_headers' => $lib, 'hash' => $hash];
    };
    declareFunction($name, $args, $f);
}
开发者ID:gokulp,项目名称:grokit,代码行数:35,代码来源:Number-Funcs.h.php

示例3: Hash

function Hash($args, array $t_args = [])
{
    $funcName = generate_name('Hash_');
    $retType = lookupType('base::BIGINT');
    echo $retType;
    ?>
 <?php 
    echo $funcName;
    ?>
( <?php 
    echo const_typed_ref_args($args);
    ?>
 ) {
    uint64_t hashVal = H_b;
<?php 
    foreach ($args as $name => $type) {
        ?>
    hashVal = CongruentHash(<?php 
        echo $name;
        ?>
, hashVal);
<?php 
    }
    // foreach argument
    ?>
    return static_cast<<?php 
    echo $retType;
    ?>
>(hashVal);
}
<?php 
    return ['kind' => 'FUNCTION', 'name' => $funcName, 'result' => $retType, 'system_headers' => ['cinttypes'], 'user_headers' => ['HashFunctions.h'], 'deterministic' => true];
}
开发者ID:gokulp,项目名称:grokit,代码行数:33,代码来源:Hash-Funcs.h.php

示例4: type

 public function type()
 {
     if (!is_null($this->type)) {
         return lookupType($this->type->name(), $this->type->template_args());
     }
     if (is_null($this->type_ast)) {
         return null;
     }
     return parseType($this->type_ast);
 }
开发者ID:gokulp,项目名称:grokit,代码行数:10,代码来源:grokit_attman.php

示例5: Contains

function Contains($args, $targs)
{
    grokit_assert(\count($args) == 1, 'Contains supports exactly 1 input, ' . \count($args) . ' given');
    grokit_assert(array_key_exists('values', $targs), 'Contains() requires a "values" template argument');
    $inputName = 'contains_input';
    $inputType = $args[0];
    $boolType = lookupType('base::bool');
    $typename = generate_name('_ContainsType');
    $funcname = generate_name('Contains');
    $sys_headers = ['cstddef'];
    $use_mct = get_default($targs, 'use.mct', false);
    if ($use_mct) {
        $sys_headers[] = 'mct/closed-hash-set.hpp';
        $setType = 'mct::closed_hash_set<' . $inputType . ', KeyHash>';
    } else {
        $sys_headers[] = 'unordered_set';
        $setType = 'std::unordered_set<' . $inputType . ', KeyHash>';
    }
    $values = $targs['values'];
    grokit_assert(is_array($values), 'Contains(): values argument must be an array of strings');
    $quotedValues = [];
    $escapeChars = "\"'\n\r\t\\";
    foreach ($values as $index => $val) {
        grokit_assert(is_string($val), "Contains(): Value at index {$index} is not a string");
        $quotedValues[] = '"' . addcslashes($val, $escapeChars) . '"';
    }
    $nVals = \count($quotedValues);
    ?>

class <?php 
    echo $typename;
    ?>
 {
public:
	struct KeyHash {
		std::size_t operator () (const <?php 
    echo $inputType;
    ?>
 & val) const {
			return static_cast<std::size_t>(Hash(val));
		}
	};

	using Set = <?php 
    echo $setType;
    ?>
;

	// Singleton
	static const <?php 
    echo $typename;
    ?>
 instance;

private:
	static const char* str_values[<?php 
    echo $nVals;
    ?>
];

	Set values;

	<?php 
    echo $typename;
    ?>
():
		values()
	{
		<?php 
    echo $inputType;
    ?>
 temp;
		for( auto str : str_values ) {
			FromString(temp, str);
			values.insert(temp);
		}
	}

public:
	bool exists(const <?php 
    echo $inputType;
    ?>
 & <?php 
    echo $inputName;
    ?>
) const {
		return values.count(<?php 
    echo $inputName;
    ?>
) > 0;
	}
};

const <?php 
    echo $typename;
    ?>
 <?php 
    echo $typename;
    ?>
::instance;
//.........这里部分代码省略.........
开发者ID:gokulp,项目名称:grokit,代码行数:101,代码来源:Contains.h.php

示例6: BloomFilter

/**
 *  A GLA that estimates the cardinality of a dataset using a bloom filter of
 *  a configurable size.
 *
 *  Note: This filter has very high performance, so long as all of the states
 *  fit into cache, preferably L1 or L2, but L3 is also fine. Once the states
 *  are large enough that all of them cannot fit inside L3 cache at the same
 *  time, performance takes a nose dive (4x loss minimum).
 */
function BloomFilter(array $t_args, array $input, array $output)
{
    grokit_assert(\count($output) == 1, 'BloomFilter produces only 1 value, ' . \count($output) . ' outputs given.');
    $outputName = array_keys($output)[0];
    $outputType = array_get_index($output, 0);
    if (is_null($outputType)) {
        $outputType = lookupType('BASE::BIGINT');
    }
    $output[$outputName] = $outputType;
    grokit_assert($outputType->is('numeric'), 'BloomFilter output must be numeric!');
    $exp = get_first_key_default($t_args, ['exponent'], 16);
    grokit_assert(is_integer($exp), 'BloomFilter exponent must be an integer.');
    grokit_assert($exp > 0 && $exp < 64, 'BloomFilter exponent must be in range (0,64), ' . $exp . ' given.');
    $nullCheck = get_default($t_args, 'null.check', false);
    $nullable = [];
    if (is_bool($nullCheck)) {
        foreach ($input as $name => $type) {
            $nullable[$name] = $nullCheck;
        }
    } else {
        if (is_array($nullCheck)) {
            foreach ($input as $name => $type) {
                $nullable[$name] = false;
            }
            foreach ($nullCheck as $index => $n) {
                grokit_assert(is_string($n), 'BloomFilster null.check has invalid value at position ' . $index);
                grokit_assert(array_key_exists($n, $nullable), 'BloomFilster null.check has unknown input ' . $n . ' at position ' . $index);
                $nullable[$n] = true;
            }
        } else {
            grokit_error('BloomFilster null.check must be boolean or list of inputs to check for nulls');
        }
    }
    $debug = get_default($t_args, 'debug', 0);
    $bits = pow(2, $exp);
    $bytes = ceil($bits / 8.0);
    // Calculate the number of bits set for every possible value of a byte
    $nBits = [];
    for ($i = 0; $i < 256; $i++) {
        $n = $i;
        $b = 0;
        while ($n > 0) {
            $n &= $n - 1;
            $b++;
        }
        $nBits[$i] = $b;
    }
    $className = generate_name('BloomFilter');
    ?>
class <?php 
    echo $className;
    ?>
 {
    static constexpr size_t BITS = <?php 
    echo $bits;
    ?>
;
    static constexpr size_t BYTES = <?php 
    echo $bytes;
    ?>
;
    static constexpr size_t MASK = BITS - 1;
    static constexpr std::array<unsigned char, 256> BITS_SET = { <?php 
    echo implode(', ', $nBits);
    ?>
 };
    static constexpr std::array<unsigned char, 8> BIT_MASKS = {
        0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80
    };

    size_t count;

    std::array<unsigned char, BYTES> set;
    //unsigned char set[BYTES];
    //std::bitset<BITS> set;

public:
    <?php 
    echo $className;
    ?>
() : count(0), set() {
        for( size_t i = 0; i < BYTES; i++ ) { //>
            set[i] = 0;
        }
    }

    ~<?php 
    echo $className;
    ?>
() { }

//.........这里部分代码省略.........
开发者ID:gokulp,项目名称:grokit,代码行数:101,代码来源:BloomFilter.h.php

示例7: ExtremeTuples

function ExtremeTuples(array $t_args, array $inputs, array $outputs)
{
    $extremes = get_first_key($t_args, ['extremes']);
    $nExt = \count($extremes);
    grokit_assert($nExt > 0, 'No extremes specified for ExtremeTuples GLA.');
    if (\count($inputs) == 0) {
        grokit_assert(array_key_exists('inputs', $t_args), 'No arguments specified for ExtremeTuples GLA.');
        $count = 0;
        foreach ($t_args['inputs'] as $type) {
            if (is_identifier($type)) {
                $type = lookupType(strval($type));
            }
            grokit_assert(is_datatype($type), 'Only datatypes can be specified as inputs to ' . 'the ExtremeTuples GLA');
            $name = 'et_val' . $count;
            $inputs[$name] = $type;
        }
    }
    $outputMap = [];
    reset($outputs);
    foreach ($inputs as $name => $type) {
        $oKey = key($outputs);
        $outputs[$oKey] = $type;
        $outputMap[$oKey] = $name;
        next($outputs);
    }
    grokit_assert($nExt <= \count($inputs), 'There can not be more extreme values than there are inputs!');
    $mainAtts = [];
    $extraAtts = [];
    $minOpts = ['MIN', 'MINIMUM', '-', '<'];
    $maxOpts = ['MAX', 'MAXIMUM', '+', '>'];
    $inArrayCase = function ($needle, $haystack) {
        foreach ($haystack as $item) {
            if (strcasecmp($needle, $item) == 0) {
                return true;
            }
        }
        return false;
    };
    $minimum = [];
    foreach ($extremes as $name => $val) {
        grokit_assert(array_key_exists($name, $inputs), "ExtremeTuples: Expression with name " . $name . " specified as extreme not found in inputs");
    }
    foreach ($inputs as $name => $type) {
        if (array_key_exists($name, $extremes)) {
            $mainAtts[$name] = $type;
            if ($inArrayCase($extremes[$name], $minOpts)) {
                $minimum[$name] = true;
            } else {
                if ($inArrayCase($extremes[$name], $maxOpts)) {
                    $minimum[$name] = false;
                } else {
                    grokit_error('Unknown extreme type ' . $extremes[$name] . ' specified for ' . $name);
                }
            }
        } else {
            $extraAtts[$name] = $type;
        }
    }
    $debug = get_default($t_args, 'debug', 0);
    $className = generate_name('ExtremeTuples');
    ?>

class <?php 
    echo $className;
    ?>
 {

    struct Tuple {
<?php 
    foreach ($inputs as $name => $type) {
        ?>
        <?php 
        echo $type;
        ?>
 <?php 
        echo $name;
        ?>
;
<?php 
    }
    // foreach input
    ?>

        // Default Constructor, Copy Constructor, and Copy Assignment are all
        // default
        Tuple(void) = default;
        Tuple(const Tuple &) = default;
        Tuple & operator = (const Tuple &) = default;

        Tuple(<?php 
    echo array_template('const {val} & _{key}', ', ', $inputs);
    ?>
) :
            <?php 
    echo array_template('{key}(_{key})', ', ', $inputs);
    ?>

        { }

        // operator > means that this tuple is "better" than the other tuple.
//.........这里部分代码省略.........
开发者ID:gokulp,项目名称:grokit,代码行数:101,代码来源:ExtremeTuples.h.php

示例8: IsNull

<?php 
    $functions[] = ['IsNull', ['@type'], 'BASE::BOOL', true, true];
    ?>
inline
bool IsNull( @type f ) {
    return isnan(f);
}

<?php 
    $gContent .= ob_get_clean();
    ?>
//////////////
// Operators

// all operators defined by C++

<?php 
    return array('kind' => 'TYPE', "system_headers" => array("cstdlib", "cstdio", "cinttypes", 'cmath'), "complex" => false, "global_content" => $gContent, 'binary_operators' => ['+', '-', '*', '/', '==', '!=', '>', '<', '>=', '<='], 'unary_operators' => ['+', '-'], 'constructors' => $constructors, 'functions' => $functions, 'properties' => ['real', 'numeric', '_primative_'], 'describe_json' => DescribeJson('float'), 'extras' => ['size.bytes' => 8]);
}
//end of function
// Define the constructors from the various other types.
foreach (['BYTE', 'SMALLINT', 'BIGINT', 'FLOAT', 'INT'] as $type) {
    $fullType = 'base::' . $type;
    $call = function ($args, $targs = []) use($fullType) {
        $arg = lookupType($fullType);
        $ret = lookupType('base::DOUBLE');
        return array('kind' => 'FUNCTION', 'input' => [$arg], 'result' => $ret, 'deterministic' => true);
    };
    declareFunctionGlobal('base', 'DOUBLE', [$fullType], $call);
}
开发者ID:gokulp,项目名称:grokit,代码行数:30,代码来源:DOUBLE.h.php

示例9: HyperLogLog

/**
 *  A GLA that estimates the cardinality of a dataset using the HyperLogLog
 *  algorithm, with a configurable number of bins.
 */
function HyperLogLog(array $t_args, array $input, array $output)
{
    $debug = get_default($t_args, 'debug', 0);
    grokit_assert(\count($output) == 1, 'HyperLogLog produces only 1 value, ' . \count($output) . ' outputs given.');
    $outputName = array_keys($output)[0];
    $outputType = array_get_index($output, 0);
    if (is_null($outputType)) {
        $outputType = lookupType('BASE::BIGINT');
    }
    $output[$outputName] = $outputType;
    grokit_assert($outputType->is('numeric'), 'BloomFilter output must be numeric!');
    $exp = get_first_key_default($t_args, ['bins.exponent'], 4);
    grokit_assert(is_integer($exp), 'HyperLogLog bins.exponent must be an integer');
    // Set limit of 2^24 bins, because states past 16MB start to get silly
    grokit_assert($exp >= 4 && $exp < 24, 'HyperLogLog bins.exponent must be in range [4, 24]');
    $useBuiltinCtz = get_default($t_args, 'use.builtin.ctz', true);
    $ctzFunc = $useBuiltinCtz ? '__builtin_ctzl' : 'ctz';
    $bins = pow(2, $exp);
    // Determine the value of alpha based on $exp
    switch ($exp) {
        case 4:
            $alpha = 0.673;
            break;
        case 5:
            $alpha = 0.697;
            break;
        case 6:
            $alpha = 0.709;
            break;
        default:
            $alpha = 0.7213000000000001 / (1 + 1.079 / $bins);
    }
    $className = generate_name('HyperLogLog');
    ?>

class <?php 
    echo $className;
    ?>
 {
    // Number of bins for registers
    static constexpr const size_t NUM_BINS = <?php 
    echo $bins;
    ?>
;
    // Number of bits used to index into registers, log2(NUM_BINS)
    static constexpr const size_t INDEX_BITS = <?php 
    echo $exp;
    ?>
;
    // Mask used to obtain register index from hash value
    static constexpr const size_t INDEX_MASK = NUM_BINS - 1;

    // Alpha coefficient used to correct cardinality estimate. Based on NUM_BINS.
    static constexpr const long double ALPHA = <?php 
    echo $alpha;
    ?>
;

    // Value of cardinality estimate after which we must apply the
    // large range correction
    static constexpr const long double LARGE_BREAKPOINT = (1.0 / 30.0) * <?php 
    echo pow(2, 32);
    ?>
;

    // Constants for population count
    static constexpr const uint64_t m1  = 0x5555555555555555;
    static constexpr const uint64_t m2  = 0x3333333333333333;
    static constexpr const uint64_t m4  = 0x0f0f0f0f0f0f0f0f;
    static constexpr const uint64_t h01 = 0x0101010101010101;

    // The registers
    std::array<unsigned char, NUM_BINS> registers;

    // A count used to remember how many tuples were processed, mostly for debugging.
    size_t count;

public:

    <?php 
    echo $className;
    ?>
(void) : registers() {
        for( auto & elem : registers ) {
            elem = 0;
        }
    }

    ~<?php 
    echo $className;
    ?>
() { }

    int popcount(uint64_t x) {
        // Put count of each 2 bits into those 2 bits
        x -= (x >> 1) & m1;
//.........这里部分代码省略.........
开发者ID:gokulp,项目名称:grokit,代码行数:101,代码来源:HyperLogLog.h.php

示例10: IsNull

inline
bool IsNull( @type f ) {
    return isnan(f);
}

<?php 
    $gContents = ob_get_clean();
    ?>

//////////////
// Operators

// all operators defined by C++

<?php 
    return array('kind' => 'TYPE', "system_headers" => array("cstdlib", "cstdio", "cinttypes", 'cmath', 'limits'), "complex" => false, 'binary_operators' => ['+', '-', '*', '/', '==', '!=', '>', '<', '>=', '<='], 'unary_operators' => ['+', '-'], 'constructors' => $constructors, 'functions' => $functions, 'properties' => ['real', 'numeric', '_primative_'], 'global_content' => $gContents, 'describe_json' => DescribeJson('float'), 'extras' => ['size.bytes' => 4]);
}
// end of function
// Define the constructors from the various other types.
foreach (['BYTE', 'SMALLINT', 'BIGINT', 'INT', 'FLOAT', 'DOUBLE'] as $type) {
    $fullType = 'base::' . $type;
    $call = function ($args, $targs = []) use($fullType) {
        $arg = lookupType($fullType);
        $ret = lookupType('base::FLOAT');
        return array('kind' => 'FUNCTION', 'input' => [$arg], 'result' => $ret, 'deterministic' => true);
    };
    declareFunctionGlobal('base', 'FLOAT', [$fullType], $call);
}
?>

开发者ID:gokulp,项目名称:grokit,代码行数:29,代码来源:FLOAT.h.php

示例11: AlphaOperator

 public static function AlphaOperator($op, $nArgs, DataType $alpha)
 {
     $aVal = $alpha->value();
     switch ($nArgs) {
         case 1:
             grokit_assert(array_key_exists($op, self::$unaryOperators), 'Attempted to generate invalid unary operator ' . $op . ' with alpha type ' . $alpha);
             $form = self::$unaryOperators[$op];
             switch ($form) {
                 case 'ata':
                     $args = [$alpha->value()];
                     $call = function () use($alpha) {
                         return array('kind' => InfoKind::T_OP, 'input' => [$alpha], 'result' => $alpha);
                     };
                     break;
             }
             break;
         case 2:
             // Binary operator
             grokit_assert(array_key_exists($op, self::$binaryOperators), 'Attempted to generate invalid binary operator ' . $op . ' with alpha type ' . $alpha);
             $form = self::$binaryOperators[$op];
             switch ($form) {
                 case 'aata':
                     $args = [$aVal, $aVal];
                     $call = function () use($alpha) {
                         return array('kind' => InfoKind::T_OP, 'input' => [$alpha, $alpha], 'result' => $alpha);
                     };
                     break;
                 case 'aatb':
                     $args = [$aVal, $aVal];
                     $call = function () use($alpha) {
                         return array('kind' => InfoKind::T_OP, 'input' => [$alpha, $alpha], 'result' => lookupType('base::bool'));
                     };
                     break;
             }
     }
     declareOperator($op, $args, $call);
 }
开发者ID:gokulp,项目名称:grokit,代码行数:37,代码来源:grokit_libman.php

示例12: generate_name

    $name = generate_name('Time');
    ?>

inline TIME <?php 
    echo $name;
    ?>
(const DATETIME& date_time) {
  return TIME(date_time.Hour(), date_time.Minute(), date_time.Second(), 0);
}

<?php 
    return ['kind' => 'FUNCTION', 'name' => $name, 'input' => $args, 'result' => $result, 'deterministic' => true];
});
?>

<?php 
declareFunction('DATETIMEFROMINT', ['BASE::INT'], function ($args) {
    $result = lookupType('BASE::DATETIME');
    $name = generate_name('DateTimeFromInt');
    ?>

inline DATETIME <?php 
    echo $name;
    ?>
(const INT& seconds) {
  return DATETIME(seconds);
}

<?php 
    return ['kind' => 'FUNCTION', 'name' => $name, 'input' => $args, 'result' => $result, 'deterministic' => true];
});
开发者ID:gokulp,项目名称:grokit,代码行数:31,代码来源:Date_Functions.php

示例13: page_rank_vd

function page_rank_vd($t_args, $inputs, $outputs)
{
    $className = generate_name('PageRank');
    $inputs_ = array_combine(['s', 't'], $inputs);
    $vertex = $inputs_['s'];
    $outputs_ = ['node' => $vertex, 'rank' => lookupType('double')];
    $outputs = array_combine(array_keys($outputs), $outputs_);
    $sys_headers = ['vector', 'algorithm'];
    $user_headers = [];
    $lib_headers = [];
    $libraries = [];
    $properties = [];
    $extra = [];
    $result_type = ['fragment'];
    ?>

using namespace std;

class <?php 
    echo $className;
    ?>
;

<?php 
    $constantState = lookupResource('pagerankVD::page_rank_vd_Constant_State', ['className' => $className]);
    ?>

class <?php 
    echo $className;
    ?>
 {
 public:
  using ConstantState = <?php 
    echo $constantState;
    ?>
;
  using Iterator = std::pair<int, int>;
  static const constexpr float kDamping = 0.85;
  static const constexpr int nIterations = 5;
  static const constexpr int kBlock = 32;
  static const constexpr int kMaxFragments = 64;

 private:

  static std::vector<double> weight;
  static std::vector<double> pagerank;
  static std::vector<double> oldPagerank;

  const ConstantState& constant_state;
  long nVertices;
  int iteration;
  int num_fragments;

 public:
  <?php 
    echo $className;
    ?>
(const <?php 
    echo $constantState;
    ?>
& state)
      : constant_state(state),
        nVertices(state.nVertices),
        iteration(state.iteration) {
  }

  void AddItem(<?php 
    echo const_typed_ref_args($inputs_);
    ?>
) {
    if (iteration == 0) {
      nVertices = max((long) max(s, t), nVertices);
      return;
    } else if (iteration == 1) {
      weight[s]++;
    } else {
      oldPagerank[t] += weight[s] * pagerank[s];
    }
  }

  void AddState(<?php 
    echo $className;
    ?>
 &other) {
    if (iteration == 0)
      nVertices = max(nVertices, other.nVertices);
  }

  // Most computation that happens at the end of each iteration is parallelized
  // by performed it inside Finalize.
  bool ShouldIterate(ConstantState& state) {
    state.iteration = ++iteration;
    cout << "Finished Iteration: " << iteration << endl;
    if (iteration == 1) {
      state.nVertices = ++nVertices;
      cout << "num_nodes: " << nVertices << endl;
      oldPagerank.reserve(nVertices);
      pagerank.reserve(nVertices);
      weight.reserve(nVertices);
      std::fill (pagerank.begin(),pagerank.end(),1);
//.........这里部分代码省略.........
开发者ID:vineethdasaraju,项目名称:LGDataProcessingPageRank,代码行数:101,代码来源:pagerankvd.php

示例14: CountDistinct

/**
 *  A GLA that counts the number of distinct elements by keeping track of the
 *  distinct elements.
 *
 *  Unless an exact count of the distinct is absolutely needed, consider using
 *  an approximation of the distinct, such as a Bloom Filter.
 */
function CountDistinct(array $t_args, array $input, array $output)
{
    grokit_assert(\count($output) == 1, 'CountDistinct should have only 1 output, ' . \count($output) . 'given');
    $outputName = array_keys($output)[0];
    $outputType = array_get_index($output, 0);
    if (is_null($outputType)) {
        $outputType = lookupType('BASE::BIGINT');
    }
    $output[$outputName] = $outputType;
    grokit_assert($outputType->is('numeric'), 'CountDistinct output must be numeric!');
    $useMCT = get_default($t_args, 'use.mct', true);
    $keepHashes = get_default($t_args, 'mct.keep.hashes', false);
    $initSize = get_default($t_args, 'init.size', 65536);
    $nullCheck = get_default($t_args, 'null.check', false);
    grokit_assert(is_bool($useMCT), 'CountDistinct use.mct argument must be boolean');
    grokit_assert(is_integer($initSize), 'Distinct init.size argument must be an integer');
    grokit_assert($initSize > 0, 'Distinct init.size argument must be positive');
    grokit_assert(is_bool($keepHashes), 'CountDistinct mct.keep.hashes argument must be boolean');
    $distTmpArgs = ['use.mct' => $useMCT, 'init.size' => $initSize, 'mct.keep.hashes' => $keepHashes, 'null.check' => $nullCheck];
    $gla = lookupGLA('BASE::DISTINCT', $distTmpArgs, $input, $input);
    $className = generate_name('CountDistinct');
    ?>
class <?php 
    echo $className;
    ?>
 {
    using Distinct = <?php 
    echo $gla->value();
    ?>
;

    Distinct distinctGLA;

public:

    <?php 
    echo $className;
    ?>
(void):
        distinctGLA()
    { }

    ~<?php 
    echo $className;
    ?>
(void) { }

    void AddItem(<?php 
    echo const_typed_ref_args($input);
    ?>
) {
        distinctGLA.AddItem(<?php 
    echo args($input);
    ?>
);
    }

    void AddState(<?php 
    echo $className;
    ?>
 & o) {
        distinctGLA.AddState(o.distinctGLA);
    }

    void GetResult(<?php 
    echo $outputType;
    ?>
 & <?php 
    echo $outputName;
    ?>
) {
        <?php 
    echo $outputName;
    ?>
 = distinctGLA.get_countDistinct();
    }
};
<?php 
    return ['kind' => 'GLA', 'name' => $className, 'input' => $input, 'output' => $output, 'result_type' => 'single'];
}
开发者ID:gokulp,项目名称:grokit,代码行数:87,代码来源:CountDistinct.h.php

示例15: declareFunctionGlobal

<?php

// Copyright 2015, Tera Insights, LLC. All Rights Reserved.
declareFunctionGlobal('BASE', 'BOOL', ['BASE::NULL'], function () {
    $boolType = lookupType('BASE::BOOL');
    $nullType = lookupType('BASE::NULL');
    return ['kind' => 'FUNCTION', 'name' => 'bool_Null', 'input' => [$nullType], 'result' => $boolType, 'deterministic' => true];
});
?>

inline int ToString(bool b, char * buffer) {
	if (b)
		return 1 + sprintf(buffer, "true");
	else
		return 1 + sprintf(buffer, "false");
}

inline void FromString(bool & b, const char* buffer) {
	char first = *buffer;
	char upper = *buffer & 0xDF;
	if (first == '1' || upper == 'T' || upper == 'Y')
		b = true;
	else
		b = false;
}

namespace BASE {
	inline
	bool bool_Null(const GrokitNull& null) {
		return false;
	}
开发者ID:gokulp,项目名称:grokit,代码行数:31,代码来源:BOOL.h.php


注:本文中的lookupType函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。