Giter VIP home page Giter VIP logo

bplustree's Issues

class ([B and java.lang.Comparable are in module java.base of loader 'bootstrap')

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;
    }

begin with bplusTree-file

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:(

range query function may exist bug

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.