6 #include "common_stub.hpp"
8 extern "C" value caml_bitmap_create(value size)
11 size_t bits = Long_val(size);
12 size_t words = bits / (8*sizeof(unsigned int));
13 unsigned int *buffer = (unsigned int*) calloc(words+1, sizeof(unsigned int));
15 sxsi_raise_msg("BP: cannot allocate memory");
16 CAMLreturn( (value) buffer);
19 extern "C" value caml_bitmap_resize(value bitmap, value nsize)
21 CAMLparam2(bitmap, nsize);
22 size_t bits = Long_val(nsize);
23 size_t bytes = (bits / (8 * sizeof(unsigned int)) + 1 ) * sizeof(unsigned int);
24 unsigned int * buffer = (unsigned int*) realloc((void *) bitmap, bytes);
26 sxsi_raise_msg("BP: cannot reallocate memory");
27 CAMLreturn((value) buffer);
30 extern "C" value caml_bitmap_setbit(value bitmap, value i, value b)
32 CAMLparam3(bitmap, i, b);
33 unsigned int j = Int_val(i);
34 unsigned int x = Bool_val(b);
35 bp_setbit ((unsigned int*) bitmap, j, x);
39 extern "C" void caml_bp_delete(value b)
42 bp * B = Obj_val<bp*>(b);
47 extern "C" value caml_bp_construct(value bitmap, value npar)
49 CAMLparam2(bitmap, npar);
51 bp * b = bp_construct(Int_val(npar), (unsigned int *) bitmap, OPT_DEGREE);
52 res = sxsi_alloc_custom<bp*>(caml_bp_delete);
53 Obj_val<bp*>(res) = b;
57 extern "C" value caml_bp_first_child(value b, value idx)
60 CAMLreturn (Val_int( bp_first_child(Obj_val<bp*>(b), Int_val(idx))));
64 extern "C" value caml_bp_next_sibling(value b, value idx)
67 CAMLreturn (Val_int(bp_next_sibling(Obj_val<bp*>(b), Int_val(idx))));
70 extern "C" value caml_bp_preorder_rank(value b, value idx)
73 CAMLreturn (Val_int(bp_preorder_rank(Obj_val<bp*>(b), Int_val(idx)) - 1));
77 extern "C" value caml_bp_load(value file)
82 int f1 = Int_val(file);
84 FILE * fd = fdopen(f2, "r");
86 sxsi_raise_msg("Error opening bp file");
89 result = sxsi_alloc_custom<bp*>(caml_bp_delete);
90 Obj_val<bp*>(result) = B;
94 extern "C" value caml_bp_save(value b, value file)
97 bp *B = Obj_val<bp*>(b);
98 int f1 = Int_val(file);
100 FILE * fd = fdopen(f2, "a");
103 sxsi_raise_msg("Error saving bp file");
106 CAMLreturn(Val_unit);
109 extern "C" value caml_bp_alloc_stats(value unit)
112 CAMLreturn (Val_long(bp_get_alloc_stats()));