Skip to content

Commit 32296ca

Browse files
committed
Added C APIs: BM_bvector_rshift1(), BM_bvector_merge(), int BM_bvector_set_bits()
1 parent 3b06936 commit 32296ca

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

lang-maps/libbm/include/libbm.h

+18
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,13 @@ BM_API_EXPORT int BM_bvector_swap(BM_BVHANDLE h1, BM_BVHANDLE h2);
195195
*/
196196
BM_API_EXPORT int BM_bvector_set_bit(BM_BVHANDLE h, unsigned int i, int val);
197197

198+
/* set list of bits to 1
199+
idx - index of bits to set
200+
idx_size - size of the array to set
201+
*/
202+
BM_API_EXPORT int BM_bvector_set_bits(BM_BVHANDLE h, unsigned int* idx, unsigned int idx_size);
203+
204+
198205
/* set bit to 1 without extra checks (faster).
199206
Use of this function requires full initialization by BM_bvector_init();
200207
i - index of a bit to set
@@ -404,6 +411,17 @@ BM_API_EXPORT int BM_bvector_combine_SUB(BM_BVHANDLE hdst, BM_BVHANDLE hsrc);
404411
*/
405412
BM_API_EXPORT int BM_bvector_combine_XOR(BM_BVHANDLE hdst, BM_BVHANDLE hsrc);
406413

414+
/* perform logical OR operation on two bit vectors
415+
hdst = hdst OR hsrc
416+
merge operation is faster than just OR, but it destroys the
417+
source vector (by borrowing its memory)
418+
*/
419+
BM_API_EXPORT int BM_bvector_merge(BM_BVHANDLE hdst, BM_BVHANDLE hsrc);
420+
421+
422+
/* Logical shift right by 1
423+
*/
424+
BM_API_EXPORT int BM_bvector_rshift1(BM_BVHANDLE hdst);
407425

408426
/* -------------------------------------------- */
409427
/* bvector operations with arrays */

lang-maps/libbm/src/libbm_impl.cpp

+53
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,23 @@ int BM_bvector_set_bit(BM_BVHANDLE h, unsigned int i, int val)
331331
return BM_OK;
332332
}
333333

334+
// -----------------------------------------------------------------
335+
336+
int BM_bvector_set_bits(BM_BVHANDLE h, unsigned int* idx, unsigned int idx_size)
337+
{
338+
if (!h || !idx)
339+
return BM_ERR_BADARG;
340+
BM_TRY
341+
{
342+
TBM_bvector* bv = (TBM_bvector*)h;
343+
bv->set(idx, idx_size);
344+
}
345+
BM_CATCH_ALL
346+
ETRY;
347+
return BM_OK;
348+
}
349+
350+
334351
// -----------------------------------------------------------------
335352

336353
int BM_bvector_flip_bit(BM_BVHANDLE h, unsigned int i)
@@ -762,6 +779,42 @@ int BM_bvector_calc_stat(BM_BVHANDLE h,
762779

763780
// -----------------------------------------------------------------
764781

782+
int BM_bvector_merge(BM_BVHANDLE hdst, BM_BVHANDLE hsrc)
783+
{
784+
if (!hdst || !hsrc)
785+
return BM_ERR_BADARG;
786+
787+
BM_TRY
788+
{
789+
TBM_bvector* bv1 = (TBM_bvector*)hdst;
790+
TBM_bvector* bv2 = (TBM_bvector*)hsrc;
791+
792+
bv1->merge(*bv2);
793+
}
794+
BM_CATCH_ALL
795+
ETRY;
796+
return BM_OK;
797+
}
798+
799+
// -----------------------------------------------------------------
800+
801+
int BM_bvector_rshift1(BM_BVHANDLE hdst)
802+
{
803+
if (!hdst)
804+
return BM_ERR_BADARG;
805+
806+
BM_TRY
807+
{
808+
TBM_bvector* bv = (TBM_bvector*)hdst;
809+
bv->shift_right();
810+
}
811+
BM_CATCH_ALL
812+
ETRY;
813+
return BM_OK;
814+
}
815+
816+
// -----------------------------------------------------------------
817+
765818

766819
int BM_bvector_combine_operation(BM_BVHANDLE hdst, BM_BVHANDLE hsrc, int opcode)
767820
{

0 commit comments

Comments
 (0)