Skip to content

Instantly share code, notes, and snippets.

View abhijitiitr's full-sized avatar

Abhijit Pratap Singh abhijitiitr

View GitHub Profile
-module(niftest).
-export([init/0, hello/1]).
-on_load(init/0).
init() ->
erlang:load_nif("./niftest", 1).
hello(_Pid) ->
/* niftest.c */
#include "erl_nif.h"
#include <unistd.h>
#include <stdio.h>
static ERL_NIF_TERM hello(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
int pid;
enif_get_int(env, argv[0], &pid);
if (pid==10 || pid==7 || pid == 1)
% c(binary_test).
% Ref=binary_test:open(<<1>>).
% binary_test:increment(Ref,<<3>>).
%%% The initial value of binary term changes always. Why is this happening?
-module(binary_test).
-export([open/1,increment/2,spawn_concurrent_increment/0,spawn_core/0]).
-on_load(init/0).
#include "nifpp.h"
#include <iostream>
using namespace std;
class BinaryStore
{
ERL_NIF_TERM binary_term;
public:
BinaryStore(ERL_NIF_TERM binary)
{
binary_term = binary;
-module(append_tuple).
-export([append_tuple/2,return_result_set/1]).
-on_load(init/0).
init() ->
ok = erlang:load_nif("./append_tuple", 0).
append_tuple(_T,_T1) ->
exit(nif_library_not_loaded).
#include "nifpp.h"
class ResultSet
{
std::vector<std::vector<nifpp::TERM>> array_of_result_sets;
int count;
public:
ResultSet()
{
count = 0;
-module(mmap_binary).
-export([open/1,inspect/1]).
-on_load(init/0).
% -include_lib("eunit/include/eunit.hrl").
init() ->
ok = erlang:load_nif("./mmap_binary", 0).
open(_Filename) ->
exit(nif_library_not_loaded).
#include "nifpp.h"
using namespace std;
static int load(ErlNifEnv* env, void** priv, ERL_NIF_TERM load_info)
{
nifpp::register_resource<int>(env, nullptr, "integer");
return 0;
}
static ERL_NIF_TERM open_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
This is an example how to perform multi-select faceting in ElasticSearch.
Selecting multiple values from the same facet will result in an OR filter between each of the values:
(facet1.value1 OR facet1.value2)
Faceting on more than one facet will result in an AND filter between each facet:
(facet1.value1 OR facet1.value2) AND (facet2.value1)
I have chosen to update the counts for each facet the selected value DOES NOT belong to since we are performing an AND between each facet. I have included an example that shows how to keep the counts if you don't want to do this (filter0.sh).