bplustree icon indicating copy to clipboard operation
bplustree copied to clipboard

range query function may exist bug

Open Josehokec opened this issue 2 years ago • 0 comments

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.

Josehokec avatar Sep 13 '23 07:09 Josehokec