Skip to content

Commit

Permalink
Merge pull request #3 from bloxbean/bitmap
Browse files Browse the repository at this point in the history
Bitmap implementation
  • Loading branch information
satran004 committed Dec 21, 2023
2 parents 783b9a0 + e07872f commit 63557de
Show file tree
Hide file tree
Showing 12 changed files with 1,183 additions and 3 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ way to store and retrieve data from RocksDB.
- [x] **MultiSet (RocksMultiSet) :** A basic implementation for set where you can add, remove and check if an item exists. It supports multiple sets under the same name, but different namespaces.
- [x] **ZSet (RocksZSet) :** A basic implementation for sorted set where you can add, remove and check if an item exists. You can find score of an item and items within a score range.
- [x] **MultiZSet (RocksMultiZSet) :** A basic implementation for sorted set where you can add, remove and check if an item exists. You can find score of an item and items within a score range. It supports multiple sorted sets under the same name, but different namespaces.
- [ ] **Map (RocksMap) :** Not implemented yet
- [x] **Map (RocksMap) :** A basic implementation for map where you can add, remove and check if an item exists.
- [x] **MultiMap (RocksMultiMap) :** A basic implementation for map where you can add, remove and check if an item exists. It supports multiple maps under the same name, but different namespaces.
- [x] **Bitmap (RocksBitmap) :** A basic implementation for bitmap where you can set, unset and check if a bit is set.
- [x] **MultiBitmap (RocksMultiBitmap) :** A basic implementation for bitmap where you can set, unset and check if a bit is set. It supports multiple bitmaps under the same name, but different namespaces.

## Pre-requisites

Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ subprojects {
maven {
url "https://oss.sonatype.org/content/repositories/snapshots"
}
maven { url 'https://jitpack.io' }
}

archivesBaseName = 'rocks-types-' + project.name
Expand Down
1 change: 1 addition & 0 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ dependencies {
api libs.slf4j.api

api libs.rocksdb
api libs.roaringbitmap
implementation libs.messagepack.jackson
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,24 @@ protected void writeBatch(WriteBatch batch, byte[] key, byte[] value) {
}
}

@SneakyThrows
protected void merge(WriteBatch writeBatch, byte[] key, byte[] value) {
if (writeBatch != null) {
mergeBatch(writeBatch, key, value);
} else {
merge(key, value);
}
}

@SneakyThrows
protected void mergeBatch(WriteBatch batch, byte[] key, byte[] value) {
if (columnFamilyHandle != null) {
batch.merge(columnFamilyHandle, key, value);
} else {
batch.merge(key, value);
}
}

@SneakyThrows
protected void deleteBatch(WriteBatch batch, byte[] key) {
if (columnFamilyHandle != null) {
Expand Down Expand Up @@ -93,6 +111,15 @@ protected void delete(byte[] key) {
}
}

@SneakyThrows
protected void merge(byte[] key, byte[] value) {
if (columnFamilyHandle != null) {
db.merge(columnFamilyHandle, key, value);
} else {
db.merge(key, value);
}
}

protected RocksIterator iterator() {
if (columnFamilyHandle != null) {
return db.newIterator(columnFamilyHandle);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package com.bloxbean.rocks.types.collection;

import com.bloxbean.rocks.types.config.RocksDBConfig;
import org.roaringbitmap.RoaringBitmap;
import org.rocksdb.WriteBatch;

/**
* Bitmap implementation using RocksDB
* RocksBitmap is a wrapper class for RocksMultiBitmap with default column family
*/
public class RocksBitmap extends RocksMultiBitmap {

public RocksBitmap(RocksDBConfig rocksDBConfig, String name) {
super(rocksDBConfig, name);
}

public RocksBitmap(RocksDBConfig rocksDBConfig, String name, int fragmentSize) {
super(rocksDBConfig, name, fragmentSize);
}

public RocksBitmap(RocksDBConfig rocksDBConfig, String columnFamily, String name) {
super(rocksDBConfig, columnFamily, name);
}

public RocksBitmap(RocksDBConfig rocksDBConfig, String columnFamily, String name, int fragmentSize) {
super(rocksDBConfig, columnFamily, name, fragmentSize);
}

public void setBit(int index) {
super.setBit(null, index);
}

public void setBitBatch(WriteBatch writeBatch, int... bitIndexes) {
super.setBitBatch(null, writeBatch, bitIndexes);
}

public boolean getBit(int bitIndex) {
return super.getBit(null, bitIndex);
}

public void clearBit(int bitIndex) {
super.clearBit(null, bitIndex);
}

public void clearBitBatch(WriteBatch writeBatch, int... bitIndexes) {
super.clearBitBatch(null, writeBatch, bitIndexes);
}

public long nextSetBit(int fromIndex) {
return super.nextSetBit(null, fromIndex);
}

public long nextClearBit(int fromIndex) {
return super.nextClearBit(null, fromIndex);
}

public long previousSetBit(int fromIndex) {
return super.previousSetBit(null, fromIndex);
}

public long previousClearBit(int fromIndex) {
return super.previousClearBit(null, fromIndex);
}

public RoaringBitmap getAllBits() {
return super.getAllBits(null);
}

public RoaringBitmap getBits(int fromFragmentIndex, int toFragmentIndex) {
return super.getBits(null, fromFragmentIndex, toFragmentIndex);
}
}

0 comments on commit 63557de

Please sign in to comment.