Skip to content

Commit

Permalink
Release 1.0.1.0 & Add RoaringBitmapX
Browse files Browse the repository at this point in the history
  • Loading branch information
IceMimosa committed Oct 31, 2023
1 parent d15c7d5 commit 623a6ef
Show file tree
Hide file tree
Showing 25 changed files with 2,340 additions and 26 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ RoaringBitmap
[![docs-badge][]][docs]
![Java 11 CI](https://github.com/RoaringBitmap/RoaringBitmap/workflows/Java%2011%20CI/badge.svg)

| Maven Central for Bitlap RoaringBitmap | 中文说明 | RoaringBitmapX |
|------------------------------------------------------------------------------------------------------------|---------------------------|-------------------------------------------------------------------------------------------------------------|
| [![Maven Central](https://img.shields.io/maven-central/v/org.bitlap/RoaringBitmapX)][bitlap-RoaringBitmap] | [中文说明](./README.zh-CN.md) | [![Maven Central](https://img.shields.io/maven-central/v/org.bitlap/RoaringBitmapX)][bitlap-RoaringBitmapX] |

---

Bitsets, also called bitmaps, are commonly used as fast data structures.
Unfortunately, they can use too much memory. To compensate, we often use
compressed bitmaps.
Expand Down Expand Up @@ -541,3 +547,6 @@ This work was supported by NSERC grant number 26143.

[docs-badge]:https://img.shields.io/badge/API-docs-blue.svg?style=flat-square
[docs]:http://www.javadoc.io/doc/org.roaringbitmap/RoaringBitmap/

[bitlap-RoaringBitmap]:https://central.sonatype.com/artifact/org.bitlap/RoaringBitmap
[bitlap-RoaringBitmapX]:https://central.sonatype.com/artifact/org.bitlap/RoaringBitmapX
7 changes: 7 additions & 0 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# RoaringBitmapX

## RBM

## BBM

## CBM
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,44 @@ public final class RoaringArray implements Cloneable, Externalizable, Appendable

int size = 0;

protected RoaringArray() {
/**
* create RoaringArray with initial capacity
*/
public RoaringArray() {
this(INITIAL_CAPACITY);
}

RoaringArray(int initialCapacity) {
/**
* create RoaringArray
*
* @param initialCapacity initialCapacity
*/
public RoaringArray(int initialCapacity) {
this(new char[initialCapacity], new Container[initialCapacity], 0);
}


RoaringArray(char[] keys, Container[] values, int size) {
/**
* create RoaringArray
*
* @param keys keys
* @param values values
* @param size size
*/
public RoaringArray(char[] keys, Container[] values, int size) {
this.keys = keys;
this.values = values;
this.size = size;
}

public char[] getKeys() {
return keys;
}

public Container[] getValues() {
return values;
}

/**
* Find the smallest integer index larger than pos such that array[index].key>=x. If none can
* be found, return size. Based on code by O. Kaser.
Expand All @@ -61,7 +84,7 @@ protected RoaringArray() {
* @return the smallest index greater than pos such that array[index].key is at least as large as
* min, or size if it is not possible.
*/
protected int advanceUntil(char x, int pos) {
public int advanceUntil(char x, int pos) {
int lower = pos + 1;

// special handling for a possibly common sequential case
Expand Down Expand Up @@ -119,7 +142,12 @@ public void append(char key, Container value) {
size++;
}

void append(RoaringArray roaringArray) {
/**
* append a roaringArray
*
* @param roaringArray roaringArray
*/
public void append(RoaringArray roaringArray) {
assert size == 0 || roaringArray.size == 0
|| keys[size - 1] < roaringArray.keys[0];
if (roaringArray.size != 0 && size != 0) {
Expand Down Expand Up @@ -213,7 +241,7 @@ void appendCopy(RoaringArray sa, int startingIndex, int end) {
* @param startingIndex starting index in the other array
* @param end endingIndex (exclusive) in the other array
*/
protected void append(RoaringArray sa, int startingIndex, int end) {
public void append(RoaringArray sa, int startingIndex, int end) {
extendArray(end - startingIndex);
for (int i = startingIndex; i < end; ++i) {
this.keys[this.size] = sa.keys[i];
Expand All @@ -227,7 +255,10 @@ private int binarySearch(int begin, int end, char key) {
return Util.unsignedBinarySearch(keys, begin, end, key);
}

protected void clear() {
/**
* clear
*/
public void clear() {
this.keys = null;
this.values = null;
this.size = 0;
Expand Down Expand Up @@ -663,21 +694,26 @@ void extendArray(int k) {
}
}

// involves a binary search
protected Container getContainer(char x) {
/**
* involves a binary search
*
* @param x x
* @return container
*/
public Container getContainer(char x) {
int i = getContainerIndex(x);
if (i < 0) {
return null;
}
return this.values[i];
}

protected int getContainerIndex(char x) {
public int getContainerIndex(char x) {
int i = this.binarySearch(0, size, x);
return i;
}

protected Container getContainerAtIndex(int i) {
public Container getContainerAtIndex(int i) {
return this.values[i];
}

Expand Down Expand Up @@ -764,7 +800,13 @@ int getIndex(char x) {
return this.binarySearch(0, size, x);
}

protected char getKeyAtIndex(int i) {
/**
* getKeyAtIndex
*
* @param i i
* @return char
*/
public char getKeyAtIndex(int i) {
return this.keys[i];
}

Expand All @@ -777,7 +819,12 @@ public int hashCode() {
return hashvalue;
}

private boolean hasRunContainer() {
/**
* hasRunContainer
*
* @return boolean
*/
public boolean hasRunContainer() {
for (int k = 0; k < size; ++k) {
Container ck = values[k];
if (ck instanceof RunContainer) {
Expand All @@ -787,7 +834,12 @@ private boolean hasRunContainer() {
return false;
}

private int headerSize() {
/**
* headerSize
*
* @return int
*/
public int headerSize() {
if (hasRunContainer()) {
if (size < NO_OFFSET_THRESHOLD) {// for small bitmaps, we omit the offsets
return 4 + (size + 7) / 8 + 4 * size;
Expand Down Expand Up @@ -961,11 +1013,11 @@ public int serializedSizeInBytes() {
return count;
}

void setContainerAtIndex(int i, Container c) {
public void setContainerAtIndex(int i, Container c) {
this.values[i] = c;
}

protected int size() {
public int size() {
return this.size;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1065,6 +1065,10 @@ public static RoaringBitmap xor(final RoaringBitmap x1, final RoaringBitmap x2)

RoaringArray highLowContainer = null;

public RoaringArray getHighLowContainer() {
return highLowContainer;
}

/**
* Create an empty bitmap
*/
Expand All @@ -1076,7 +1080,7 @@ public RoaringBitmap() {
/**
* Wrap an existing high low container
*/
RoaringBitmap(RoaringArray highLowContainer) {
public RoaringBitmap(RoaringArray highLowContainer) {
this.highLowContainer = highLowContainer;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* two classes ({@link org.bitlap.roaringbitmap.buffer.MutableRoaringBitmap} and
* ({@link org.bitlap.roaringbitmap.buffer.ImmutableRoaringBitmap}) that users
* can rely upon for fast set of integers.
* It differs from the org.roaringbitmap in that
* It differs from the org.bitlap.roaringbitmap in that
* the backing stores are ByteBuffers.
*
* Initially, one wants to construct a bitmap using
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


/**
* The org.roaringbitmap package provides
* The org.bitlap.roaringbitmap package provides
* one class ({@link org.bitlap.roaringbitmap.RoaringBitmap}) that users
* can rely upon for fast set of integers.
*
Expand Down
19 changes: 19 additions & 0 deletions RoaringBitmapX/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
val deps: Map<String, String> by extra

plugins {
id("org.jetbrains.kotlin.jvm") version "1.9.10"
`java-library`
}

tasks.withType<Test>().configureEach {
useJUnitPlatform()
}

dependencies {
implementation(project(":RoaringBitmap"))

testImplementation("org.junit.jupiter:junit-jupiter-api:${deps["jupiter"]}")
testImplementation("org.junit.jupiter:junit-jupiter-params:${deps["jupiter"]}")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:${deps["jupiter"]}")
testImplementation("io.kotest:kotest-runner-junit5:5.7.2")
}
60 changes: 60 additions & 0 deletions RoaringBitmapX/src/main/kotlin/org/bitlap/roaringbitmap/x/@.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright 2020-2023 IceMimosa, jxnu-liguobin and the Bitlap Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.bitlap.roaringbitmap.x

import java.time.Duration

/**
* Do [func] when [flag] is true,
* if flag is false, return [t] only
*/
fun <T> doIf(flag: Boolean, t: T, func: (T) -> T): T {
if (flag) {
return func.invoke(t)
}
return t
}

/**
* see [kotlin.system.measureTimeMillis] and [kotlin.time.measureTimedValue]
*/
fun <T> elapsed(block: () -> T): Pair<T, Duration> {
val start = System.currentTimeMillis()
return block() to Duration.ofMillis(System.currentTimeMillis() - start)
}

/**
* like sql nvl
*/
fun <T> nvl(t: T?, default: T?): T? {
return t ?: default
}

/**
* like sql coalesce
*/
fun <T> coalesce(vararg t: T?): T? {
return t.find { it != null }
}

/**
* check [expr] cannot be false
*/
fun checkExpression(expr: Boolean, key: String = "expr", msg: String = "$key cannot be false") {
if (!expr) {
throw IllegalArgumentException(msg)
}
}
43 changes: 43 additions & 0 deletions RoaringBitmapX/src/main/kotlin/org/bitlap/roaringbitmap/x/AbsBM.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright 2020-2023 IceMimosa, jxnu-liguobin and the Bitlap Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.bitlap.roaringbitmap.x

import java.io.ObjectInput
import java.io.ObjectOutput

/**
* Abstract of [BM]
*/
abstract class AbsBM : BM {

@Volatile
@Transient
protected var modified: Boolean = true
protected fun <T> resetModify(func: () -> T): T {
modified = true
return func.invoke()
}

override fun writeExternal(out: ObjectOutput) {
out.write(this.getBytes())
}

override fun readExternal(`in`: ObjectInput) {
val bytes = ByteArray(`in`.available())
`in`.readFully(bytes)
this.setBytes(bytes)
}
}
Loading

0 comments on commit 623a6ef

Please sign in to comment.