davidmoten / bplustree Goto Github PK
View Code? Open in Web Editor NEWB+-tree in java that stores to disk using memory mapped files, supports range queries and duplicate keys
License: Apache License 2.0
B+-tree in java that stores to disk using memory mapped files, supports range queries and duplicate keys
License: Apache License 2.0
Hey Dave,
Thank you for sharing this library.
I am getting the below exception while inserting byte[] into Btree.
Exception in thread "main" java.lang.ClassCastException: class [B cannot be cast to class java.lang.Comparable ([B and java.lang.Comparable are in module java.base of loader 'bootstrap')
at java.base/java.util.Comparators$NaturalOrderComparator.compare(Comparators.java:47)
at com.github.davidmoten.bplustree.internal.Util.getLocation(Util.java:54)
at com.github.davidmoten.bplustree.internal.Leaf.getLocation(Leaf.java:88)
at com.github.davidmoten.bplustree.internal.Leaf.insert(Leaf.java:44)
at com.github.davidmoten.bplustree.BPlusTree.insert(BPlusTree.java:262)
Any thoughts on what could be the cause?
I am implementing Comparable
on Key, and Serializable
on both Key and Value.
Below are my code references:
Driver.java
tree = BPlusTree.file().directory("")
.maxLeafKeys(32)
.maxNonLeafKeys(8)
.segmentSizeMB(1)
.keySerializer(Serializer.bytes(100))
.valueSerializer(Serializer.bytes(100))
.naturalOrder();
ByteConversion.java
public static byte[] convertToBytes(Object object) {
try (ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(bos)) {
out.writeObject(object);
return bos.toByteArray();
}catch (Exception ex){
ex.printStackTrace();
}
return null;
}
public static Object convertFromBytes(byte[] bytes) {
try (ByteArrayInputStream bis = new ByteArrayInputStream(bytes); ObjectInputStream in = new ObjectInputStream(bis)) {
return in.readObject();
}catch (Exception ex){
ex.printStackTrace();
}
return null;
}
Some simple code begin:
'''
public class Mytest {
public static void main(String[] args) {
BPlusTree<Integer, Integer> tree = BPlusTree.file() //
.directory(Testing.newDirectory()) // I copy your Testing class
.clearDirectory() //
.maxKeys(3) //
.segmentSizeMB(1) //
.keySerializer(Serializer.INTEGER) //
.valueSerializer(Serializer.INTEGER) //
.naturalOrder();
}
}
'''
And unfortunately error:
Exception in thread "main" java.lang.NoSuchMethodError: com.github.davidmoten.guavamini.Preconditions.checkNotNull(Ljava/lang/Object;)Ljava/lang/Object;
at com.github.davidmoten.bplustree.BPlusTree$BuilderFile.directory(BPlusTree.java:67)
at test.Mytest.main(Mytest.java:27)
sry I dont konw how to solve it:(
I want to delete some key value pairs as they come and go in real systems, can you provide some information on how to do this ?
I want to restore the previous state after the restart, but after the restart, I can only do queries but not insert data, once inserted, it will crash. What should I do?
I tested and found that there was an error in the results of the range query. My test code is as follows:
import com.github.davidmoten.bplustree.BPlusTree;
import com.github.davidmoten.bplustree.Serializer;
import org.apache.commons.io.FileUtils;
import java.io.File;
import java.io.IOException;
public class DiskBPlusTreeTest{
public static void main(String[] args){
String dir = System.getProperty("user.dir");
String indexDirectory = dir + File.separator + "test";
File file = new File(indexDirectory);
if(file.exists()){
try {
FileUtils.cleanDirectory(file);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
file.mkdirs();
BPlusTree<Long, byte[]> tree = BPlusTree.file().directory(file).maxKeys(128)
.keySerializer(Serializer.LONG).valueSerializer(Serializer.bytes(16)).naturalOrder();
int num = 40000;
for(int i = 0; i < num; ++i){
long key = i % 10;
byte[] record = new byte[16];
tree.insert(key, record);
}
Iterable<byte[]> records = tree.find(0L, 10L);
int cnt = 0;
for(byte[] record : records){
cnt++;
}
System.out.println(cnt);
}
}
The program should be output 40000, however, the output of my laptop is 36100.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.