#ifndef LIBBM_INCLUDED_H__
#define LIBBM_INCLUDED_H__
#include <stddef.h>
#define BM_OK (0)
#define BM_ERR_BADALLOC (1)
#define BM_ERR_BADARG (2)
#define BM_ERR_RANGE (3)
#define BM_ERR_CPU (4)
#define BM_ERR_SERIALFORMAT (5)
#define BM_ERR_BAD_VALUE (6)
#define BM_ERR_RANK_SELECT_IDX_MISSING (7)
#define BM_ERR_DETACHED (101)
#define BM_ERR_JVM_NOT_SUPPORTED (102)
#define BM_ERR_JVM_OUT_OF_MEMORY (103)
#define BM_OK_MSG "BM-00: All correct"
#define BM_ERR_BADALLOC_MSG "BM-01: Allocation error"
#define BM_ERR_BADARG_MSG "BM-02: Invalid or missing function argument"
#define BM_ERR_RANGE_MSG "BM-03: Incorrect range or index"
#define BM_ERR_CPU_MSG "BM-04: Incorrect CPU vectorization (SIMD) version"
#define BM_ERR_SERIALFORMAT_MSG "BM-05: Serialization format error"
#define BM_ERR_BAD_VALUE_MSG "BM-06: Bad value"
#define BM_ERR_RANK_SELECT_IDX_MISSING_MSG "BM-07: Rank-Select index not constructed, call sync() first"
#define BM_ERR_DETACHED_MSG "BM-101: Current thread no attached to JVM"
#define BM_ERR_JVM_NOT_SUPPORTED_MSG "BM-102: JVM version not supported"
#define BM_ERR_JVM_OUT_OF_MEMORY_MSG "BM-103: Out of memory error"
#define BM_UNK_MSG "BM-XX: Unknown error"
#define BM_SIMD_NO 0
#define BM_SIMD_SSE2 1
#define BM_SIMD_SSE42 2
#define BM_SIMD_AVX2 5
#define BM_BVHANDLE void*
#define BM_BVEHANDLE void*
#define BM_TRUE 1
#define BM_FALSE 0
#if defined(_WIN32)
#ifdef BMDLLEXPORTS
# define BM_API_EXPORT __declspec(dllexport)
#else
#if defined(BM_USE_DLL)
# define BM_API_EXPORT __declspec(dllimport)
#else
# define BM_API_EXPORT
#endif
#endif
#else
# define BM_API_EXPORT
#endif
#ifdef __cplusplus
extern "C" {
#endif
struct BM_bvector_statistics
{
size_t bit_blocks;
size_t gap_blocks;
size_t max_serialize_mem;
size_t memory_used;
};
BM_API_EXPORT int BM_init(void*);
BM_API_EXPORT const char* BM_version(int* major, int* minor, int* patch);
BM_API_EXPORT int BM_simd_version(void);
BM_API_EXPORT const char* BM_error_msg(int errcode);
BM_API_EXPORT int BM_bvector_construct(BM_BVHANDLE* h, unsigned int bv_max);
BM_API_EXPORT int BM_bvector_init(BM_BVHANDLE h);
BM_API_EXPORT int BM_bvector_construct_copy(BM_BVHANDLE* h, BM_BVHANDLE hfrom);
BM_API_EXPORT int BM_bvector_free(BM_BVHANDLE h);
BM_API_EXPORT int BM_bvector_get_size(BM_BVHANDLE h, unsigned int* psize);
BM_API_EXPORT int BM_bvector_set_size(BM_BVHANDLE h, unsigned int new_size);
BM_API_EXPORT int BM_bvector_swap(BM_BVHANDLE h1, BM_BVHANDLE h2);
BM_API_EXPORT int BM_bvector_set_bit(BM_BVHANDLE h, unsigned int i, int val);
BM_API_EXPORT int BM_bvector_set_bits(BM_BVHANDLE h, unsigned int* idx, unsigned int idx_size);
BM_API_EXPORT int BM_bvector_set_bit_no_check(BM_BVHANDLE h, unsigned int i);
BM_API_EXPORT
int BM_bvector_set_bit_conditional(BM_BVHANDLE h,
unsigned int i,
int val,
int condition,
int* pchanged);
BM_API_EXPORT
int BM_bvector_flip_bit(BM_BVHANDLE h, unsigned int i);
BM_API_EXPORT
int BM_bvector_inc_bit(BM_BVHANDLE h, unsigned int i, int* carry_over);
BM_API_EXPORT int BM_bvector_set(BM_BVHANDLE h);
BM_API_EXPORT int BM_bvector_set_range(BM_BVHANDLE h,
unsigned int left,
unsigned int right,
int value);
BM_API_EXPORT int BM_bvector_invert(BM_BVHANDLE h);
BM_API_EXPORT int BM_bvector_clear(BM_BVHANDLE h, int free_mem);
BM_API_EXPORT int BM_bvector_extract_next(BM_BVHANDLE h, unsigned int i, unsigned int* pnext);
BM_API_EXPORT int BM_bvector_get_bit(BM_BVHANDLE h, unsigned int i, int* pval);
BM_API_EXPORT int BM_bvector_count(BM_BVHANDLE h, unsigned int* pcount);
BM_API_EXPORT
int BM_bvector_count_range(BM_BVHANDLE h,
unsigned int left,
unsigned int right,
unsigned int* pcount);
BM_API_EXPORT int BM_bvector_any(BM_BVHANDLE h, int* pval);
BM_API_EXPORT int BM_bvector_find(BM_BVHANDLE h,
unsigned int from, unsigned int* ppos, int* pfound);
BM_API_EXPORT int BM_bvector_find_reverse(BM_BVHANDLE h,
unsigned int* ppos, int* pfound);
BM_API_EXPORT int BM_bvector_find_rank(BM_BVHANDLE h,
unsigned int rank,
unsigned int from,
unsigned int* pidx,
int* pfound);
BM_API_EXPORT int BM_bvector_get_first(BM_BVHANDLE h, unsigned int* pi,
int* pfound);
BM_API_EXPORT int BM_bvector_get_next(BM_BVHANDLE h, unsigned int i,
unsigned int* pnext);
BM_API_EXPORT int BM_bvector_compare(BM_BVHANDLE h1, BM_BVHANDLE h2, int* pres);
BM_API_EXPORT int BM_bvector_find_first_mismatch(BM_BVHANDLE h1, BM_BVHANDLE h2,
unsigned int* pi,
int* pfound);
BM_API_EXPORT
int BM_bvector_optimize(BM_BVHANDLE h,
int opt_mode,
struct BM_bvector_statistics* pstat);
BM_API_EXPORT
int BM_bvector_calc_stat(BM_BVHANDLE h,
struct BM_bvector_statistics* pstat);
BM_API_EXPORT int BM_bvector_combine_operation(BM_BVHANDLE hdst, BM_BVHANDLE hsrc, int opcode);
BM_API_EXPORT int BM_bvector_combine_AND(BM_BVHANDLE hdst, BM_BVHANDLE hsrc);
BM_API_EXPORT int BM_bvector_combine_AND_2sc(BM_BVHANDLE hdst, BM_BVHANDLE hsrc1, BM_BVHANDLE hsrc2, int compress);
BM_API_EXPORT int BM_bvector_combine_OR(BM_BVHANDLE hdst, BM_BVHANDLE hsrc);
BM_API_EXPORT int BM_bvector_combine_OR_2sc(BM_BVHANDLE hdst, BM_BVHANDLE hsrc1, BM_BVHANDLE hsrc2, int compress);
BM_API_EXPORT int BM_bvector_combine_SUB(BM_BVHANDLE hdst, BM_BVHANDLE hsrc);
BM_API_EXPORT int BM_bvector_combine_SUB_2sc(BM_BVHANDLE hdst, BM_BVHANDLE hsrc1, BM_BVHANDLE hsrc2, int compress);
BM_API_EXPORT int BM_bvector_combine_XOR(BM_BVHANDLE hdst, BM_BVHANDLE hsrc);
BM_API_EXPORT int BM_bvector_combine_XOR_2sc(BM_BVHANDLE hdst, BM_BVHANDLE hsrc1, BM_BVHANDLE hsrc2, int compress);
BM_API_EXPORT int BM_bvector_merge(BM_BVHANDLE hdst, BM_BVHANDLE hsrc);
BM_API_EXPORT int BM_bvector_rshift1(BM_BVHANDLE hdst);
BM_API_EXPORT
int BM_bvector_combine_OR_arr(BM_BVHANDLE hdst,
const unsigned int* arr_begin,
const unsigned int* arr_end);
BM_API_EXPORT
int BM_bvector_combine_XOR_arr(BM_BVHANDLE hdst,
const unsigned int* arr_begin,
const unsigned int* arr_end);
BM_API_EXPORT
int BM_bvector_combine_SUB_arr(BM_BVHANDLE hdst,
const unsigned int* arr_begin,
const unsigned int* arr_end);
BM_API_EXPORT
int BM_bvector_combine_AND_arr(BM_BVHANDLE hdst,
const unsigned int* arr_begin,
const unsigned int* arr_end);
BM_API_EXPORT
int BM_bvector_combine_AND_arr_sorted(BM_BVHANDLE hdst,
const unsigned int* arr_begin,
const unsigned int* arr_end);
BM_API_EXPORT int BM_bvector_enumerator_construct(BM_BVHANDLE h, BM_BVEHANDLE* peh);
BM_API_EXPORT
int BM_bvector_enumerator_construct_from(BM_BVHANDLE h,
BM_BVEHANDLE* peh,
unsigned int pos);
BM_API_EXPORT int BM_bvector_enumerator_free(BM_BVEHANDLE eh);
BM_API_EXPORT int BM_bvector_enumerator_is_valid(BM_BVEHANDLE eh, int* pvalid);
BM_API_EXPORT int BM_bvector_enumerator_get_value(BM_BVEHANDLE eh, unsigned int* pvalue);
BM_API_EXPORT
int BM_bvector_enumerator_next(BM_BVEHANDLE eh,
int* pvalid, unsigned int* pvalue);
BM_API_EXPORT
int BM_bvector_enumerator_goto(BM_BVEHANDLE eh, unsigned int pos,
int* pvalid, unsigned int* pvalue);
BM_API_EXPORT
int BM_bvector_serialize(BM_BVHANDLE h,
char* buf,
size_t buf_size,
size_t* pblob_size);
BM_API_EXPORT
int BM_bvector_deserialize(BM_BVHANDLE h,
const char* buf,
size_t buf_size);
BM_API_EXPORT int BM_bvector_count_AND(BM_BVHANDLE h1, BM_BVHANDLE h2, unsigned int* pcount);
BM_API_EXPORT int BM_bvector_any_AND(BM_BVHANDLE h1, BM_BVHANDLE h2, unsigned int* pany);
BM_API_EXPORT int BM_bvector_count_XOR(BM_BVHANDLE h1, BM_BVHANDLE h2, unsigned int* pcount);
BM_API_EXPORT int BM_bvector_any_XOR(BM_BVHANDLE h1, BM_BVHANDLE h2, unsigned int* pany);
BM_API_EXPORT int BM_bvector_count_SUB(BM_BVHANDLE h1, BM_BVHANDLE h2, unsigned int* pcount);
BM_API_EXPORT int BM_bvector_any_SUB(BM_BVHANDLE h1, BM_BVHANDLE h2, unsigned int* pany);
BM_API_EXPORT int BM_bvector_count_OR(BM_BVHANDLE h1, BM_BVHANDLE h2, unsigned int* pcount);
BM_API_EXPORT int BM_bvector_any_OR(BM_BVHANDLE h1, BM_BVHANDLE h2, unsigned int* pany);
#ifdef __cplusplus
}
#endif
#endif