void update_dangling_value(web* w) { assert(w != NULL); size_t i, j; float d = g_damping_factor; if (w->dangling_v == -1) w->dangling_v = w->pagerank[0] * w->dangling_pages->size / w->size; else { w->dangling_v = 0; for (i = 0; i < w->dangling_pages->size; ++i) { int page_id = vec_get(w->dangling_pages, i); w->dangling_v += w->pagerank[page_id]; } w->dangling_v = w->dangling_v / w->size; } for (i = 0; i < w->dangling_pages->size; ++i) { float pagerank = 0; int page_id = vec_get(w->dangling_pages, i); for (j = 0; j < w->webnodes[page_id]->in_links->size; ++j) { int in_link = vec_get(w->webnodes[page_id]->in_links, j); pagerank += w->pagerank[in_link] * d / w->webnodes[in_link]->out_links_num; } pagerank = pagerank + (1 - d) / w->size; pagerank = pagerank + d * w->dangling_v; w->pagerank[page_id] = pagerank; } }
char* vec_char (vec_t *vec) { ensure_vec(vec, __func__); int count = vec->count; push(strf("[")); for (int i = 0; i < count; i++) { if (is_vec(vec_get(vec, i)[0])) push(strf("vec[]")); else if (is_map(vec_get(vec, i)[0])) push(strf("map[]")); else push(to_char(vec_get(vec, i)[0])); op_concat(); if (i < count-1) { push(strf(", ")); op_concat(); } } push(strf("]")); op_concat(); return pop(); }
int test() { vector * vec = (vector *) malloc(sizeof(struct vector)); vec_init(vec, 50); int i; for (i = 0; i < 14; i++) { vec_push(vec, i * 4 + 2); } vec_set(vec, 0, 1); printf("capacity = %zd, %zd\n", vec->capacity, vec->size); vec_set(vec, 39, 1); printf("capacity = %zd, %zd\n", vec->capacity, vec->size); vec_set(vec, 19, 2); printf("capacity = %zd, %zd\n", vec->capacity, vec->size); vec_set(vec, 45, 2); printf("capacity = %zd, %zd\n", vec->capacity, vec->size); printf("vec[3] = %d\n", vec_get(vec, 3)); printf("vec[6] = %d\n", vec_get(vec, 6)); printf("vec[666] = %d\n", vec_get(vec, 666)); for (size_t i = 0; i < vec->size; i++) { printf("vec[%zd] = %d\n", i, vec->data[i]); } vec_free(vec); return 0; }
static void do_emit_data(Vector *inits, int size, int off, int depth) { SAVE; for (int i = 0; i < vec_len(inits) && 0 < size; i++) { Node *node = vec_get(inits, i); Node *v = node->initval; emit_padding(node, off); if (node->totype->bitsize > 0) { assert(node->totype->bitoff == 0); long data = eval_intexpr(v, NULL); Type *totype = node->totype; for (i++ ; i < vec_len(inits); i++) { node = vec_get(inits, i); if (node->totype->bitsize <= 0) { break; } v = node->initval; totype = node->totype; data |= ((((long)1 << totype->bitsize) - 1) & eval_intexpr(v, NULL)) << totype->bitoff; } emit_data_primtype(totype, &(Node){ AST_LITERAL, totype, .ival = data }, depth); off += totype->size; size -= totype->size; if (i == vec_len(inits)) break; } else {
double efp_quadrupole_quadrupole_energy(const double *quad1, const double *quad2, const vec_t *dr) { double r = vec_len(dr); double r2 = r * r; double r5 = r2 * r2 * r; double r7 = r5 * r2; double r9 = r7 * r2; double q1dr = quadrupole_sum(quad1, dr); double q2dr = quadrupole_sum(quad2, dr); double q1q2 = 0.0; double q1q2dr = 0.0; for (size_t a = 0; a < 3; a++) { double t1 = 0.0; double t2 = 0.0; for (size_t b = 0; b < 3; b++) { size_t idx = quad_idx(a, b); t1 += quad1[idx] * vec_get(dr, b); t2 += quad2[idx] * vec_get(dr, b); q1q2 += quad1[idx] * quad2[idx]; } q1q2dr += t1 * t2; } return (2.0 / r5 * q1q2 - 20.0 / r7 * q1q2dr + 35.0 / r9 * q1dr * q2dr) / 3.0; }
MAT *m_inverse(const MAT *A, MAT *out) { unsigned int i; char MatrixTempBuffer[ 4000 ]; VEC *tmp = VNULL, *tmp2 = VNULL; MAT *A_cp = MNULL; PERM *pivot = PNULL; if ( ! A ) error(E_NULL,"m_inverse"); if ( A->m != A->n ) error(E_SQUARE,"m_inverse"); if ( ! out || out->m < A->m || out->n < A->n ) out = m_resize(out,A->m,A->n); if( SET_MAT_SIZE( A->m, A->n ) < 1000 ) mat_get( &A_cp, (void *)( MatrixTempBuffer + 2000 ), A->m, A->n ); else A_cp = matrix_get( A->m, A->n ); A_cp = m_copy( A, A_cp ); if( SET_VEC_SIZE( A->m ) < 1000 ) { vec_get( &tmp, (void *)MatrixTempBuffer, A->m ); vec_get( &tmp2, (void *)(MatrixTempBuffer + 1000), A->m ); } else { tmp = v_get( A->m ); tmp2 = v_get( A->m ); } if( SET_PERM_SIZE( A->m ) < 1000 ) { perm_get( &pivot, (void *)( MatrixTempBuffer + 3000 ), A->m ); } else { pivot = px_get( A->m ); } LUfactor(A_cp,pivot); //tracecatch_matrix(LUfactor(A_cp,pivot),"m_inverse"); for ( i = 0; i < A->n; i++ ){ v_zero(tmp); tmp->ve[i] = 1.0; LUsolve(A_cp,pivot,tmp,tmp2); //tracecatch_matrix(LUsolve(A_cp,pivot,tmp,tmp2),"m_inverse"); set_col(out,i,tmp2); } if( tmp != (VEC *)(MatrixTempBuffer ) ) // память выделялась, надо освободить V_FREE(tmp); if( tmp2 != (VEC *)(MatrixTempBuffer + 1000) ) // память выделялась, надо освободить V_FREE(tmp2); if( A_cp != (MAT *)(MatrixTempBuffer + 2000) ) // память выделялась, надо освободить M_FREE(A_cp); if( pivot != (PERM *)(MatrixTempBuffer + 3000) ) // память выделялась, надо освободить PX_FREE( pivot ); return out; }
/* these two functions for use by bd_estimate_transitions */ void unpack_params(Vector *params, BDPhyloHmm *bdphmm) { int params_idx = 0; if (bdphmm->estim_omega) bdphmm->mu = 1/vec_get(params, params_idx++); if (bdphmm->estim_gamma) { double gamma = vec_get(params, params_idx++); bdphmm->nu = gamma/(1-gamma) * bdphmm->mu; } if (bdphmm->estim_phi) bdphmm->phi = vec_get(params, params_idx++); bd_set_transitions(bdphmm); }
/* Wrapper for likelihood function for use in parameter estimation */ double ff_likelihood_wrapper(Vector *params, void *data) { FeatFitData *d = (FeatFitData*)data; d->cdata->mod->scale = vec_get(params, 0); if (d->cdata->stype == SUBTREE) d->cdata->mod->scale_sub = vec_get(params, 1); /* reestimate subst models on edges */ tm_set_subst_matrices(d->cdata->mod); return -1 * ff_compute_log_likelihood(d->cdata->mod, d->cdata->msa, d->feat, d->cdata->fels_scratch[0]); }
/* 実行膜スタックからmemを削除する。外部関数が膜の削除しようとするとき に、その膜がスタックに積まれている事がある。そのため、安全な削除を行 うために、この手続きが必要になる。外部の機能を使わない通常の実行時に はこの手続きは必要ない*/ void lmn_memstack_delete(LmnMemStack memstack, LmnMembrane *mem) { unsigned long i, j, n = vec_num(memstack); for (i = n-1; i >= 0; i--) { if ((LmnMembrane *)vec_get(memstack, i) == mem) { /* 空いた分後ろの要素を前にを詰める */ for (j = i+1; j < n; j++) { vec_set(memstack, j-1, vec_get(memstack, j)); } break; } } vec_pop(memstack); }
struct variable * cp_enqvar(char *word) { struct dvec *d; struct variable *vv, *tv; struct plot *pl; int i; if (*word == '&') { word++; d = vec_get(word); if (!d) return (NULL); if (d->v_length == 1) { vv = alloc(struct variable); vv->va_next = NULL; vv->va_name = copy(word); vv->va_type = CP_REAL; if (isreal(d)) vv->va_real = d->v_realdata[0]; else vv->va_real = realpart(d->v_compdata[0]); } else {
void cpp_eval(char *buf) { stream_stash(make_file_string(buf)); Vector *toplevels = read_toplevels(); for (int i = 0; i < vec_len(toplevels); i++) emit_toplevel(vec_get(toplevels, i)); stream_unstash(); }
int exe_sqlite3_exe(sqlite3_vtab_cursor* pCursor, sqlite3_context *ctx) { exe_cursor_t *cursor = (exe_cursor_t*) pCursor; exe_table_t *table = (exe_table_t*) pCursor->pVtab; exe_t* exe = (exe_t*) vec_get(table->content,cursor->row); sqlite3_result_text(ctx, exe->exe, exe->exe_len, SQLITE_STATIC); return SQLITE_OK; }
struct membuf *get_named_buffer(const char *name) { int pos; struct sbe e[1]; struct sbe *ep; struct membuf *mp; /* name is already strdup:ped */ e->name = name; pos = vec_find(s_sbe_table, sbe_cmp, e); if(pos >= 0) { /* found */ ep = vec_get(s_sbe_table, pos); } else { membuf_init(e->mb); read_file(name, e->mb); ep = vec_insert(s_sbe_table, -(pos + 2), e); } mp = ep->mb; return mp; }
int exe_sqlite3_pid(sqlite3_vtab_cursor* pCursor, sqlite3_context *ctx) { exe_cursor_t *cursor = (exe_cursor_t*) pCursor; exe_table_t *table = (exe_table_t*) pCursor->pVtab; exe_t* exe = (exe_t*) vec_get(table->content,cursor->row); sqlite3_result_int(ctx, exe->pid); return SQLITE_OK; }
static void spoil_mon_info() { int i; vec_ptr v = vec_alloc(NULL); doc_ptr doc = doc_alloc(80); spoiler_hack = TRUE; for (i = 1; i < max_r_idx; i++) { monster_race *r_ptr = &r_info[i]; if (!r_ptr->name) continue; if (r_ptr->id == MON_MONKEY_CLONE) continue; if (r_ptr->id == MON_KAGE) continue; vec_add(v, r_ptr); } vec_sort(v, (vec_cmp_f)_compare_r_level_desc); for (i = 0; i < vec_length(v); i++) { monster_race *r_ptr = vec_get(v, i); doc_printf(doc, "<topic:%s><color:r>=====================================================================</color>\n", r_name + r_ptr->name); mon_display_doc(r_ptr, doc); doc_newline(doc); } vec_free(v); doc_display(doc, "Monster Spoilers", 0); doc_free(doc); spoiler_hack = FALSE; }
int cmdline_sqlite3_cmdline(sqlite3_vtab_cursor* pCursor, sqlite3_context *ctx) { cmdline_cursor_t *cursor = (cmdline_cursor_t*) pCursor; cmdline_table_t *table = (cmdline_table_t*) pCursor->pVtab; cmdline_t* cmdline = (cmdline_t*) vec_get(table->content,cursor->row); sqlite3_result_text(ctx, cmdline->cmdline, cmdline->cmdline_len, SQLITE_STATIC); return SQLITE_OK; }
char moto_isVarGlobal(MotoEnv *env, char *name) { MotoVar* var; if ((var = (MotoVar *)stab_get(env->frame->symtab, name)) == NULL) { int i = env->frameindex; while (--i >= 0) { MotoFrame *frame = (MotoFrame *)vec_get(env->frames, i); SymbolTable *symtab = frame->symtab; if ((var = (MotoVar *)stab_get(symtab, name)) != NULL) { break; } if (frame->type == FN_FRAME) break; } } /* If we still don't have it, check the globals */ if(var==NULL) { var=stab_get(env->globals, name); if(var!=NULL) return '\1'; } return '\0'; }
struct pnode * PP_mkfnode(const char *func, struct pnode *arg) { struct func *f; struct pnode *p, *q; struct dvec *d; char buf[BSIZE_SP]; (void) strcpy(buf, func); strtolower(buf); /* Make sure the case is ok. */ for (f = &ft_funcs[0]; f->fu_name; f++) if (eq(f->fu_name, buf)) break; if (f->fu_name == NULL) { /* Give the user-defined functions a try. */ q = ft_substdef(func, arg); if (q) return (q); } if ((f->fu_name == NULL) && arg->pn_value) { /* Kludge -- maybe it is really a variable name. */ (void) sprintf(buf, "%s(%s)", func, arg->pn_value->v_name); free_pnode(arg); d = vec_get(buf); if (d == NULL) { /* Well, too bad. */ fprintf(cp_err, "Error: no such function as %s.\n", func); return (NULL); } /* (void) strcpy(buf, d->v_name); XXX */ return (PP_mksnode(buf)); } else if (f->fu_name == NULL) { fprintf(cp_err, "Error: no function as %s with that arity.\n", func); free_pnode(arg); return (NULL); } if (!f->fu_func && arg->pn_op && arg->pn_op->op_num == PT_OP_COMMA) { p = PP_mkbnode(PT_OP_MINUS, PP_mkfnode(func, arg->pn_left), PP_mkfnode(func, arg->pn_right)); free_pnode(arg); return p; } p = alloc_pnode(); p->pn_func = f; p->pn_left = arg; if (p->pn_left) p->pn_left->pn_use++; return (p); }
void sp_atom_finalize() { int i; for (i = 0; i < vec_num(sp_atom_callback_tbl); i++) { LMN_FREE(vec_get(sp_atom_callback_tbl, i)); } vec_free(sp_atom_callback_tbl); }
int vec_inserted_index(Vector *v, LmnWord w) { int i; for (i = 0; i < vec_num(v); i++){ if (vec_get(v, i) == w) return i; } vec_push(v, w); return vec_num(v) - 1; }
void vec_debugi(pvec v) { int i; printf("(%d/%d):", v->size, v->_capacity); for(i = 0; i < v->size; i++) { int* x = (int*)vec_get(v, i); printf(" %d", *x ); } printf("\n"); }
static char *get_caller_list() { Buffer *b = make_buffer(); for (int i = 0; i < vec_len(functions); i++) { if (i > 0) buf_printf(b, " -> "); buf_printf(b, "%s", vec_get(functions, i)); } buf_write(b, '\0'); return buf_body(b); }
static void set_reg_nums(Vector *args) { numgp = numfp = 0; for (int i = 0; i < vec_len(args); i++) { Node *arg = vec_get(args, i); if (is_flotype(arg->ty)) numfp++; else numgp++; } }
void moto_freeTreeCells(MotoEnv *env) { MotoTree *tree = env->tree; Vector *cells = tree->cells; int size = vec_size(cells); int i; for (i = 0; i < size; i++) { moto_freeCell(env, vec_get(cells, i)); } }
// Set the register class for parameter passing to RAX. // 0 is INTEGER, 1 is SSE, 2 is MEMORY. static void emit_builtin_reg_class(Node *node) { Node *arg = vec_get(node->args, 0); assert(arg->ty->kind == KIND_PTR); Type *ty = arg->ty->ptr; if (ty->kind == KIND_STRUCT) emit("mov $2, #eax"); else if (is_flotype(ty)) emit("mov $1, #eax"); else emit("mov $0, #eax"); }
doc_style_ptr doc_current_style(doc_ptr doc) { int ct = vec_length(doc->style_stack); doc_style_ptr style = NULL; if (ct > 0) style = vec_get(doc->style_stack, ct - 1); assert(style); return style; }
double efp_dipole_quadrupole_energy(const vec_t *d1, const double *quad2, const vec_t *dr) { double r = vec_len(dr); double r2 = r * r; double r5 = r2 * r2 * r; double r7 = r5 * r2; double d1dr = vec_dot(d1, dr); double q2dr = quadrupole_sum(quad2, dr); double d1q2dr = 0.0; for (size_t a = 0; a < 3; a++) for (size_t b = 0; b < 3; b++) { size_t idx = quad_idx(a, b); d1q2dr += quad2[idx] * vec_get(d1, a) * vec_get(dr, b); } return 5.0 / r7 * q2dr * d1dr - 2.0 / r5 * d1q2dr; }
void map_clear(hashmap_t* map) { for(size_t i = 0; i < map->active_buckets.length; ++i) { unsigned long pos = *(unsigned long*)vec_get(&map->active_buckets, i); hashmap_node_t* node = map->buckets[pos]; free_bucket(node); map->buckets[pos] = NULL; } vec_clear(&map->active_buckets); }
/** * ($start, $end, $g) * where * start, end = integer * g = ground * * Creates a (multi)set $g[$a], $g[$a+1], ..., $g[$b]. */ void integer_set(LmnReactCxt *rc, LmnMembrane *mem, LmnAtom a0, LmnLinkAttr t0, LmnAtom a1, LmnLinkAttr t1, LmnAtom a2, LmnLinkAttr t2) { Vector *srcvec; int i, j, n; int start, end; start = (int)a0; end = (int)a1; srcvec = vec_make(16); vec_push(srcvec, (LmnWord)LinkObj_make(a2, t2)); for (i = 0, n = start; n <= end; i++, n++) { Vector *dstlovec; ProcessTbl atommap; LinkObj l; lmn_mem_copy_ground(mem, srcvec, &dstlovec, &atommap); l = (LinkObj)vec_get(dstlovec, 0); lmn_mem_newlink(mem, n, LMN_INT_ATTR, 0, l->ap, t2, LMN_ATTR_GET_VALUE(l->pos)); lmn_mem_push_atom(mem, n, LMN_INT_ATTR); for (j = 0; j < vec_num(dstlovec); j++) LMN_FREE(vec_get(dstlovec, j)); vec_free(dstlovec); proc_tbl_free(atommap); } lmn_mem_delete_atom(mem, a0, t0); lmn_mem_delete_atom(mem, a1, t1); lmn_mem_delete_ground(mem, srcvec); for (i = 0; i < vec_num(srcvec); i++) LMN_FREE(vec_get(srcvec, i)); vec_free(srcvec); }
void map_traverse(hashmap_t* map, hashmap_traverse_t traverse, void* data) { for(size_t i = 0; i < map->active_buckets.length; ++i) { unsigned long pos = *(unsigned long*)vec_get(&map->active_buckets, i); hashmap_node_t* node = map->buckets[pos]; while(node) { traverse(node->key, node->value, data); node = node->next; } } }