Skip to content

Commit 2575e12

Browse files
committed
Bring C++ namespacing up to date
The bitset_t was once an internal implementation detail, but was made a part of the api. The roaring::internal namespace was still being used on bitset_t. This moves it to the API namespace. Also, the `misc` namespace where the configreport put its routines was not being included in some places. This fixes that. Additionally, the roaring.h C API is put inside roaring::api in C builds when you include it indirectly via roaring.hh, so qualified names of api::roaring_xxx() were used in roaring.hh. But it's possible to do `using namespace api;` inside roaring.hh inside of the `namespace roaring {` scope, and import the api definitions for that namespace so that you don't have to qualify the names and yet still don't leak them into either the global namespace or the roaring namespace. Finally, the various containers were being exposed as api vs. internal. While things like the iterators are api, things like run_container_t should be internal.
1 parent 120a6d6 commit 2575e12

18 files changed

Lines changed: 139 additions & 107 deletions

cpp/roaring/roaring.hh

Lines changed: 92 additions & 93 deletions
Large diffs are not rendered by default.

cpp/roaring/roaring64map.hh

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@
2828

2929
#include "roaring.hh"
3030

31-
namespace roaring {
31+
namespace roaring { // `using namespace` inside applies to this scope only
3232

33-
using roaring::Roaring;
33+
using namespace api; // roaring.h C APIs are put in roaring::api in C++
3434

3535
class Roaring64MapSetBitBiDirectionalIterator;
3636

@@ -40,8 +40,6 @@ typedef Roaring64MapSetBitBiDirectionalIterator
4040
Roaring64MapSetBitForwardIterator;
4141

4242
class Roaring64Map {
43-
typedef api::roaring_bitmap_t roaring_bitmap_t;
44-
4543
public:
4644
/**
4745
* Create an empty bitmap
@@ -1120,7 +1118,7 @@ class Roaring64Map {
11201118
* means that it should stop), and takes (uint64_t element, void* ptr) as
11211119
* inputs.
11221120
*/
1123-
void iterate(api::roaring_iterator64 iterator, void *ptr) const {
1121+
void iterate(roaring_iterator64 iterator, void *ptr) const {
11241122
for (const auto &map_entry : roarings) {
11251123
bool should_continue =
11261124
roaring_iterate64(&map_entry.second.roaring, iterator,
@@ -1980,7 +1978,7 @@ class Roaring64MapSetBitBiDirectionalIterator {
19801978
std::map<uint32_t, Roaring>::const_iterator
19811979
map_iter{}; // The empty constructor silences warnings from pedantic
19821980
// static analyzers.
1983-
api::roaring_uint32_iterator_t
1981+
roaring_uint32_iterator_t
19841982
i{}; // The empty constructor silences warnings from pedantic static
19851983
// analyzers.
19861984
};

include/roaring/roaring_types.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#ifdef __cplusplus
2020
extern "C" {
2121
namespace roaring {
22-
namespace api {
22+
namespace internal {
2323
#endif
2424

2525
/**
@@ -38,14 +38,20 @@ namespace api {
3838
extern "C++" {
3939
struct container_s {};
4040
}
41-
#define ROARING_CONTAINER_T ::roaring::api::container_s
41+
#define ROARING_CONTAINER_T ::roaring::internal::container_s
4242
#else
4343
#define ROARING_CONTAINER_T void // no compile-time checking
4444
#endif
4545

4646
#define ROARING_FLAG_COW UINT8_C(0x1)
4747
#define ROARING_FLAG_FROZEN UINT8_C(0x2)
4848

49+
#ifdef __cplusplus
50+
} // end namespace internal (but still in namespace roaring)
51+
using internal::container_s; // use scoped to this namespace block
52+
namespace api { // begin API namespace
53+
#endif
54+
4955
/**
5056
* Roaring arrays are array-based key-value pairs having containers as values
5157
* and 16-bit integer keys. A roaring bitmap might be implemented as such.
@@ -153,7 +159,7 @@ typedef struct roaring_container_iterator_s {
153159
#ifdef __cplusplus
154160
}
155161
}
156-
} // extern "C" { namespace roaring { namespace api {
162+
} // extern "C" { namespace roaring { namespace internal {
157163
#endif
158164

159165
#endif /* ROARING_TYPES_H */

src/bitset.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#ifdef __cplusplus
1212
extern "C" {
1313
namespace roaring {
14-
namespace internal {
14+
namespace api { // bitset_t was once internal, but made public in the API
1515
#endif
1616

1717
extern inline void bitset_print(const bitset_t *b);

src/bitset_util.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@
1717
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
1818
#endif
1919
#ifdef __cplusplus
20-
using namespace ::roaring::internal;
2120
extern "C" {
2221
namespace roaring {
23-
namespace api {
22+
namespace internal {
2423
#endif
2524

2625
#if CROARING_IS_X64
@@ -1143,7 +1142,7 @@ void bitset_flip_list(uint64_t *words, const uint16_t *list, uint64_t length) {
11431142
#ifdef __cplusplus
11441143
}
11451144
}
1146-
} // extern "C" { namespace roaring { namespace api {
1145+
} // extern "C" { namespace roaring { namespace internal {
11471146
#endif
11481147
#if defined(__GNUC__) && !defined(__clang__)
11491148
#pragma GCC diagnostic pop

tests/add_offset.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#ifdef __cplusplus // stronger type checking errors if C built in C++ mode
1414
using namespace roaring::internal;
15+
using namespace roaring::misc;
1516
#endif
1617

1718
#include "test.h"

tests/c_example1.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77

88
#include "test.h"
99

10+
#ifdef __cplusplus // stronger type checking errors if C built in C++ mode
11+
using namespace roaring::api;
12+
using namespace roaring::misc;
13+
#endif
14+
1015
bool roaring_iterator_sumall(uint32_t value, void *param) {
1116
*(uint32_t *)param += value;
1217
return true; // iterate till the end
@@ -162,4 +167,4 @@ int main() {
162167
roaring_bitmap_free(r3);
163168
printf("Success.\n");
164169
return EXIT_SUCCESS;
165-
}
170+
}

tests/cbitset_unit.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
#include "test.h"
88

9+
#ifdef __cplusplus // stronger type checking errors if C built in C++ mode
10+
using namespace roaring::api;
11+
#endif
12+
913
int compute_cardinality(bitset_t *b) {
1014
size_t k = 0;
1115
for (size_t i = 0; bitset_next_set_bit(b, &i); i++) {

tests/container_comparison_unit.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#ifdef __cplusplus // stronger type checking errors if C built in C++ mode
1919
using namespace roaring::internal;
20+
using namespace roaring::misc;
2021
#endif
2122

2223
#include "test.h"

tests/cpp_example1.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "roaring/roaring64map.hh"
55

66
using namespace roaring;
7+
78
int main() {
89
Roaring r1;
910
for (uint32_t i = 100; i < 1000; i++) {

0 commit comments

Comments
 (0)