Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ jobs:
test:
strategy:
matrix:
go-version: [1.19.x, 1.20.x, 1.21.x, 1.22.x]
go-version: [1.24.x, 1.25.x]
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
Expand All @@ -23,7 +23,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: 1.22.x
go-version: 1.25.x
- name: Checkout code
uses: actions/checkout@v4
- name: Install musl
Expand Down
20 changes: 9 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: help all test format fmtcheck vet lint qa deps clean nuke
.PHONY: help all test format fmtcheck vet lint qa deps clean nuke



Expand Down Expand Up @@ -27,8 +27,8 @@ help:

# Alias for help target
all: help
test:
go test
test:
go test ./...
# Format the source code
format:
@find ./ -type f -name "*.go" -exec gofmt -w {} \;
Expand All @@ -41,32 +41,30 @@ fmtcheck:

# Check for syntax errors
vet:
GOPATH=$(GOPATH) go vet ./...
go vet ./...

# Check for style errors
lint:
GOPATH=$(GOPATH) PATH=$(GOPATH)/bin:$(PATH) golint ./...
go vet ./...





# Alias to run all quality-assurance checks
qa: fmtcheck test vet lint
qa: fmtcheck test vet

# --- INSTALL ---

# Get the dependencies
deps:
GOPATH=$(GOPATH) go get github.com/smartystreets/goconvey/convey
GOPATH=$(GOPATH) go get github.com/willf/bitset
GOPATH=$(GOPATH) go get github.com/golang/lint/golint
go mod download

# Remove any build artifact
clean:
GOPATH=$(GOPATH) go clean ./...
go clean ./...

# Deletes any intermediate file
nuke:
rm -rf ./target
GOPATH=$(GOPATH) go clean -i ./...
go clean -i ./...
44 changes: 41 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,51 @@ http://arxiv.org/abs/1402.6407 This paper used data from http://lemire.me/data/r



### Dependencies
### Requirements

None in particular.
Go 1.24 or better, and a C compiler (cgo). The CRoaring sources are bundled
with the package, so there is nothing else to install:

Naturally, you also need to grab the roaring code itself:
- go get github.com/RoaringBitmap/gocroaring

The bundled CRoaring version is reported by `gocroaring.CRoaringVersion`.

### 32-bit and 64-bit bitmaps

The package wraps both C APIs. `gocroaring.Bitmap` stores 32-bit integers and
wraps `roaring_bitmap_t`; `gocroaring.Bitmap64` stores 64-bit integers and
wraps `roaring64_bitmap_t`. The two types offer the same operations, with the
free functions of the 64-bit type carrying a `64` suffix (`Or64`, `And64`,
`Read64`, and so on).

```go
rb := gocroaring.New64()
rb.AddRange(1<<40, 1<<40+1000)
rb.RunOptimize()
fmt.Println(rb.Cardinality(), rb.Contains(1<<40+5))
```

### Memory management

Bitmaps and iterators hold memory allocated by C. That memory is released
automatically once the Go value becomes unreachable: we register a cleanup with
`runtime.AddCleanup` rather than a finalizer, which lets the garbage collector
reclaim a bitmap in a single cycle instead of two, and makes creating and
discarding bitmaps about 20% cheaper than the finalizer-based approach we used
previously. You may still call `Free` to release the C memory eagerly; doing so
cancels the cleanup, and calling `Free` twice is harmless.

Iteration reads values from C in blocks rather than one at a time, so walking a
bitmap through `Iterator()` is more than an order of magnitude faster than
paying for a crossing of the Go/C boundary per value. Use `NewIterator()` when
you need to move backwards or seek.

The CRoaring entry points are declared `#cgo nocallback` (none of them calls
back into Go) and, where the function does not keep the buffer it is given,
`#cgo noescape` (so the Go buffers we hand to C are not forced onto the heap).
The frozen views are deliberately left out of the `noescape` list, since they
do retain their buffer.


### Example

Expand Down
Loading
Loading