예제 #1
0
static ERL_NIF_TERM macros(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
    const ERL_NIF_TERM* a;
    ERL_NIF_TERM lists, tuples;
    int arity;
    if (!enif_get_tuple(env, argv[0], &arity, &a) || arity != 9) {
	return enif_make_badarg(env);
    }
    
    lists = enif_make_list(env,9,
			   enif_make_list1(env,a[0]),
			   enif_make_list2(env,a[0],a[1]),
			   enif_make_list3(env,a[0],a[1],a[2]),
			   enif_make_list4(env,a[0],a[1],a[2],a[3]),
			   enif_make_list5(env,a[0],a[1],a[2],a[3],a[4]),
			   enif_make_list6(env,a[0],a[1],a[2],a[3],a[4],a[5]),
			   enif_make_list7(env,a[0],a[1],a[2],a[3],a[4],a[5],a[6]),
			   enif_make_list8(env,a[0],a[1],a[2],a[3],a[4],a[5],a[6],a[7]),
			   enif_make_list9(env,a[0],a[1],a[2],a[3],a[4],a[5],a[6],a[7],a[8]));
    tuples = enif_make_list(env,9,
			    enif_make_tuple1(env,a[0]),
			    enif_make_tuple2(env,a[0],a[1]),
			    enif_make_tuple3(env,a[0],a[1],a[2]),
			    enif_make_tuple4(env,a[0],a[1],a[2],a[3]),
			    enif_make_tuple5(env,a[0],a[1],a[2],a[3],a[4]),
			    enif_make_tuple6(env,a[0],a[1],a[2],a[3],a[4],a[5]),
			    enif_make_tuple7(env,a[0],a[1],a[2],a[3],a[4],a[5],a[6]),
			    enif_make_tuple8(env,a[0],a[1],a[2],a[3],a[4],a[5],a[6],a[7]),
			    enif_make_tuple9(env,a[0],a[1],a[2],a[3],a[4],a[5],a[6],a[7],a[8]));
    return enif_make_tuple2(env,lists,tuples);
}
예제 #2
0
ERL_NIF_TERM histogram_stats(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
    histogram_handle* handle;
    if (enif_get_resource(env,argv[0],histogram_RESOURCE,(void**)&handle))
    {
        pthread_mutex_lock(&(handle->m));

        std::vector<double> percentiles;
        percentiles.push_back(0.500);
        percentiles.push_back(0.950);
        percentiles.push_back(0.990);
        std::vector<double> scores(handle->p->percentiles(percentiles));

        ERL_NIF_TERM result =
                          enif_make_list8(env, 
                               STAT_TUPLE(ATOM_MIN, handle->p->min()),
                               STAT_TUPLE(ATOM_MAX, handle->p->max()),
                               STAT_TUPLE(ATOM_MEAN, handle->p->mean()),
                               STAT_TUPLE(ATOM_COUNT, handle->p->count()),
                               STAT_TUPLE(ATOM_STDDEV, handle->p->stddev()),
                               STAT_TUPLE(ATOM_P50, scores[0]),
                               STAT_TUPLE(ATOM_P95, scores[1]),
                               STAT_TUPLE(ATOM_P99, scores[2]));

        pthread_mutex_unlock(&(handle->m));
        return result;
    }
    else 
        return enif_make_badarg(env);
}
예제 #3
0
파일: geonum.c 프로젝트: chinnurtb/geonum
/**
 * Erlang Wrapper for binary geonum_neighbor
 */
ERL_NIF_TERM
erl_geonum_all_neighbors(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
    long long neighbors[8];
    long long geonum;

    if(!enif_get_int64(env, argv[0], &geonum)) {
        return enif_make_badarg(env);
    }

    geonum_all_neighbors(geonum, neighbors);

    return make_ok(env, enif_make_list8(env,
    		enif_make_int64(env, neighbors[0]),
    		enif_make_int64(env, neighbors[1]),
    		enif_make_int64(env, neighbors[2]),
    		enif_make_int64(env, neighbors[3]),
    		enif_make_int64(env, neighbors[4]),
    		enif_make_int64(env, neighbors[5]),
    		enif_make_int64(env, neighbors[6]),
    		enif_make_int64(env, neighbors[7])
    ));
}