Skip to content

Commit d97e2eb

Browse files
committed
Merge branch 'master' of github.com:RoaringBitmap/CRoaring
2 parents 75e7374 + 0901095 commit d97e2eb

File tree

7 files changed

+114
-10
lines changed

7 files changed

+114
-10
lines changed

.github/workflows/emscripten.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: emscripten
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
10+
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
11+
- uses: mymindstorm/setup-emsdk@6ab9eb1bda2574c4ddb79809fc9247783eaf9021 # v14
12+
- name: Verify
13+
run: emcc -v
14+
- name: Checkout
15+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v3.6.0
16+
- name: Configure
17+
run: emcmake cmake -B build
18+
- name: Build # We build but do not test
19+
run: cmake --build build

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,15 @@ configure_file ("${CMAKE_CURRENT_SOURCE_DIR}/tests/config.h.in"
108108
#################################
109109

110110
add_subdirectory(src)
111-
if(ENABLE_ROARING_TESTS)
111+
if(ENABLE_ROARING_TESTS AND NOT EMSCRIPTEN)
112112
if(CMAKE_SIZEOF_VOID_P EQUAL 8) # we only include the benchmarks on 64-bit systems.
113113
add_subdirectory(benchmarks)
114114
endif()
115115
add_subdirectory(tests)
116116
endif()
117117
find_program(BASH bash)
118118

119-
if(ENABLE_ROARING_TESTS AND BASH)
119+
if(ENABLE_ROARING_TESTS AND BASH AND NOT EMSCRIPTEN)
120120
message(STATUS "Amalgamation tests enabled")
121121
set(CROARING_SINGLEHEADER_FILES
122122
${CMAKE_CURRENT_BINARY_DIR}/amalgamation_demo.c

cpp/roaring64map.hh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include <algorithm>
1313
#include <cinttypes> // PRIu64 macro
14+
#include <climits> // for UINT64_MAX
1415
#include <cstdarg> // for va_list handling in bitmapOf()
1516
#include <cstdio> // for std::printf() in the printf() method
1617
#include <cstring> // for std::memcpy()
@@ -781,6 +782,9 @@ class Roaring64Map {
781782
* Returns true if the bitmap is full (cardinality is max uint64_t + 1).
782783
*/
783784
bool isFull() const {
785+
// This function is somewhat absurd. A full 64-bit bitmap would surely
786+
// exceed our memory limits.
787+
#if SIZE_MAX >= UINT64_MAX
784788
// only bother to check if map is fully saturated
785789
//
786790
// we put std::numeric_limits<>::max/min in parentheses
@@ -793,6 +797,11 @@ class Roaring64Map {
793797
return roaring_map_entry.second.isFull();
794798
})
795799
: false;
800+
#else
801+
// if SIZE_MAX < UINT64_MAX, then we cannot represent a full bitmap
802+
// in a 64-bit integer, so we return false.
803+
return false;
804+
#endif
796805
}
797806

798807
/**

src/containers/run.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ void run_container_offset(const run_container_t *c, container_t **loc,
157157
lo = run_container_create_given_capacity(lo_cap);
158158
memcpy(lo->runs, c->runs, lo_cap * sizeof(rle16_t));
159159
lo->n_runs = lo_cap;
160-
for (int i = 0; i < lo_cap; ++i) {
160+
for (unsigned int i = 0; i < lo_cap; ++i) {
161161
lo->runs[i].value += offset;
162162
}
163163
*loc = (container_t *)lo;
@@ -167,7 +167,7 @@ void run_container_offset(const run_container_t *c, container_t **loc,
167167
hi = run_container_create_given_capacity(hi_cap);
168168
memcpy(hi->runs, c->runs + pivot, hi_cap * sizeof(rle16_t));
169169
hi->n_runs = hi_cap;
170-
for (int i = 0; i < hi_cap; ++i) {
170+
for (unsigned int i = 0; i < hi_cap; ++i) {
171171
hi->runs[i].value += offset;
172172
}
173173
*hic = (container_t *)hi;

src/roaring64.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ static void extend_containers(roaring64_bitmap_t *r) {
129129
new_capacity = 5 * r->capacity / 4;
130130
}
131131
uint64_t increase = new_capacity - r->capacity;
132-
r->containers =
133-
roaring_realloc(r->containers, new_capacity * sizeof(container_t *));
132+
r->containers = (container_t **)roaring_realloc(
133+
r->containers, new_capacity * sizeof(container_t *));
134134
memset(r->containers + r->capacity, 0, increase * sizeof(container_t *));
135135
r->capacity = new_capacity;
136136
}
@@ -987,8 +987,8 @@ size_t roaring64_bitmap_shrink_to_fit(roaring64_bitmap_t *r) {
987987
}
988988
uint64_t new_capacity = r->first_free;
989989
if (new_capacity < r->capacity) {
990-
r->containers = roaring_realloc(r->containers,
991-
new_capacity * sizeof(container_t *));
990+
r->containers = (container_t **)roaring_realloc(
991+
r->containers, new_capacity * sizeof(container_t *));
992992
freed += (r->capacity - new_capacity) * sizeof(container_t *);
993993
r->capacity = new_capacity;
994994
}
@@ -2454,7 +2454,7 @@ roaring64_bitmap_t *roaring64_bitmap_frozen_view(const char *buf,
24542454
maxbytes -= sizeof(r->capacity);
24552455

24562456
r->containers =
2457-
(container_t *)roaring_malloc(r->capacity * sizeof(container_t *));
2457+
(container_t **)roaring_malloc(r->capacity * sizeof(container_t *));
24582458

24592459
// Container element counts.
24602460
if (maxbytes < r->capacity * sizeof(uint16_t)) {

tests/CMakeLists.txt

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,79 @@ endif()
6161

6262
get_directory_property(parent_dir PARENT_DIRECTORY)
6363
configure_file("${parent_dir}/tools/cmake/CTestCustom.cmake" "${CMAKE_BINARY_DIR}")
64+
65+
66+
# The amalgamate_demo and amalgamate_demo_cpp do not catch errors from our
67+
# quick start instructions.
68+
69+
if(BASH_EXECUTABLE)
70+
set(AMALGAMATION_DIR "${CMAKE_BINARY_DIR}/tests/amalgamation")
71+
file(MAKE_DIRECTORY "${AMALGAMATION_DIR}")
72+
73+
add_custom_command(
74+
OUTPUT "${AMALGAMATION_DIR}/roaring.c" "${AMALGAMATION_DIR}/roaring.h" "${AMALGAMATION_DIR}/roaring.hh"
75+
COMMAND "${BASH_EXECUTABLE}" "${CMAKE_SOURCE_DIR}/amalgamation.sh" "${AMALGAMATION_DIR}"
76+
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
77+
COMMENT "Running amalgamation.sh to generate amalgamated files"
78+
VERBATIM
79+
)
80+
81+
add_custom_target(amalgamation ALL
82+
DEPENDS "${AMALGAMATION_DIR}/roaring.c" "${AMALGAMATION_DIR}/roaring.h" "${AMALGAMATION_DIR}/roaring.hh"
83+
)
84+
85+
set(AMALG_C "${AMALGAMATION_DIR}/demo_amalg_c.c")
86+
file(WRITE "${AMALG_C}" "
87+
#include <stdio.h>
88+
#include <stdlib.h>
89+
#include \"roaring.c\"
90+
int main() {
91+
roaring_bitmap_t *r1 = roaring_bitmap_create();
92+
for (uint32_t i = 100; i < 1000; i++) roaring_bitmap_add(r1, i);
93+
printf(\"cardinality = %d\\n\", (int) roaring_bitmap_get_cardinality(r1));
94+
roaring_bitmap_free(r1);
95+
96+
bitset_t *b = bitset_create();
97+
for (int k = 0; k < 1000; ++k) {
98+
bitset_set(b, 3 * k);
99+
}
100+
printf(\"%zu \\n\", bitset_count(b));
101+
bitset_free(b);
102+
return EXIT_SUCCESS;
103+
}
104+
")
105+
106+
add_executable(amalg_c_demo "${AMALG_C}")
107+
add_dependencies(amalg_c_demo amalgamation)
108+
target_include_directories(amalg_c_demo PRIVATE "${AMALGAMATION_DIR}")
109+
110+
set(AMALG_CPP "${AMALGAMATION_DIR}/demo_amalg_cpp.cpp")
111+
file(WRITE "${AMALG_CPP}" "
112+
#include <iostream>
113+
#include \"roaring.hh\" // the amalgamated roaring.hh includes roaring64map.hh
114+
#include \"roaring.c\"
115+
int main() {
116+
roaring::Roaring r1;
117+
for (uint32_t i = 100; i < 1000; i++) {
118+
r1.add(i);
119+
}
120+
std::cout << \"cardinality = \" << r1.cardinality() << std::endl;
121+
122+
roaring::Roaring64Map r2;
123+
for (uint64_t i = 18000000000000000100ull; i < 18000000000000001000ull; i++) {
124+
r2.add(i);
125+
}
126+
std::cout << \"cardinality = \" << r2.cardinality() << std::endl;
127+
return 0;
128+
}
129+
")
130+
131+
add_executable(amalg_cpp_demo "${AMALG_CPP}")
132+
add_dependencies(amalg_cpp_demo amalgamation)
133+
target_include_directories(amalg_cpp_demo PRIVATE "${AMALGAMATION_DIR}")
134+
135+
add_test(NAME amalg_c_demo_test COMMAND amalg_c_demo)
136+
add_test(NAME amalg_cpp_demo_test COMMAND amalg_cpp_demo)
137+
else()
138+
message(STATUS "Bash executable not found, skipping amalgamation tests.")
139+
endif()

tools/cmake/FindCTargets.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
include(${PROJECT_SOURCE_DIR}/tools/cmake/Import.cmake)
22
set(BUILD_STATIC_LIB ON)
3-
if (ENABLE_ROARING_TESTS)
3+
if (ENABLE_ROARING_TESTS AND NOT EMSCRIPTEN)
44
if(ROARING_USE_CPM)
55
CPMAddPackage(
66
NAME cmocka

0 commit comments

Comments
 (0)