hhblaze / DBreeze

C# .NET NOSQL ( key value store embedded ) ACID multi-paradigm database management system.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Custom Comparator

HardySmith opened this issue · comments

Is it possible to use a custom comparator for my objects.
I use DBreeze just to store <byte[], byte[]>, but I have a special order to maintain.

Thanks for this great project!

commented

Hi, can you give a small example of your purpose?

I try to replace LevelDb (or Rocksdb) with DBreeze. I really like it. Seems to be really fast and realible.
However, my datastructures are binary only.

First 16 bits describe the table, next 8 some attributes, then indexnumber, later on a keytype and the byte[] value of something. maybe a rowident for an index-entry.

To maintain an order and to produce some secundary indexes, I have to compare my bytearray. In LevelDb this is possible by obening a Database and pass a option:

        options.Comparator = Comparator.Create(
            "MyCompare",
            (xs, ys) => Compare.Comparer.BinaryCompare(((NativeArray<byte>)xs).Select(x => x),
                ((NativeArray<byte>)ys).Select(y => y)));

Maybe that's not the intended way to use dbreeze, however a custom comparator might be comfortable sometimes.

commented

I understand, this meaning you took from LevelDb and I am not sure it is possible so directly in DBreeze. Here keys are lexicographically sorted for maximal efficient search. There are some special functions to help to covert numerical data types into "lexicographically" sortable.

Here are some docs, like How DBreeze index works, to have understanding about the fact that we create indexes depending upon queries we are going to apply and Object-DBreeze to see that query types can be so different that leads to rearranging of the key and appearance of the secondary indices.

Keys are created for different types of range search and traversing and can be created manually by using functions from
DBreeze.Utils.BytesProcessing that contains rich library to work with byte[]: conatenating, comparation (_ByteArrayEquals), cutting and so on...

Please reopen that issue if you have practical advices that are really implementable concerning your question.