Skip to content

Commit

Permalink
Run clang-format on the repo, add a github action to check formatting (
Browse files Browse the repository at this point in the history
…#577)

* Add clang-format directives to order includes

* Run clang-format.sh on the entire repo

* Add previous formatting commit to ignored revisions

This allows anyone to ignore the commit with:
   git blame --ignore-revs-file .git-blame-ignore-revs

Or to always use the ignore-revs file:
    git config blame.ignoreRevsFile .git-blame-ignore-revs

* Fix some include orders

* Add a github action to check clang-format

* Reference formatting in README and PR template

* Use .clang-format-ignore for github action

The github action expects a .clang-format-ignore file in order to exclude files,
so I've renamed it. It also expects the entries to match the full path as far as
I can tell, so I've switched them to be regexes rather than plain filenames.
  • Loading branch information
SLieve authored Feb 3, 2024
1 parent 676c863 commit 37c0388
Show file tree
Hide file tree
Showing 100 changed files with 5,178 additions and 4,898 deletions.
8 changes: 8 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
BasedOnStyle: Google
IndentWidth: 4
IncludeBlocks: Regroup
IncludeCategories:
- Regex: '^<roaring/'
Priority: 2
- Regex: '^"'
Priority: 3
- Regex: '.*'
Priority: 1
5 changes: 5 additions & 0 deletions .clang-format-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.*microbenchmarks/performancecounters/ibireme.h
.*microbenchmarks/performancecounters/linux-perf-events.h
.*microbenchmarks/performancecounters/event_counter.h
.*microbenchmarks/performancecounters/apple_arm_events.h
.*microbenchmarks/toni_ronnko_dirent.h
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Ran clang-format on the entire repo.
fd112ff5799e265fe172b3d28ff17388af108eb7
2 changes: 2 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Before submitting this PR, run `tools/clang-format.sh` on your changes. See the "Contributing" section in the README for details.

18 changes: 18 additions & 0 deletions .github/workflows/clang-format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: clang-format

on: [push]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: DoozyX/clang-format-lint-action@v0.17
with:
source: '.'
exclude: './cmake'
extensions: 'c,h,hh,cpp'
clangFormatVersion: 17
style: file # Use .clang-format at repo root

4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,10 @@ Justin Whear wrote a Zig wrapper available at https://github.com/jwhear/roaring-

https://groups.google.com/forum/#!forum/roaring-bitmaps

# Contributing

When contributing a change to the project, please run `tools/clang-format.sh` after making any changes. A github action runs on all PRs to ensure formatting is consistent with this.

# References about Roaring

- Daniel Lemire, Owen Kaser, Nathan Kurz, Luca Deri, Chris O'Hara, François Saint-Jacques, Gregory Ssi-Yan-Kai, Roaring Bitmaps: Implementation of an Optimized Software Library, Software: Practice and Experience Volume 48, Issue 4 April 2018 Pages 867-895 [arXiv:1709.07821](https://arxiv.org/abs/1709.07821)
Expand Down
105 changes: 52 additions & 53 deletions benchmarks/add_benchmark.c
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
#define _GNU_SOURCE
#include <roaring/roaring.h>
#include <math.h>
#include <stdio.h>

#include <roaring/roaring.h>

#include "benchmark.h"
#include "random.h"

enum order_e {
ASC,
DESC,
SHUFFLE
};
enum order_e { ASC, DESC, SHUFFLE };
typedef enum order_e order_t;

/*
Expand All @@ -19,42 +17,41 @@ typedef enum order_e order_t;
*
* TODO also generate overlapping intervals
*/
void make_data(uint32_t spanlen, uint32_t intvlen, double density, order_t order,
uint32_t **offsets_out, uint32_t *count_out) {

uint32_t count = floor(spanlen * density / intvlen);
uint32_t *offsets = malloc(count * sizeof(uint32_t));

uint64_t sum = 0;
for (uint32_t i = 0; i < count; i++) {
offsets[i] = pcg32_random_r(&pcg32_global);
sum += offsets[i];
}
for (uint32_t i = 0; i < count; i++) {
double v = offsets[i];
v /= sum;
v *= (spanlen - count * intvlen) / (double)intvlen;
uint32_t gap = floor(v);

if (i == 0) {
offsets[i] = gap;
} else {
offsets[i] = offsets[i-1] + intvlen + gap;
}
}

if (order == SHUFFLE) {
shuffle_uint32(offsets, count);
} else if (order == DESC) {
for (uint32_t i = 0, j = count-1; i < count/2; i++, j--) {
uint32_t tmp = offsets[i];
offsets[i] = offsets[j];
offsets[j] = tmp;
}
}

*offsets_out = offsets;
*count_out = count;
void make_data(uint32_t spanlen, uint32_t intvlen, double density,
order_t order, uint32_t **offsets_out, uint32_t *count_out) {
uint32_t count = floor(spanlen * density / intvlen);
uint32_t *offsets = malloc(count * sizeof(uint32_t));

uint64_t sum = 0;
for (uint32_t i = 0; i < count; i++) {
offsets[i] = pcg32_random_r(&pcg32_global);
sum += offsets[i];
}
for (uint32_t i = 0; i < count; i++) {
double v = offsets[i];
v /= sum;
v *= (spanlen - count * intvlen) / (double)intvlen;
uint32_t gap = floor(v);

if (i == 0) {
offsets[i] = gap;
} else {
offsets[i] = offsets[i - 1] + intvlen + gap;
}
}

if (order == SHUFFLE) {
shuffle_uint32(offsets, count);
} else if (order == DESC) {
for (uint32_t i = 0, j = count - 1; i < count / 2; i++, j--) {
uint32_t tmp = offsets[i];
offsets[i] = offsets[j];
offsets[j] = tmp;
}
}

*offsets_out = offsets;
*count_out = count;
}

double array_min(double *arr, size_t len) {
Expand All @@ -67,11 +64,13 @@ double array_min(double *arr, size_t len) {
return min;
}

void run_test(uint32_t spanlen, uint32_t intvlen, double density, order_t order) {
void run_test(uint32_t spanlen, uint32_t intvlen, double density,
order_t order) {
printf("intvlen=%u density=%f order=%s\n", intvlen, density,
(order == ASC ? "ASC" :
(order == DESC ? "DESC" :
(order == SHUFFLE ? "SHUFFLE" : "???"))));
(order == ASC
? "ASC"
: (order == DESC ? "DESC"
: (order == SHUFFLE ? "SHUFFLE" : "???"))));

uint32_t *offsets;
uint32_t count;
Expand Down Expand Up @@ -135,7 +134,7 @@ void run_test(uint32_t spanlen, uint32_t intvlen, double density, order_t order)
roaring_bitmap_t *r = roaring_bitmap_create();
RDTSC_START(cycles_start);
for (int64_t i = 0; i < count; i++) {
roaring_bitmap_add_range(r, offsets[i], offsets[i]+intvlen);
roaring_bitmap_add_range(r, offsets[i], offsets[i] + intvlen);
}
RDTSC_FINAL(cycles_final);
results[p] = (cycles_final - cycles_start) * 1.0 / count / intvlen;
Expand Down Expand Up @@ -165,7 +164,7 @@ void run_test(uint32_t spanlen, uint32_t intvlen, double density, order_t order)
roaring_bitmap_add_range(r, 0, spanlen);
RDTSC_START(cycles_start);
for (int64_t i = 0; i < count; i++) {
roaring_bitmap_remove_range(r, offsets[i], offsets[i]+intvlen);
roaring_bitmap_remove_range(r, offsets[i], offsets[i] + intvlen);
}
RDTSC_FINAL(cycles_final);
results[p] = (cycles_final - cycles_start) * 1.0 / count / intvlen;
Expand All @@ -176,21 +175,21 @@ void run_test(uint32_t spanlen, uint32_t intvlen, double density, order_t order)
free(offsets);
}

int main(int argc, char* argv[]) {
int main(int argc, char *argv[]) {
(void)argc;
(void)argv;

const uint32_t spanlen = 1000*1000;
const uint32_t spanlen = 1000 * 1000;
uint32_t intvlen_array[] = {1, 4, 16, 64};
order_t order_array[] = {SHUFFLE, ASC, DESC};
printf("[cycles/element]\n");
for (size_t r = 0; r < sizeof(order_array)/sizeof(order_array[0]); r++) {
for (size_t i = 0; i < sizeof(intvlen_array)/sizeof(intvlen_array[0]); i++) {
for (size_t r = 0; r < sizeof(order_array) / sizeof(order_array[0]); r++) {
for (size_t i = 0; i < sizeof(intvlen_array) / sizeof(intvlen_array[0]);
i++) {
run_test(spanlen, intvlen_array[i], 0.2, order_array[r]);
}
printf("\n");
}

return 0;
}

28 changes: 18 additions & 10 deletions benchmarks/adversarialunions_benchmark.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#define _GNU_SOURCE
#include <roaring/roaring.h>
#include <stdio.h>

#include <roaring/roaring.h>

#include "benchmark.h"
static inline int quickfull() {
printf("The naive approach works well when the bitmaps quickly become full\n");
printf(
"The naive approach works well when the bitmaps quickly become full\n");
uint64_t cycles_start, cycles_final;
size_t bitmapcount = 100;
size_t size = 1000000;
Expand All @@ -17,19 +20,21 @@ static inline int quickfull() {
}

RDTSC_START(cycles_start);
roaring_bitmap_t *answer0 = roaring_bitmap_or_many_heap(bitmapcount, (const roaring_bitmap_t **)bitmaps);
roaring_bitmap_t *answer0 = roaring_bitmap_or_many_heap(
bitmapcount, (const roaring_bitmap_t **)bitmaps);
RDTSC_FINAL(cycles_final);
printf("%f cycles per union (many heap) \n",
(cycles_final - cycles_start) * 1.0 / bitmapcount);

RDTSC_START(cycles_start);
roaring_bitmap_t *answer1 = roaring_bitmap_or_many(bitmapcount, (const roaring_bitmap_t **)bitmaps);
roaring_bitmap_t *answer1 =
roaring_bitmap_or_many(bitmapcount, (const roaring_bitmap_t **)bitmaps);
RDTSC_FINAL(cycles_final);
printf("%f cycles per union (many) \n",
(cycles_final - cycles_start) * 1.0 / bitmapcount);

RDTSC_START(cycles_start);
roaring_bitmap_t *answer2 = roaring_bitmap_copy(bitmaps[0]);
roaring_bitmap_t *answer2 = roaring_bitmap_copy(bitmaps[0]);
for (size_t i = 1; i < bitmapcount; i++) {
roaring_bitmap_or_inplace(answer2, bitmaps[i]);
}
Expand All @@ -48,7 +53,9 @@ static inline int quickfull() {
}

static inline int notsofull() {
printf("The naive approach works less well when the bitmaps do not quickly become full\n");
printf(
"The naive approach works less well when the bitmaps do not quickly "
"become full\n");
uint64_t cycles_start, cycles_final;
size_t bitmapcount = 100;
size_t size = 1000000;
Expand All @@ -62,19 +69,21 @@ static inline int notsofull() {
}

RDTSC_START(cycles_start);
roaring_bitmap_t *answer0 = roaring_bitmap_or_many_heap(bitmapcount, (const roaring_bitmap_t **)bitmaps);
roaring_bitmap_t *answer0 = roaring_bitmap_or_many_heap(
bitmapcount, (const roaring_bitmap_t **)bitmaps);
RDTSC_FINAL(cycles_final);
printf("%f cycles per union (many heap) \n",
(cycles_final - cycles_start) * 1.0 / bitmapcount);

RDTSC_START(cycles_start);
roaring_bitmap_t *answer1 = roaring_bitmap_or_many(bitmapcount, (const roaring_bitmap_t **)bitmaps);
roaring_bitmap_t *answer1 =
roaring_bitmap_or_many(bitmapcount, (const roaring_bitmap_t **)bitmaps);
RDTSC_FINAL(cycles_final);
printf("%f cycles per union (many) \n",
(cycles_final - cycles_start) * 1.0 / bitmapcount);

RDTSC_START(cycles_start);
roaring_bitmap_t *answer2 = roaring_bitmap_copy(bitmaps[0]);
roaring_bitmap_t *answer2 = roaring_bitmap_copy(bitmaps[0]);
for (size_t i = 1; i < bitmapcount; i++) {
roaring_bitmap_or_inplace(answer2, bitmaps[i]);
}
Expand All @@ -92,7 +101,6 @@ static inline int notsofull() {
return 0;
}


int main() {
printf("How to best aggregate the bitmaps is data-sensitive.\n");
quickfull();
Expand Down
5 changes: 3 additions & 2 deletions benchmarks/array_container_benchmark.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <roaring/portability.h>
#include <roaring/containers/array.h>
#include <roaring/misc/configreport.h>
#include <roaring/portability.h>

#include "benchmark.h"
#include "random.h"

Expand Down Expand Up @@ -33,7 +34,7 @@ void array_cache_prefetch(array_container_t* B) {
k += CACHELINESIZE / (int32_t)sizeof(uint16_t)) {
__builtin_prefetch(B->array + k);
}
#endif // !CROARING_REGULAR_VISUAL_STUDIO
#endif // !CROARING_REGULAR_VISUAL_STUDIO
}

int add_test(array_container_t* B) {
Expand Down
7 changes: 4 additions & 3 deletions benchmarks/benchmark.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@

#ifndef BENCHMARKS_INCLUDE_BENCHMARK_H_
#define BENCHMARKS_INCLUDE_BENCHMARK_H_
#include <roaring/portability.h>
#include <time.h>

#include <roaring/portability.h>

#ifdef ROARING_INLINE_ASM
#define CLOBBER_MEMORY __asm volatile("" ::: /* pretend to clobber */ "memory")
#else
Expand Down Expand Up @@ -60,8 +61,8 @@
#else // defined(RDTSC_CLOCK_ID)

/**
* Fall back to the `clock` function
*/
* Fall back to the `clock` function
*/
#define RDTSC_START(cycles) \
do { \
cycles = clock(); \
Expand Down
Loading

0 comments on commit 37c0388

Please sign in to comment.