bool MapDatabasePostgreSQL::saveBlock(const v3s16 &pos, const std::string &data) { // Verify if we don't overflow the platform integer with the mapblock size if (data.size() > INT_MAX) { errorstream << "Database_PostgreSQL::saveBlock: Data truncation! " << "data.size() over 0xFFFFFFFF (== " << data.size() << ")" << std::endl; return false; } verifyDatabase(); s32 x, y, z; x = htonl(pos.X); y = htonl(pos.Y); z = htonl(pos.Z); const void *args[] = { &x, &y, &z, data.c_str() }; const int argLen[] = { sizeof(x), sizeof(y), sizeof(z), (int)data.size() }; const int argFmt[] = { 1, 1, 1, 1 }; if (getPGVersion() < 90500) { execPrepared("write_block_update", ARRLEN(args), args, argLen, argFmt); execPrepared("write_block_insert", ARRLEN(args), args, argLen, argFmt); } else { execPrepared("write_block", ARRLEN(args), args, argLen, argFmt); } return true; }
static void test(struct socket_server *ss) { pthread_t pid; pthread_create(&pid, NULL, _poll, ss); int i = 0; int connid = socket_server_connect(ss, 400, "127.0.0.1", 8888); getc(stdin); socket_server_start(ss, 401, connid); char* tmp[3] = { "hello", "world", "wong" }; int cnt = ARRLEN(tmp); char* contents[ARRLEN(tmp)]; for (i = 0; i < cnt; ++i) { contents[i] = malloc(strlen(tmp[i]) + 1); memcpy(contents[i], tmp[i], strlen(tmp[i])); } for (i = 0; i < cnt; ++i) { socket_server_send(ss, connid, contents[i], strlen(contents[i])); getc(stdin); } printf("done\n"); pthread_join(pid, NULL); }
int updateMemory(void) { #define ARRLEN(X) (sizeof(X) / sizeof(X[0])) long pagesize; /* using a long promotes the arithmetic */ size_t len; { static int mib[] = {CTL_HW, HW_PHYSMEM}; len = sizeof(Total); sysctl(mib, ARRLEN(mib), &Total, &len, NULL, 0); Total >>= 10; } { struct uvmexp x; static int mib[] = {CTL_VM, VM_UVMEXP}; len = sizeof(x); STotal = SUsed = SFree = -1; pagesize = 1; if(-1 < sysctl(mib, ARRLEN(mib), &x, &len, NULL, 0)) { pagesize = x.pagesize; STotal = (pagesize * x.swpages) >> 10; SUsed = (pagesize * x.swpginuse) >> 10; SFree = STotal - SUsed; } }
void test_nghttp2_hd_deflate_bound(void) { nghttp2_hd_deflater deflater; nghttp2_nv nva[] = {MAKE_NV(":method", "GET"), MAKE_NV("alpha", "bravo")}; nghttp2_bufs bufs; size_t bound, bound2; nghttp2_mem *mem; mem = nghttp2_mem_default(); frame_pack_bufs_init(&bufs); nghttp2_hd_deflate_init(&deflater, mem); bound = nghttp2_hd_deflate_bound(&deflater, nva, ARRLEN(nva)); CU_ASSERT(12 + 6 * 2 * 2 + nva[0].namelen + nva[0].valuelen + nva[1].namelen + nva[1].valuelen == bound); nghttp2_hd_deflate_hd_bufs(&deflater, &bufs, nva, ARRLEN(nva)); CU_ASSERT(bound > (size_t)nghttp2_bufs_len(&bufs)); bound2 = nghttp2_hd_deflate_bound(&deflater, nva, ARRLEN(nva)); CU_ASSERT(bound == bound2); nghttp2_bufs_free(&bufs); nghttp2_hd_deflate_free(&deflater); }
int main(void) { int A[] = {6, 2, 4, 3, 5, 1}; int i = 0; clock_t begin, end; printf("Tal før sortering:\n "); for(i = 0; i < ARRLEN(A); i++) printf("%d ", A[i]); printf("\n"); begin = clock(); MergeSort(A, 0, ARRLEN(A) - 1); end = clock(); printf("Tal efter sortering:\n "); for(i = 0; i < ARRLEN(A); i++) printf("%d ", A[i]); printf("\n"); printf("Kørselstid = %f\n", (double)(end - begin) / CLOCKS_PER_SEC); }
static int generateOFFSIVAL(OFFSIVALARR *oivr, int d_min, int d_max, const ResultSet *rsp) /**< Collect position intervals for the top scoring results of * the largest fragment. * Array of results must have been sorted by rsr[i].swatscor. */ { int errcode; struct SETUPOFFSIVALARG_ arg; resultSetGetNumberOfResultsInSegment(0, rsp); ARRLEN(*oivr) = (size_t) 0; if (resultSetGetNumberOfResultsInSegment(0, rsp) < 1) return ERRCODE_SUCCESS; arg.dmin = (SEQLEN_t) (d_min < 0)? 0: d_min; arg.dmax = (SEQLEN_t) (d_max < 0)? 0: d_max; if (arg.dmin > arg.dmax) return ERRCODE_ASSERT; arg.oivr = *oivr; arg.max_rank = 0; if ((errcode = resultSetDo(&arg, setupOFFSIVALcbf, rsp))) return errcode; *oivr = arg.oivr; /* sort intervals by sequence and lower limit */ qsort(*oivr, ARRLEN(*oivr), sizeof(OFFSIVAL), cmpOFFSIVAL); return ERRCODE_SUCCESS; }
static void resetPairs(ResultPairs *p) { ARRLEN(p->mpr) = 0; ARRLEN(p->ivr) = 0; p->status = 0; p->n_proper = 0; p->n_within = 0; }
void size_readable(float *size, const char **unit) { const char *units[] = { "", "K", "M", "G" }; int i; for (i = 0; i < ARRLEN(units) && *size > 1024.0; i++) *size /= 1024.0; *unit = units[MIN(i, ARRLEN(units) - 1)]; }
void resultSetBlankPairs(ResultPairs *p) { if ((p)) { ARRLEN(p->ivr) = 0; ARRLEN(p->mpr) = 0; p->status = 0; p->n_proper = 0; p->n_within = 0; p->dmin = 0; p->dmax = 0; } }
static void run_nghttp2_hd(void) { nghttp2_hd_deflater deflater; nghttp2_hd_inflater inflater; nghttp2_bufs bufs; int rv; nghttp2_nv nva1[] = { MAKE_NV(":scheme", "https"), MAKE_NV(":authority", "example.org"), MAKE_NV(":path", "/slashdot"), MAKE_NV("accept-encoding", "gzip, deflate"), MAKE_NV("foo", "bar")}; nghttp2_nv nva2[] = { MAKE_NV(":scheme", "https"), MAKE_NV(":authority", "example.org"), MAKE_NV(":path", "/style.css"), MAKE_NV("cookie", "nghttp2=FTW"), MAKE_NV("foo", "bar2")}; rv = frame_pack_bufs_init(&bufs); if (rv != 0) { return; } rv = nghttp2_hd_deflate_init(&deflater, nghttp2_mem_fm()); if (rv != 0) { goto deflate_init_fail; } rv = nghttp2_hd_inflate_init(&inflater, nghttp2_mem_fm()); if (rv != 0) { goto inflate_init_fail; } rv = deflate_inflate(&deflater, &inflater, &bufs, nva1, ARRLEN(nva1), nghttp2_mem_fm()); if (rv != 0) { goto deflate_hd_fail; } rv = deflate_inflate(&deflater, &inflater, &bufs, nva2, ARRLEN(nva2), nghttp2_mem_fm()); if (rv != 0) { goto deflate_hd_fail; } deflate_hd_fail: nghttp2_hd_inflate_free(&inflater); inflate_init_fail: nghttp2_hd_deflate_free(&deflater); deflate_init_fail: nghttp2_bufs_free(&bufs); }
static int flagOutPairsWithDoubleFragments(const ResultPairs *pairp, const ResultSet *rsrp, const ResultSet *rsmp) { int errcode; MATEPAIRARR mpr = pairp->mpr; size_t npairs = ARRLEN(pairp->mpr); MAPFLG_t const mask = MAPFLG_PROPER | MAPFLG_WITHIN | MAPFLG_INVALID; MAPFLG_t const properflg = MAPFLG_PROPER | MAPFLG_WITHIN; int nn, i, j; short qsegnoA, qsegnoB; if (npairs > INT_MAX) return ERRCODE_OVERFLOW; nn = (int) npairs; if ((errcode = resultSetGetNumberOfSegments(NULL, &qsegnoA, rsrp))) return errcode; if ((errcode = resultSetGetNumberOfSegments(NULL, &qsegnoB, rsmp))) return errcode; if (nn < 2 || (qsegnoA < 1 && qsegnoB < 1)) return ERRCODE_SUCCESS; for (i=0; i<nn; i++) { if ((mpr[i].mapflg&mask) == properflg) { /* is first proper pair, flag out all other pairs with complementary fragments */ int sxA = resultGetFragmentNo(mpr[i].ap); int sxB = resultGetFragmentNo(mpr[i].bp); for (j=0; j<nn; j++) { if (!(mpr[j].mapflg&MAPFLG_INVALID) && j != i && (mpr[j].mapflg&properflg) != properflg && (resultGetFragmentNo(mpr[j].ap) == sxA || resultGetFragmentNo(mpr[j].bp) == sxB) ) mpr[j].mapflg |= MAPFLG_INVALID; } } } /* skip the flagged out pairs */ for (j=0; j<nn && !(mpr[j].mapflg&MAPFLG_INVALID); j++); for (i=j+1; i<nn; i++) { if (!(mpr[i].mapflg&MAPFLG_INVALID)) mpr[j++] = mpr[i]; } ARRLEN(mpr) = (size_t) j; return ERRCODE_SUCCESS; }
void test_nghttp2_hd_deflate_same_indexed_repr(void) { nghttp2_hd_deflater deflater; nghttp2_hd_inflater inflater; nghttp2_nv nva1[] = {MAKE_NV("cookie", "alpha"), MAKE_NV("cookie", "alpha")}; nghttp2_nv nva2[] = {MAKE_NV("cookie", "alpha"), MAKE_NV("cookie", "alpha"), MAKE_NV("cookie", "alpha")}; nghttp2_bufs bufs; ssize_t blocklen; nva_out out; int rv; nghttp2_mem *mem; mem = nghttp2_mem_default(); frame_pack_bufs_init(&bufs); nva_out_init(&out); CU_ASSERT(0 == nghttp2_hd_deflate_init(&deflater, mem)); CU_ASSERT(0 == nghttp2_hd_inflate_init(&inflater, mem)); /* Encode 2 same headers. Emit 1 literal reprs and 1 index repr. */ rv = nghttp2_hd_deflate_hd_bufs(&deflater, &bufs, nva1, ARRLEN(nva1)); blocklen = nghttp2_bufs_len(&bufs); CU_ASSERT(0 == rv); CU_ASSERT(blocklen > 0); CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem)); CU_ASSERT(2 == out.nvlen); assert_nv_equal(nva1, out.nva, 2, mem); nva_out_reset(&out, mem); nghttp2_bufs_reset(&bufs); /* Encode 3 same headers. This time, emits 3 index reprs. */ rv = nghttp2_hd_deflate_hd_bufs(&deflater, &bufs, nva2, ARRLEN(nva2)); blocklen = nghttp2_bufs_len(&bufs); CU_ASSERT(0 == rv); CU_ASSERT(blocklen == 3); CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem)); CU_ASSERT(3 == out.nvlen); assert_nv_equal(nva2, out.nva, 3, mem); nva_out_reset(&out, mem); nghttp2_bufs_reset(&bufs); /* Cleanup */ nghttp2_bufs_free(&bufs); nghttp2_hd_inflate_free(&inflater); nghttp2_hd_deflate_free(&deflater); }
MapgenSpecificParams *EmergeManager::createMapgenParams(const std::string &mgname) { u32 i; for (i = 0; i < ARRLEN(reg_mapgens) && mgname != reg_mapgens[i].name; i++); if (i == ARRLEN(reg_mapgens)) { errorstream << "EmergeManager: Mapgen " << mgname << " not registered" << std::endl; return NULL; } MapgenFactory *mgfactory = reg_mapgens[i].factory; return mgfactory->createMapgenParams(); }
void test_nghttp2_hd_no_index(void) { nghttp2_hd_deflater deflater; nghttp2_hd_inflater inflater; nghttp2_bufs bufs; ssize_t blocklen; nghttp2_nv nva[] = { MAKE_NV(":method", "GET"), MAKE_NV(":method", "POST"), MAKE_NV(":path", "/foo"), MAKE_NV("version", "HTTP/1.1"), MAKE_NV(":method", "GET"), }; size_t i; nva_out out; int rv; nghttp2_mem *mem; mem = nghttp2_mem_default(); /* 1st :method: GET can be indexable, last one is not */ for (i = 1; i < ARRLEN(nva); ++i) { nva[i].flags = NGHTTP2_NV_FLAG_NO_INDEX; } frame_pack_bufs_init(&bufs); nva_out_init(&out); nghttp2_hd_deflate_init(&deflater, mem); nghttp2_hd_inflate_init(&inflater, mem); rv = nghttp2_hd_deflate_hd_bufs(&deflater, &bufs, nva, ARRLEN(nva)); blocklen = nghttp2_bufs_len(&bufs); CU_ASSERT(0 == rv); CU_ASSERT(blocklen > 0); CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem)); CU_ASSERT(ARRLEN(nva) == out.nvlen); assert_nv_equal(nva, out.nva, ARRLEN(nva), mem); CU_ASSERT(out.nva[0].flags == NGHTTP2_NV_FLAG_NONE); for (i = 1; i < ARRLEN(nva); ++i) { CU_ASSERT(out.nva[i].flags == NGHTTP2_NV_FLAG_NO_INDEX); } nva_out_reset(&out, mem); nghttp2_bufs_free(&bufs); nghttp2_hd_inflate_free(&inflater); nghttp2_hd_deflate_free(&deflater); }
Mapgen *EmergeManager::createMapgen(const std::string &mgname, int mgid, MapgenParams *mgparams) { u32 i; for (i = 0; i != ARRLEN(reg_mapgens) && mgname != reg_mapgens[i].name; i++); if (i == ARRLEN(reg_mapgens)) { errorstream << "EmergeManager; mapgen " << mgname << " not registered" << std::endl; return NULL; } MapgenFactory *mgfactory = reg_mapgens[i].factory; return mgfactory->createMapgen(mgid, mgparams, this); }
void test_nghttp2_nv_array_copy(void) { nghttp2_nv *nva; ssize_t rv; nghttp2_nv emptynv[] = {MAKE_NV("", ""), MAKE_NV("", "")}; nghttp2_nv nv[] = {MAKE_NV("alpha", "bravo"), MAKE_NV("charlie", "delta")}; nghttp2_nv bignv; bignv.name = (uint8_t*)"echo"; bignv.namelen = strlen("echo"); bignv.valuelen = (1 << 14) - 1; bignv.value = malloc(bignv.valuelen); memset(bignv.value, '0', bignv.valuelen); rv = nghttp2_nv_array_copy(&nva, NULL, 0); CU_ASSERT(0 == rv); CU_ASSERT(NULL == nva); rv = nghttp2_nv_array_copy(&nva, emptynv, ARRLEN(emptynv)); CU_ASSERT(0 == rv); CU_ASSERT(nva[0].namelen == 0); CU_ASSERT(nva[0].valuelen == 0); CU_ASSERT(nva[1].namelen == 0); CU_ASSERT(nva[1].valuelen == 0); nghttp2_nv_array_del(nva); rv = nghttp2_nv_array_copy(&nva, nv, ARRLEN(nv)); CU_ASSERT(0 == rv); CU_ASSERT(nva[0].namelen == 5); CU_ASSERT(0 == memcmp("alpha", nva[0].name, 5)); CU_ASSERT(nva[0].valuelen = 5); CU_ASSERT(0 == memcmp("bravo", nva[0].value, 5)); CU_ASSERT(nva[1].namelen == 7); CU_ASSERT(0 == memcmp("charlie", nva[1].name, 7)); CU_ASSERT(nva[1].valuelen == 5); CU_ASSERT(0 == memcmp("delta", nva[1].value, 5)); nghttp2_nv_array_del(nva); /* Large header field is acceptable */ rv = nghttp2_nv_array_copy(&nva, &bignv, 1); CU_ASSERT(0 == rv); nghttp2_nv_array_del(nva); free(bignv.value); }
gint read_memswap(gulong *mem, gulong *swap, gulong *MT, gulong *MU, gulong *ST, gulong *SU) { int pagesize; size_t len; #define ARRLEN(X) (sizeof(X)/sizeof(X[0])) { static int mib[2]; /* 64-bit datatype */ if(sizeof(size_t) == 8) { mib[0] = CTL_HW; mib[1] = HW_PHYSMEM64; } /* assume 32-bit datatype */ else { mib[0] = CTL_HW; mib[1] = HW_PHYSMEM; } len = sizeof(MTotal); sysctl(mib, ARRLEN(mib), &MTotal, &len, NULL, 0); MTotal >>= 10; } { static int mib[] = {CTL_HW, HW_PAGESIZE}; len = sizeof(pagesize); sysctl(mib, ARRLEN(mib), &pagesize, &len, NULL, 0); } #if __NetBSD_Version__ > 106210000 { struct swapent* swap; int nswap, n; STotal = SUsed = SFree = 0; if ((nswap = swapctl(SWAP_NSWAP, NULL, 0)) > 0) { swap = (struct swapent*)malloc(nswap * sizeof(*swap)); if (swapctl(SWAP_STATS, (void*)swap, nswap) == nswap) { for (n = 0; n < nswap; n++) { STotal += swap[n].se_nblks; SUsed += swap[n].se_inuse; } STotal = dbtob(STotal >> 10); SUsed = dbtob(SUsed >> 10); SFree = STotal - SUsed; } free(swap); } }
void img_init(img_t *img, win_t *win) { zoom_min = zoom_levels[0] / 100.0; zoom_max = zoom_levels[ARRLEN(zoom_levels) - 1] / 100.0; if (img == NULL || win == NULL) return; imlib_context_set_display(win->env.dpy); imlib_context_set_visual(win->env.vis); imlib_context_set_colormap(win->env.cmap); img->im = NULL; img->win = win; img->zoom = options->zoom; img->zoom = MAX(img->zoom, zoom_min); img->zoom = MIN(img->zoom, zoom_max); img->checkpan = false; img->dirty = false; img->aa = options->aa; img->alpha = true; img->slideshow = false; img->ss_delay = SLIDESHOW_DELAY * 1000; img->multi.cap = img->multi.cnt = 0; img->multi.animate = false; }
void img_init(img_t *img, win_t *win) { zoom_min = zoom_levels[0] / 100.0; zoom_max = zoom_levels[ARRLEN(zoom_levels) - 1] / 100.0; if (img == NULL || win == NULL) return; imlib_context_set_display(win->env.dpy); imlib_context_set_visual(win->env.vis); imlib_context_set_colormap(win->env.cmap); img->im = NULL; img->win = win; img->scalemode = options->scalemode; img->zoom = options->zoom; img->zoom = MAX(img->zoom, zoom_min); img->zoom = MIN(img->zoom, zoom_max); img->checkpan = false; img->dirty = false; img->aa = ANTI_ALIAS; img->alpha = ALPHA_LAYER; img->multi.cap = img->multi.cnt = 0; img->multi.animate = false; img->multi.length = img->multi.repeat = 0; img->cmod = imlib_create_color_modifier(); img->gamma = MIN(MAX(options->gamma, -GAMMA_RANGE), GAMMA_RANGE); img->ss.on = options->slideshow > 0; img->ss.delay = options->slideshow > 0 ? options->slideshow : SLIDESHOW_DELAY; }
void img_init(img_t *img, win_t *win) { zoom_min = zoom_levels[0] / 100.0; zoom_max = zoom_levels[ARRLEN(zoom_levels) - 1] / 100.0; if (img == NULL || win == NULL) return; imlib_context_set_display(win->env.dpy); imlib_context_set_visual(win->env.vis); imlib_context_set_colormap(win->env.cmap); img->im = NULL; img->win = win; img->zoom = options->zoom; img->zoom = MAX(img->zoom, zoom_min); img->zoom = MIN(img->zoom, zoom_max); img->checkpan = false; img->dirty = false; img->aa = RENDER_ANTI_ALIAS; img->alpha = !RENDER_WHITE_ALPHA; img->multi.cap = img->multi.cnt = 0; img->multi.animate = false; img->cmod = imlib_create_color_modifier(); img->gamma = MIN(MAX(options->gamma, -GAMMA_RANGE), GAMMA_RANGE); }
static int error_reply(nghttp2_session *session, http2_stream_data *stream_data) { int rv; int pipefd[2]; nghttp2_nv hdrs[] = { MAKE_NV(":status", "404") }; rv = pipe(pipefd); if(rv != 0) { warn("Could not create pipe"); rv = nghttp2_submit_rst_stream(session, NGHTTP2_FLAG_NONE, stream_data->stream_id, NGHTTP2_INTERNAL_ERROR); if(rv != 0) { warnx("Fatal error: %s", nghttp2_strerror(rv)); return -1; } return 0; } write(pipefd[1], ERROR_HTML, sizeof(ERROR_HTML) - 1); close(pipefd[1]); stream_data->fd = pipefd[0]; if(send_response(session, stream_data->stream_id, hdrs, ARRLEN(hdrs), pipefd[0]) != 0) { close(pipefd[0]); return -1; } return 0; }
static int fprintMatePairStats(FILE *fp, const MATEPAIRARR mpr, const RESULTPTRARR rresr, const RESULTPTRARR mresr, int dmin, int dmax, RSLTPAIRLIB_t pairlibcode, const InsHist *ihp) { int i, npair = ARRLEN(mpr); int n = 0; MAPFLG_t bitflg; int32_t count, totnum; RESULT *rrp, *mrp; for (i=0; i<npair; i++) { count = totnum = 0; bitflg = testProperPair(mpr[i].ins, mpr[i].flag, dmin, dmax, pairlibcode); if ((bitflg & MAPFLG_WITHIN) && (bitflg & MAPFLG_PROPER)) count = insGetHistoCount(&totnum, mpr[i].ins, 1, ihp); rrp = rresr[mpr[i].ax]; mrp = mresr[mpr[i].bx]; fprintf(fp, "PAIR[%i] posA=(%i, %llu), posB=(%i, %llu), ins=%i, mapqA=%i, mapqB=%i," \ "totnum=%i, counts=%i, mscor=%i\n", n, (int) rrp->sidx, (long long unsigned int) rrp->s_start, (int) mrp->sidx, (long long unsigned int) mrp->s_start, mpr[i].ins, rrp->mapscor, mrp->mapscor, totnum, count, mpr[i].mscor); n++; } return n; }
static int getNumberOfProperPairs(int *n_proper, const MATEPAIRARR mpr) /**< Returns the number of pairs within range that have the same best * pair score. * * \param n_proper Returns the number of proper pairs within the range (can be NULL). * \param mpr Array of mate pairs. * * \note Pair mapping score must have been assigned (assignScoresToPairs) and the * pairs sorted (cmpMATEPAIRbyScoreDescending) before this routine gets called. */ { int i, npair = ARRLEN(mpr); int n, npr; int32_t maxscor; if (npair < 1) return 0; n = npr = 0; for (i=0; i<npair; i++) { if (mpr[i].mscor < maxscor) break; if (mpr[i].mapflg & MAPFLG_WITHIN) { if (mpr[i].mapflg & MAPFLG_PROPER) { npr++; } n++; } } return n; }
void logRaw(LogLevel lev, const std::string &line) { STATIC_ASSERT(ARRLEN(g_level_to_android) == LL_MAX, mismatch_between_android_and_internal_loglevels); __android_log_print(g_level_to_android[lev], PROJECT_NAME_C, "%s", line.c_str()); }
int load(char *name) { char path[255]; char *err; struct dso_entry *entry = NULL; int i; for (i = 0; i < ARRLEN(loaded); i++) { if (!loaded[i].lib) { entry = &loaded[i]; break; } } if (!entry) { ftdm_log(FTDM_LOG_CRIT, "Cannot load more libraries\n"); return -1; } ftdm_build_dso_path(name, path, sizeof(path)); ftdm_log(FTDM_LOG_DEBUG, "Loading %s!\n", path); entry->lib = ftdm_dso_open(path, &err); if (!entry->lib) { ftdm_log(FTDM_LOG_CRIT, "Cannot load library '%s': %s\n", path, err); return -1; } strncpy(entry->name, name, sizeof(entry->name)-1); entry->name[sizeof(entry->name)-1] = 0; return 0; }
int draw_particles(void) { static Vec pointv[512]; static size_t pointc = ARRLEN(pointv, Vec); double z = zoom(); particle_t* p = particles; int i = 0; size_t count = HASH_COUNT(particles); while(i < count) { for(; p != NULL && i < pointc; p = p->hh.next, i++) { cpVect pos = cpBodyGetPos(p->body); if(fabs(pos.x) <= z / 2 && fabs(pos.y) <= z / 2) { // rough check if position is inside screen borders // TODO: possibly make it separate function pointv[i] = cpv2vec(pos); } } if(draw_points(pointv, i % pointc)) { return -1; } } return 0; }
static int getPairNumbersAndSortByCategory(int *n_proper, int *n_within, const ResultPairs *p) /**< Return the number of all pairs, n_proper and n_within can be NULL * Assign PAIR_CATEGORIES and sort according to those (proper pairs first) */ { int i, npr=0, nin=0; int n_pairs = ARRLEN(p->mpr); MATEPAIR *mp; for (i=0; i<n_pairs; i++) { mp = p->mpr + i; mp->cls = PAIRCAT_DEFAULT; if (mp->mapflg & MAPFLG_CONTIG) { if (mp->mapflg & MAPFLG_WITHIN) { nin++; if (mp->mapflg & MAPFLG_PROPER) { mp->cls = PAIRCAT_PROPER; npr++; } else { mp->cls = PAIRCAT_WITHINLIMIT; } } else { mp->cls = PAIRCAT_SAMECONTIG; } } } if (n_pairs > 1) qsort(p->mpr, n_pairs, sizeof(MATEPAIR), cmpMATEPAIRbyCategoryDescending); if (n_proper) *n_proper = npr; if (n_within) *n_within = nin; return n_pairs; }
void android_main(android_app *app) { int retval = 0; porting::app_global = app; Thread::setName("Main"); try { app_dummy(); char *argv[] = {strdup(PROJECT_NAME), NULL}; main(ARRLEN(argv) - 1, argv); free(argv[0]); #if !EXEPTION_DEBUG } catch (std::exception &e) { errorstream << "Uncaught exception in main thread: " << e.what() << std::endl; retval = -1; } catch (...) { errorstream << "Uncaught exception in main thread!" << std::endl; retval = -1; #else } catch (int) { // impossible #endif } porting::cleanupAndroid(); infostream << "Shutting down." << std::endl; exit(retval); }
static MATEPAIR *drawPairAtRandomByProbability(const MATEPAIRARR mpr) { int i; const int n_pairs = ARRLEN(mpr); double pthresh; double s = 0.0; MATEPAIR *mp = NULL; for (i=0; i<n_pairs; i++) s += mpr[i].pbf; pthresh = RANDRAW_UNIFORM_1()*s; s = 0.0; for (i=0; i<n_pairs; i++) { s += mpr[i].pbf; if (s + MINLOGARG > pthresh) { mp = mpr + i; break; } } if (mp == NULL && n_pairs > 0) mp = mpr + n_pairs - 1; return mp; }
static int setupOFFSIVALcbf(int *errcode, void *argp, const Result *rp) { SEQLEN_t s_start, s_end, q_start, q_end; SEQNUM_t sidx; RSLTFLG_t status; SEQLEN_t r0; OFFSIVAL *ivp; struct SETUPOFFSIVALARG_ *p = (struct SETUPOFFSIVALARG_ *) argp; if (resultGetSWRank(rp) > p->max_rank) return RSLTSCBRTN_BREAK; *errcode = resultGetData(&q_start, &q_end, &s_start, &s_end, &sidx, NULL, &status, rp); if ((*errcode)) return RSLTSCBRTN_STOP; if (status&RSLTFLAG_REVERSE) { r0 = s_end + q_start - 2; } else { r0 = s_start - q_start; } ARRNEXTP(ivp, p->oivr); if (!ivp) { *errcode = ERRCODE_NOMEM; return RSLTSCBRTN_STOP; } ivp->rp = rp; ivp->sidx = sidx; ivp->status = status; if (r0 >= p->dmax) { ivp->upper = r0 - p->dmin; ivp->lower = r0 - p->dmax; } else { ivp->upper = (r0 > p->dmin)? r0 - p->dmin: 0; ivp->lower = 0; } ARRNEXTP(ivp, p->oivr); if (!ivp) { *errcode = ERRCODE_NOMEM; return RSLTSCBRTN_STOP; } ivp->rp = rp; ivp->sidx = sidx; ivp->status = status; ivp->upper = r0 + p->dmax; ivp->lower = r0 + p->dmin; if (ivp->lower <= (ivp-1)->upper) { (ivp-1)->upper = ivp->upper; ARRLEN(p->oivr)--; } return RSLTSCBRTN_OK; }