function Gather(array $t_args, array $inputs, array $outputs) { // Class name randomly generated $className = generate_name("Gather"); $outputs = array_combine(array_keys($outputs), $inputs); $sys_headers = ['vector']; $user_headers = []; $lib_headers = []; $libraries = []; $properties = ['list']; $extra = []; $result_type = 'single'; ?> class <?php echo $className; ?> ; class <?php echo $className; ?> { public: using Tuple = std::tuple<<?php echo typed($inputs); ?> >; using Vector = std::vector<Tuple>; private: // The container that gathers the input. Vector items; // The tuple to be filled with the current item. Tuple item; // Used for iterating over the container during GetNextResult. int return_counter; public: <?php echo $className; ?> (){} void AddItem(<?php echo const_typed_ref_args($inputs); ?> ) { <?php foreach (array_keys($inputs) as $index => $name) { ?> std::get<<?php echo $index; ?> >(item) = <?php echo $name; ?> ; <?php } ?> items.push_back(item); } void AddState(<?php echo $className; ?> & other) { items.reserve(items.size() + other.items.size()); items.insert(items.end(), other.items.begin(), other.items.end()); } void Finalize() { return_counter = 0; } void GetResult(<?php echo typed_ref_args($outputs); ?> , int index = 0) const { <?php foreach (array_keys($outputs) as $index => $name) { ?> <?php echo $name; ?> = std::get<<?php echo $index; ?> >(items[index]); <?php } ?> } int GetCount() const { return items.size(); } const Vector& GetList() const { return items; } }; <?php return ['kind' => 'GLA', 'name' => $className, 'system_headers' => $sys_headers, 'user_headers' => $user_headers, 'lib_headers' => $lib_headers, 'libraries' => $libraries, 'properties' => $properties, 'extra' => $extra, 'iterable' => false, 'input' => $inputs, 'output' => $outputs, 'result_type' => $result_type]; }
function Multi_Hash(array $t_args, array $inputs, array $outputs) { // Class name randomly generated $className = generate_name('Hash'); // Processing of template arguments. $split = $t_args['split']; // Processing of inputs. $keys = array_slice($inputs, 0, $split); $vals = array_slice($inputs, $split); $sys_headers = ['map', 'tuple', 'unordered_map']; $user_headers = []; $lib_headers = ['HashFct.h']; $libraries = []; $properties = []; $extra = ['keys' => $keys, 'vals' => $vals]; $result_type = ['state']; ?> class <?php echo $className; ?> ; class <?php echo $className; ?> { public: // The standard hashing for Grokit is used, which returns a uint64_t. using Key = uint64_t; // The value type for the map that contains the various values passed through. using Tuple = std::tuple<<?php echo typed($vals); ?> >; // The map used, which must be a multimap. using Map = std::unordered_multimap<uint64_t, Tuple>; private: // The container that gathers the input. Map map; public: <?php echo $className; ?> () {} void AddItem(<?php echo const_typed_ref_args($inputs); ?> ) { auto key = ChainHash(<?php echo args($keys); ?> ); auto val = std::make_tuple(<?php echo args($vals); ?> ); map.insert(std::make_pair(key, val)); } void AddState(<?php echo $className; ?> & other) { map.insert(other.map.begin(), other.map.end()); } const Map& GetMap() const { return map; } static uint64_t ChainHash(<?php echo const_typed_ref_args($keys); ?> ) { uint64_t offset = 1; <?php foreach (array_keys($keys) as $name) { ?> offset = CongruentHash(Hash(<?php echo $name; ?> ), offset); <?php } ?> return offset; } }; <?php return ['kind' => 'GLA', 'name' => $className, 'system_headers' => $sys_headers, 'user_headers' => $user_headers, 'lib_headers' => $lib_headers, 'libraries' => $libraries, 'properties' => $properties, 'extra' => $extra, 'iterable' => false, 'input' => $inputs, 'output' => $outputs, 'result_type' => $result_type]; }