Skip to content

Commit

Permalink
Merge branch 'master' into add_more_null_checks
Browse files Browse the repository at this point in the history
  • Loading branch information
lemire authored Aug 1, 2024
2 parents 1b5fec6 + 0268464 commit 85178e4
Show file tree
Hide file tree
Showing 19 changed files with 224 additions and 75 deletions.
13 changes: 7 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -321,11 +321,12 @@ paket-files/
__pycache__/
*.pyc

amalgamation_demo
amalgamation_demo.c
amalgamation_demo.cpp
roaring.c
roaring.h
roaring.hh
# Exclude amalgamation created files
/amalgamation_demo
/amalgamation_demo.c
/amalgamation_demo.cpp
/roaring.c
/roaring.h
/roaring.hh

#############END VISUAL STUDIO##############
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ if(CMAKE_C_COMPILER_ID STREQUAL "AppleClang" AND CMAKE_C_COMPILER_VERSION VERSIO
endif()
set(ROARING_LIB_NAME roaring)
set(PROJECT_VERSION_MAJOR 4)
set(PROJECT_VERSION_MINOR 0)
set(PROJECT_VERSION_PATCH 0)
set(ROARING_LIB_VERSION "4.0.0" CACHE STRING "Roaring library version")
set(PROJECT_VERSION_MINOR 1)
set(PROJECT_VERSION_PATCH 1)
set(ROARING_LIB_VERSION "4.1.1" CACHE STRING "Roaring library version")
set(ROARING_LIB_SOVERSION "16" CACHE STRING "Roaring library soversion")

option(ROARING_EXCEPTIONS "Enable exception-throwing interface" ON)
Expand Down
25 changes: 22 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,21 @@ int main(){
}
```

By default we use:
```C
static roaring_memory_t global_memory_hook = {
.malloc = malloc,
.realloc = realloc,
.calloc = calloc,
.free = free,
.aligned_malloc = roaring_bitmap_aligned_malloc,
.aligned_free = roaring_bitmap_aligned_free,
};
```

We require that the `free`/`aligned_free` functions follow the C
convention where `free(NULL)`/`aligned_free(NULL)` have no effect.


# Example (C)

Expand Down Expand Up @@ -749,13 +764,17 @@ We have optimizations specific to AVX2 and AVX-512 in the code, and they are tur

## Usage (Using `conan`)

You can install the library using the conan package manager:
You can install pre-built binaries for `roaring` or build it from source using [Conan](https://conan.io/). Use the following command to install latest version:

```
$ echo -e "[requires]\nroaring/0.3.3" > conanfile.txt
$ conan install .
conan install --requires="roaring/[*]" --build=missing
```

For detailed instructions on how to use Conan, please refer to the [Conan documentation](https://docs.conan.io/2/).

The `roaring` Conan recipe is kept up to date by Conan maintainers and community contributors.
If the version is out of date, please [create an issue or pull request](https://github.com/conan-io/conan-center-index) on the ConanCenterIndex repository.


## Usage (Using `vcpkg` on Windows, Linux and macOS)

Expand Down
2 changes: 1 addition & 1 deletion amalgamation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ DEMOCPP="amalgamation_demo.cpp"
#
ALL_PUBLIC_H="
$SCRIPTPATH/include/roaring/roaring_version.h
$SCRIPTPATH/include/roaring/roaring_types.h
$SCRIPTPATH/include/roaring/portability.h
$SCRIPTPATH/include/roaring/roaring_types.h
$SCRIPTPATH/include/roaring/bitset/bitset.h
$SCRIPTPATH/include/roaring/roaring.h
$SCRIPTPATH/include/roaring/memory.h
Expand Down
27 changes: 26 additions & 1 deletion benchmarks/run_container_benchmark.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,31 @@ int main() {
free(testvalues);
run_container_free(Bt);
}

printf("==dense range test \n");
for (int howmany = 32; howmany <= (1 << 16); howmany *= 8) {
run_container_t* Bt = run_container_create();
for (int j = 0; j < howmany; ++j) {
uint16_t min = (uint16_t)pcg32_random() % 4096;
uint16_t max = min + 4096;
int32_t nruns_greater =
rle16_count_greater(Bt->runs, Bt->n_runs, max);
int32_t nruns_less =
rle16_count_less(Bt->runs, Bt->n_runs - nruns_greater, min);
run_container_add_range_nruns(Bt, min, max, nruns_less,
nruns_greater);
}
printf("\n number of values in container = %d\n",
run_container_cardinality(Bt));
int card = run_container_cardinality(Bt);
uint32_t* out = malloc(sizeof(uint32_t) * (unsigned long)card);
BEST_TIME(run_container_to_uint32_array(out, Bt, 1234), card, repeat,
card);
free(out);

run_container_free(Bt);
}

printf("\n");

run_container_t* B1 = run_container_create();
Expand Down Expand Up @@ -170,4 +195,4 @@ int main() {
run_container_free(B2);
run_container_free(BO);
return 0;
}
}
2 changes: 1 addition & 1 deletion doxygen
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ PROJECT_NAME = "CRoaring"
# could be handy for archiving the generated documentation or if some version
# control system is used.

PROJECT_NUMBER = "4.0.0"
PROJECT_NUMBER = "4.1.1"

# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
Expand Down
10 changes: 10 additions & 0 deletions include/roaring/portability.h
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,16 @@ static inline uint32_t croaring_refcount_get(const croaring_refcount_t *val) {
#define CROARING_DEPRECATED
#endif // defined(__GNUC__) || defined(__clang__)

// We want to initialize structs to zero portably (C and C++), without
// warnings. We can do mystruct s = CROARING_ZERO_INITIALIZER;
#if __cplusplus
#define CROARING_ZERO_INITIALIZER \
{}
#else
#define CROARING_ZERO_INITIALIZER \
{ 0 }
#endif

// We need portability.h to be included first,
// but we also always want isadetection.h to be
// included (right after).
Expand Down
4 changes: 4 additions & 0 deletions include/roaring/roaring_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include <stdbool.h>
#include <stdint.h>

#include <roaring/portability.h>

#ifdef __cplusplus
extern "C" {
namespace roaring {
Expand Down Expand Up @@ -89,6 +91,8 @@ typedef struct roaring_statistics_s {
max_value; /* the maximal value, undefined if cardinality is zero */
uint32_t
min_value; /* the minimal value, undefined if cardinality is zero */

CROARING_DEPRECATED
uint64_t sum_value; /* deprecated always zero */

uint64_t cardinality; /* total number of values stored in the bitmap */
Expand Down
6 changes: 3 additions & 3 deletions include/roaring/roaring_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
// /include/roaring/roaring_version.h automatically generated by release.py, do not change by hand
#ifndef ROARING_INCLUDE_ROARING_VERSION
#define ROARING_INCLUDE_ROARING_VERSION
#define ROARING_VERSION "4.0.0"
#define ROARING_VERSION "4.1.1"
enum {
ROARING_VERSION_MAJOR = 4,
ROARING_VERSION_MINOR = 0,
ROARING_VERSION_REVISION = 0
ROARING_VERSION_MINOR = 1,
ROARING_VERSION_REVISION = 1
};
#endif // ROARING_INCLUDE_ROARING_VERSION
// clang-format on
13 changes: 8 additions & 5 deletions src/art/art.c
Original file line number Diff line number Diff line change
Expand Up @@ -1670,7 +1670,7 @@ static bool art_node_iterator_lower_bound(const art_node_t *node,
}

art_iterator_t art_init_iterator(const art_t *art, bool first) {
art_iterator_t iterator = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
art_iterator_t iterator = CROARING_ZERO_INITIALIZER;
if (art->root == NULL) {
return iterator;
}
Expand All @@ -1693,8 +1693,11 @@ bool art_iterator_lower_bound(art_iterator_t *iterator,
// a valid key. Start from the root.
iterator->frame = 0;
iterator->depth = 0;
return art_node_iterator_lower_bound(art_iterator_node(iterator),
iterator, key);
art_node_t *root = art_iterator_node(iterator);
if (root == NULL) {
return false;
}
return art_node_iterator_lower_bound(root, iterator, key);
}
int compare_result =
art_compare_prefix(iterator->key, 0, key, 0, ART_KEY_BYTES);
Expand Down Expand Up @@ -1727,15 +1730,15 @@ bool art_iterator_lower_bound(art_iterator_t *iterator,
}

art_iterator_t art_lower_bound(const art_t *art, const art_key_chunk_t *key) {
art_iterator_t iterator = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
art_iterator_t iterator = CROARING_ZERO_INITIALIZER;
if (art->root != NULL) {
art_node_iterator_lower_bound(art->root, &iterator, key);
}
return iterator;
}

art_iterator_t art_upper_bound(const art_t *art, const art_key_chunk_t *key) {
art_iterator_t iterator = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
art_iterator_t iterator = CROARING_ZERO_INITIALIZER;
if (art->root != NULL) {
if (art_node_iterator_lower_bound(art->root, &iterator, key) &&
art_compare_keys(iterator.key, key) == 0) {
Expand Down
12 changes: 3 additions & 9 deletions src/containers/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,8 @@ int array_container_shrink_to_fit(array_container_t *src) {

/* Free memory. */
void array_container_free(array_container_t *arr) {
if (arr->array !=
NULL) { // Jon Strabala reports that some tools complain otherwise
roaring_free(arr->array);
arr->array = NULL; // pedantic
}
if (arr == NULL) return;
roaring_free(arr->array);
roaring_free(arr);
}

Expand Down Expand Up @@ -177,10 +174,7 @@ void array_container_grow(array_container_t *container, int32_t min,
(uint16_t *)roaring_realloc(array, new_capacity * sizeof(uint16_t));
if (container->array == NULL) roaring_free(array);
} else {
// Jon Strabala reports that some tools complain otherwise
if (array != NULL) {
roaring_free(array);
}
roaring_free(array);
container->array =
(uint16_t *)roaring_malloc(new_capacity * sizeof(uint16_t));
}
Expand Down
7 changes: 2 additions & 5 deletions src/containers/bitset.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,8 @@ void bitset_container_add_from_range(bitset_container_t *bitset, uint32_t min,

/* Free memory. */
void bitset_container_free(bitset_container_t *bitset) {
if (bitset->words !=
NULL) { // Jon Strabala reports that some tools complain otherwise
roaring_aligned_free(bitset->words);
bitset->words = NULL; // pedantic
}
if (bitset == NULL) return;
roaring_aligned_free(bitset->words);
roaring_free(bitset);
}

Expand Down
Loading

0 comments on commit 85178e4

Please sign in to comment.