aboutsummaryrefslogtreecommitdiff
path: root/example
diff options
context:
space:
mode:
authorLuca Deri <deri@ntop.org>2021-09-26 22:55:15 +0200
committerLuca Deri <deri@ntop.org>2021-09-26 22:55:15 +0200
commit1efabef4cfce64a373f014ee43bab371a82f7e87 (patch)
tree5bf0f85b7ff9c0d0f652192e3f5fba9391925f9b /example
parentc40cf4e0ec295dc707e71f1e3adbf0481035af06 (diff)
Added API for handling compressed bitmaps
ndpi_bitmap* ndpi_bitmap_alloc(); void ndpi_bitmap_free(ndpi_bitmap* b); u_int64_t ndpi_bitmap_cardinality(ndpi_bitmap* b); void ndpi_bitmap_set(ndpi_bitmap* b, u_int32_t value); void ndpi_bitmap_unset(ndpi_bitmap* b, u_int32_t value); bool ndpi_bitmap_isset(ndpi_bitmap* b, u_int32_t value); void ndpi_bitmap_clear(ndpi_bitmap* b); size_t ndpi_bitmap_serialize(ndpi_bitmap* b, char **buf); ndpi_bitmap* ndpi_bitmap_deserialize(char *buf); based on https://github.com/RoaringBitmap/CRoaring
Diffstat (limited to 'example')
-rw-r--r--example/ndpiReader.c33
1 files changed, 32 insertions, 1 deletions
diff --git a/example/ndpiReader.c b/example/ndpiReader.c
index ab93872f2..c5e235b61 100644
--- a/example/ndpiReader.c
+++ b/example/ndpiReader.c
@@ -4363,6 +4363,36 @@ void jitterUnitTest() {
/* *********************************************** */
+void compressedBitmapUnitTest() {
+ ndpi_bitmap *b = ndpi_bitmap_alloc(), *b1;
+ u_int i, trace = 0;
+ size_t ser;
+ char *buf;
+
+ for(i=0; i<1000; i++) {
+ u_int32_t v = rand();
+
+ if(trace) printf("%u ", v);
+ ndpi_bitmap_set(b, v);
+ assert(ndpi_bitmap_isset(b, v));
+ }
+
+ if(trace) printf("\n");
+
+ ser = ndpi_bitmap_serialize(b, &buf);
+ assert(ser > 0);
+
+ if(trace) printf("len: %lu\n", ser);
+ b1 = ndpi_bitmap_deserialize(buf);
+ assert(b1);
+
+ ndpi_free(buf);
+ ndpi_bitmap_free(b);
+ ndpi_bitmap_free(b1);
+}
+
+/* *********************************************** */
+
/**
@brief MAIN FUNCTION
**/
@@ -4392,7 +4422,7 @@ int original_main(int argc, char **argv) {
printf("nDPI Library version mismatch: please make sure this code and the nDPI library are in sync\n");
return(-1);
}
-
+
if(!skip_unit_tests) {
#ifndef DEBUG_TRACE
/* Skip tests when debugging */
@@ -4423,6 +4453,7 @@ int original_main(int argc, char **argv) {
ndpi_self_check_host_match();
analysisUnitTest();
rulesUnitTest();
+ compressedBitmapUnitTest();
#endif
}