//two args: vec1 & vec2 cellpoint vector_eq(void) { int len1 = vector_len(args_ref(1)); int len2 = vector_len(args_ref(2)); int i; if (args_ref(1) == args_ref(2)){ args_pop(2); return a_true; } if (len1 != len2){ args_pop(2); return a_false; } for (i=0; i < len1; ++i){ reg = vector_ref(args_ref(1), i); args_push(vector_ref(args_ref(2), i)); args_push(reg); reg = equal(); if (is_false(reg)){ args_pop(2); return a_false; } } args_pop(2); return a_true; }
static cv_t default_handler(obj_t cont, obj_t values) { /* * For all non-message-irritants-who conditions, * print the condition's class. * For all message conditions, print the condition's message. * If who or irritants given, print (cons who irritants). */ assert(is_cont(cont)); EVAL_LOG("cont=%O values=%O", cont, values); obj_t ex = CAR(values); obj_t parts = record_get_field(ex, 0); const char *psn = program_short_name(); size_t psnl = strlen(psn); size_t i, size = vector_len(parts); for (i = 0; i < size; i++) { obj_t rtd = record_rtd(vector_ref(parts, i)); if (rtd != message && rtd != irritants && rtd != who) { ofprintf(stderr, "%*s: %O\n", (int)psnl, psn, rtd_name(rtd)); psn = ""; } } obj_t who_p = FALSE_OBJ; obj_t irr_p = make_uninitialized(); for (i = 0; i < size; i++) { obj_t p = vector_ref(parts, i); obj_t rtd = record_rtd(p); if (rtd == message) { obj_t msg = record_get_field(p, 0); const wchar_t *chars = string_value(msg); fprintf(stderr, "%*s %ls\n", (int)psnl, psn, chars); psn = ""; } else if (rtd == who) who_p = record_get_field(p, 0); else if (rtd == irritants) irr_p = record_get_field(p, 0); } if (who_p != FALSE_OBJ && !is_uninitialized(irr_p)) { ofprintf(stderr, "%*s %O\n", (int)psnl, psn, CONS(who_p, irr_p)); psn = ""; } else if (who_p != FALSE_OBJ) { ofprintf(stderr, "%*s %O\n", (int)psnl, psn, who_p); psn = ""; } else if (!is_uninitialized(irr_p)) { ofprintf(stderr, "%*s %O\n", (int)psnl, psn, irr_p); psn = ""; } if (*psn) fprintf(stderr, "%s: unknown exception\n", psn); ofprintf(stderr, "\n"); return cv(EMPTY_LIST, CONS(make_uninitialized(), EMPTY_LIST)); }
int main() { srand(time(NULL)); int size = 15; int generations = 15; int print_gen = 1; Vector *V = vector_make(size); int i; int j = 1; for(;j <= generations; j++) { if(j % print_gen == 0) { printf("on gen %d\n", j); } i = 0; for(;i<size;i++) { int *tmp = malloc(sizeof(int)); *tmp = rand() % 20; vector_ref(V, i, tmp); } int *tmp = malloc(sizeof(int)); *tmp = 5; if(vector_search(V, tmp, comparator) != -1) { printf("found\n"); } vector_walk(V, print); printf("\n"); } vector_free(V, 1); return 0; }
static void assert2_object_contents_mapped( msgc_context_t *context, word w, int n ) { #ifndef NDEBUG2 int i; for ( i=0 ; i < n ; i++ ) { if (isptr(vector_ref( w, i )) && ! gc_is_address_mapped( context->gc, ptrof(vector_ref( w, i )), FALSE )) { consolemsg("unmapped address, vector 0x%08x in gen %d, elem [%d] = 0x%08x", w, gen_of( w ), i, vector_ref( w, i )); consolemsg("(gno count: %d)", context->gc->gno_count); assert2(0); } } #endif }
static void assert2_los_addresses_mapped( msgc_context_t *context, word obj, int k, int next ) { #ifndef NDEBUG2 int i; for ( i=0 ; i < k ; i++ ) { if (isptr(vector_ref(obj, i+next)) && ! gc_is_address_mapped( context->gc, ptrof(vector_ref(obj, i+next)), FALSE )) { assert( gc_is_address_mapped( context->gc, ptrof(obj), TRUE )); consolemsg("unmapped address, los vector 0x%08x in gen %d, elem [%d] = 0x%08x", obj, gen_of(obj), i+next, vector_ref(obj, i+next )); consolemsg("(gno count: %d)", context->gc->gno_count); assert2(0); } } #endif }
//one arg: vec cellpoint vector_2_list(void) { int i, len = vector_len(args_ref(1)); reg = NIL; for (i=len-1; i >= 0; --i){ reg = cons(vector_ref(args_ref(1), i), reg); } args_pop(1); return reg; }
static void vector_free(void *vec, unsigned int *count, size_t esize, vector_free_elem free_elem) { unsigned int i; void *elem; for (i = 0; i < *count; i++) { elem = vector_ref(i, vec, *count, esize); if (elem != NULL) free_elem(elem); } free(vec); *count = 0; }
void _nsdbtput(const ns_dbt *dbt) { unsigned int i; ns_dbt *p; for (i = 0; i < _nsmapsize; i++) { p = vector_ref(i, _nsmap, _nsmapsize, sizeof(*_nsmap)); if (string_compare(&dbt->name, &p->name) == 0) { /* overwrite existing entry */ if (p->srclist != NULL) ns_src_free(&p->srclist, p->srclistsize); memmove(p, dbt, sizeof(*dbt)); return; } } _nsmap = vector_append(dbt, _nsmap, &_nsmapsize, sizeof(*_nsmap)); }
static bool fill_from_los_stack( msgc_context_t *context ) { int next, k, n, i; word obj; if (context->los_stack.stkp == context->los_stack.stkbot) { /* underflow */ if (!pop_segment( &context->los_stack )) return FALSE; } obj = *--context->los_stack.stkp; next = (int)*--context->los_stack.stkp; n = bytes2words( sizefield( *ptrof(obj) ) ); k = min( n-next, LARGE_OBJECT_LIMIT ); for ( i=0 ; i < k ; i++ ) PUSH( context, vector_ref( obj, i+next ) ); if (next+k < n) LOS_PUSH( context, next+k, obj ); return TRUE; }
static int push_constituents( msgc_context_t *context, word w ) { int i, n; switch (tagof(w)) { case PAIR_TAG : PUSH( context, pair_cdr( w ) ); /* Do the CDR last */ PUSH( context, pair_car( w ) ); /* Do the CAR first */ return 2; case VEC_TAG : case PROC_TAG : n = bytes2words( sizefield(*ptrof(w)) ); if (n > LARGE_OBJECT_LIMIT) LOS_PUSH( context, 0, w ); /* Treat large objects specially */ else for ( i=0 ; i < n ; i++ ) PUSH( context, vector_ref( w, i ) ); return n+1; default : return 0; } }
static int push_constituents( msgc_context_t *context, word w ) { int i, n; switch (tagof(w)) { case PAIR_TAG : return push_pair_constiuents( context, w ); case VEC_TAG : case PROC_TAG : assert2_tag_hdr_consistency( context, w ); n = bytes2words( sizefield(*ptrof(w)) ); if (n > LARGE_OBJECT_LIMIT) LOS_PUSH( context, 0, w ); /* Treat large objects specially */ else { assert2_object_contents_mapped( context, w, n ); for ( i=0 ; i < n ; i++ ) { PUSH( context, vector_ref( w, i ), w, i+1 ); } } return n+1; default : return 0; } }
void print_vector (STREAM stream, D instance, BOOL escape_p, int print_depth) { int size = vector_size(instance); int first = TRUE, i = 0; D element; int max_size = MIN(size, dylan_print_length); put_string("#[", stream); if (print_depth < dylan_print_depth) { for (; i < max_size; i++) { if (first) first = FALSE; else put_string(", ", stream); element = vector_ref(instance, i); print_object(stream, element, escape_p, print_depth + 1); } } if (size > max_size || print_depth >= dylan_print_depth) { if (i > 0) put_string(", ", stream); format(stream, "... 0x%lx", instance); } put_string("]", stream); }
static cv_t c_test_handler(obj_t cont, obj_t values) { obj_t ex = vector_ref(record_get_field(CAR(values), 0), 0); return cv(EMPTY_LIST, MAKE_LIST(ex)); }