derived_type& assign_array(const A& o) { // users guide: is you have a compiler error here it probably means that // you are calling assign_array with something that is not an ivl array. //NO WAY: resize(0) before resize() is optimum when assigning. //to_array().derived().resize(typename A::derived_type::size_type(0)); //?maybe?:to_array().derived().reshape( // o.template highest_common_class<derived_type>().size()); // resize_like //?or?:to_array().template highest_common_class<A>().reshape( // o.template highest_common_class<derived_type>().size()); // resize_like to_array().template highest_common_class<A>().reshape( o.template highest_common_class<t>().size()); // resize_like //TODO: shouldn't this be: //to_array().derived().resize( // o.template highest_common_class<t>().size()); // resize_like //by resize rule? shouldn't resize be always called on derived()? //or no, it should handle on itself, for any level, but then // NEEDS FIX, for all array classes to support this!! // anyway it certainly wont work well for vector<T>.resize()!!!! :) loop_on<loops::assign_copy_class>(to_array().derived(), o); return to_array().derived(); }
vm_obj array_read(vm_obj const &, vm_obj const &, vm_obj const & a, vm_obj const & i) { /* TODO(Leo): handle case where n is too big */ unsigned idx = force_to_unsigned(i); lean_vm_check(idx < to_array(a).size()); parray<vm_obj> const & _a = to_array(a); return _a[idx]; }
derived_type& assign_array(const ret<A>& o) { CHECK(to_array().length() == o.length(), eshape()); // users guide: is you have a compiler error here it probably means that // you are calling assign_array with something that is not an ivl array. to_array().derived().swap(o.ret_base()); return to_array().derived(); }
derived_type& assign_array(const A& o) { CHECK(to_array().length() == o.length(), eshape()); // users guide: is you have a compiler error here it probably means that // you are calling assign_array with something that is not an ivl array. loop_on<loops::assign_copy_class>(to_array().derived(), o); return to_array().derived(); }
std::string secret_to_wif(const ec_secret& secret, bool compressed) { auto version = to_array(payment_address::wif_version); data_chunk data; if (compressed) data = build_chunk({ version, secret, to_array(0x01) }, checksum_size); else data = build_chunk({version, secret}, checksum_size); append_checksum(data); return encode_base58(data); }
mxArray *get_array( field_data &point_data, field_data &cell_data, std::string name ){ for( field_data::iterator iter=point_data.begin(); iter!=point_data.end(); iter++ ){ if( iter->first == name ){ return to_array( iter->second ); } } for( field_data::iterator iter=cell_data.begin(); iter!=cell_data.end(); iter++ ){ if( iter->first == name ){ return to_array( iter->second ); } } return NULL; }
derived_type& assign_element(const J& s) { typedef typename derived_type::size_type sz_t; // Note: not all arrays support resizing with (1, s) // however this statement works for all array types because // fixed dim arrays have size_type of dims<N> which // has a constructor that initializes all dimensions with // the argument, e.g. sz_t(1) is [1, 1] in a size_dim<2>. //to_array().derived().reset(sz_t(1), s); to_array().derived().resize(sz_t(0)); to_array().derived().resize(sz_t(1), cast<T>(s)); return to_array().derived(); }
static int cmp_array (fz_context *ctx, pdfout_data *x, pdfout_data *y) { data_array *a = to_array (ctx, x); data_array *b = to_array (ctx, y); if (a->len != b->len) return 1; for (int i = 0; i < a->len; ++i) { if (pdfout_data_cmp (ctx, a->list[i], b->list[i])) return 1; } return 0; }
pdfout_data * pdfout_data_array_get (fz_context *ctx, pdfout_data *array, int pos) { data_array *a = to_array (ctx, array); assert (pos < a->len); return a->list[pos]; }
void init_size_with_array(const array<J, D>& o) { // need this because we want only first elements ivl::copy_out(to_array(), o); //loop_on<loops::assign_copy_class>(to_array().derived(), o); }
main() { struct tnode_t *tree = malloc(sizeof(tnode_t)); tree->data = 5; tree->lchild = NULL; tree->rchild = NULL; printf("%d\n", size(tree)); insert(&tree, 3); print_inorder(tree); printf("%d\n", size(tree)); insert(&tree, 3); print_inorder(tree); printf("%d\n", size(tree)); int *array = to_array(tree); int i = 0; while (i < size(tree)) { printf("%d ", *array); i++; array++; } printf("\n"); }
static one_byte point_sign(uint8_t byte, const hash_digest& hash) { static constexpr uint8_t low_bit_mask = 0x01; const uint8_t last_byte = hash.back(); const uint8_t last_byte_odd_field = last_byte & low_bit_mask; const uint8_t sign_byte = byte ^ last_byte_odd_field; return to_array(sign_byte); }
//-------------------------------------------------------------------------- Matrix4x4 JSONElement::to_matrix4x4() const { TempAllocator128 alloc; Array<float> array(alloc); to_array(array); return Matrix4x4(array::begin(array)); }
void pdfout_data_array_push (fz_context *ctx, pdfout_data *array, pdfout_data *entry) { data_array *a = to_array (ctx, array); if (a->cap == a->len) a->list = pdfout_x2nrealloc (ctx, a->list, &a->cap, pdfout_data *); a->list[a->len++] = entry; }
vm_obj array_iterate(vm_obj const &, vm_obj const &, vm_obj const & n, vm_obj const & a, vm_obj const & b, vm_obj const & fn) { /* TODO(Leo): handle case where n is too big */ unsigned _n = force_to_unsigned(n); parray<vm_obj> const & p = to_array(a); vm_obj r = b; for (unsigned i = 0; i < _n; i++) r = invoke(fn, mk_vm_nat(i), p[i], r); return r; }
vm_obj array_push_back(vm_obj const &, vm_obj const &, vm_obj const & a, vm_obj const & v) { parray<vm_obj> const & p = to_array(a); if (a.raw()->get_rc() == 1) { const_cast<parray<vm_obj> &>(p).push_back(v); return a; } else { parray<vm_obj> new_a = p; new_a.push_back(v); return to_obj(new_a); } }
int main() { printf("\nTEST\n====\n\n"); struct tnode_t *p = NULL; printf("Testing Insert:\n"); insert(&p, 9); printf("%d\n", p->data); insert(&p, 6); printf("%d\n", p->lchild->data); insert(&p, 11); printf("%d\n", p->rchild->data); insert(&p, 10); printf("%d\n", p->rchild->lchild->data); printf("Testing print_inorder:\n"); print_inorder(p); printf("\n"); printf("Testing size:\n"); printf("%d\n", size(p)); printf("Testing to_array:\n"); int *t; t = to_array(p); printf("%d, %d, %d, %d\n", t[0], t[1], t[2], t[3]); /* Testing dlist */ printf("Testing dlist\n"); struct dlist_t *lst; lst = tree2dlist(p); printf("%d, %d, %d, %d\n", lst->data, lst->next->data, lst->next->next->data, lst->next->next->next->data); int int9 = 9, int6 = 6, int11 = 11, int10 = 10; struct tnode_t2 *p2 = NULL; printf("Testing Insert:\n"); insert2(&p2, &int9, &comp); printf("%d\n", *(int*)(p2->data)); insert2(&p2, &int6, &comp); printf("%d\n", *(int*)(p2->lchild->data)); insert2(&p2, &int11, &comp); printf("%d\n", *(int*)(p2->rchild->data)); insert2(&p2, &int10, &comp); printf("%d\n", *(int*)(p2->rchild->lchild->data)); return 0; }
/** * to_a **/ static VALUE t_to_a(VALUE self) { root_node root; VALUE array; Data_Get_Struct(self, struct _root_node, root); array = rb_ary_new2(root->size); to_array(root, array); return array; }
void pdfout_data_drop (fz_context *ctx, pdfout_data *data) { switch (data->type) { case SCALAR: drop_scalar (ctx, to_scalar (ctx, data)); break; case ARRAY: drop_array (ctx, to_array (ctx, data)); break; case HASH: drop_hash (ctx, to_hash (ctx, data)); break; default: abort (); } }
vm_obj array_write(vm_obj const &, vm_obj const &, vm_obj const & a, vm_obj const & i, vm_obj const & v) { /* TODO(Leo): handle case where n is too big */ unsigned idx = force_to_unsigned(i); parray<vm_obj> const & p = to_array(a); lean_vm_check(idx < p.size()); if (a.raw()->get_rc() == 1) { const_cast<parray<vm_obj> &>(p).set(idx, v); return a; } else { parray<vm_obj> new_a = p; new_a.set(idx, v); return to_obj(new_a); } }
static one_byte set_flags(bool compressed, bool lot_sequence, bool multiplied) { uint8_t byte = 0; if (compressed) byte |= ek_flag::ec_compressed_key; if (lot_sequence) byte |= ek_flag::lot_sequence_key; if (!multiplied) byte |= ek_flag::ec_non_multiplied; return to_array(byte); }
vm_obj array_foreach(vm_obj const &, vm_obj const & n, vm_obj const & a, vm_obj const & fn) { /* TODO(Leo): handle case where n is too big */ unsigned _n = force_to_unsigned(n); parray<vm_obj> const & p = to_array(a); if (a.raw()->get_rc() == 1) { parray<vm_obj> & _p = const_cast<parray<vm_obj> &>(p); for (unsigned i = 0; i < _n; i++) _p.set(i, invoke(fn, mk_vm_nat(i), _p[i])); return a; } else { parray<vm_obj> new_a; for (unsigned i = 0; i < _n; i++) { new_a.push_back(invoke(fn, mk_vm_nat(i), p[i])); } return to_obj(new_a); } }
int try_execute(String command, StringList arguments){ int c_pid; //handlers dos controladores struct sigaction sigchld; struct sigaction ctrlc; struct sigaction ctrlz; sigchld.sa_flags = SA_SIGINFO; sigchld.sa_sigaction = sigchld_hand; ctrlc.sa_flags = SA_SIGINFO; ctrlc.sa_sigaction = ctrlc_hand; ctrlz.sa_flags = SA_SIGINFO; ctrlz.sa_sigaction = ctrlz_hand; c_pid = fork(); if (c_pid == 0) { //processo filho setpgid(0, 0); execv(command, to_array(arguments)); } else { /*processo pai //tem controle sobre o sinal SIGCHLD, enviado pelo processo filho apos terminar sua execucao controle dos sinais: */ sigaction(SIGCHLD, &sigchld, 0); sigaction(SIGINT, &ctrlc, 0); sigaction(SIGTSTP, &ctrlz, 0); //adiciona na lista de jobs job_list_push(job_list, new_job(copy_string(int_to_string(c_pid)), parse_proc_name(command))); if(background == 1){ return 1; }else{ wait(NULL); } } return 1; }
/** * sample **/ static VALUE t_sample(int argc, VALUE *argv, VALUE self) { root_node root; VALUE array; unsigned long sample_count = 1UL; Data_Get_Struct(self, struct _root_node, root); if (argc == 1 && TYPE(argv[0]) == T_FIXNUM) { sample_count = NUM2ULONG(argv[0]); if (sample_count < 1UL || sample_count > root->size) sample_count = 1UL; } array = rb_ary_new2(sample_count); if (sample_count == root->size) { to_array(root, array); } else if (root->size) { sample(root, array, sample_count); } return array; }
LIST* list_strsplit(char* string, char to_divide) { LIST* result = new_list(); char* section = ""; int length = strlen(string); int i = 0; for (i = 0; i < length; ++i) { section = ""; while (string[i] != to_divide && i < length) { section = concat(section, to_array(string[i])); i++; } if (strlen(section) > 0) push(result, section); } return result; }
byte_array<parse_ek_token::prefix_size> parse_ek_token::prefix_factory( bool lot_sequence) { const auto context = lot_sequence ? lot_context_ : default_context_; return splice(magic_, to_array(context)); }
char* ctos(char ch) { return to_array(ch); }
void init_size_with_element(const J& o) { loop_on<loops::assign_copy_class>(to_array(), o); }
derived_type& assign_element(const J& o) { loop_on<loops::assign_copy_class>(to_array().derived(), o); return to_array().derived(); }
int pdfout_data_array_len (fz_context *ctx, pdfout_data *array) { data_array *a = to_array (ctx, array); return a->len; }