Database 基于磁盘的B+-具有固定大小键和值的树实现

Database 基于磁盘的B+-具有固定大小键和值的树实现,database,data-structures,relational-database,b-tree,Database,Data Structures,Relational Database,B Tree,是否有库提供基于磁盘的B+树实现,专门为所有键都具有固定大小且所有值也具有固定大小(不一定与键具有相同的固定大小)的场景而设计 注意:是的,我想实现另一个玩具,概念验证RDBMS。这就是为什么我不使用SQL DBMS注释结束。 我并不特别介意图书馆是用什么语言写的。但是,我确实对库的功能有一些特定的要求。为了清楚起见,将用C语言编写的示例来说明这些要求 库必须足够灵活,允许我使用自己的比较函数。例如: struct comparer { void * extra; int (*f

是否有库提供基于磁盘的B+树实现,专门为所有键都具有固定大小且所有值也具有固定大小(不一定与键具有相同的固定大小)的场景而设计

注意:是的,我想实现另一个玩具,概念验证RDBMS。这就是为什么我不使用SQL DBMS注释结束。

我并不特别介意图书馆是用什么语言写的。但是,我确实对库的功能有一些特定的要求。为了清楚起见,将用C语言编写的示例来说明这些要求

库必须足够灵活,允许我使用自己的比较函数。例如:

struct comparer
{
    void * extra;
    int (*function)(
        void *, // closure over extra
        char *, // 1st value to be compared
        char *  // 2nd value to be compared
    );
};
struct index_spec
{
    size_t keylen, vallen;  // fixed lengths for keys and values
    struct comparer comp;   // comparison function for keys
};
struct queryable_index
{
    struct index_spec spec;
    FILE * file;            // opened in read mode
};

struct updateable_index
{
    struct index_spec spec;
    FILE * file;            // opened in read/write mode
};

struct queryable_index open_queryable_index
    (struct index_spec, const char *);

struct updateable_index open_updateable_index
    (struct index_spec spec, const char * filename);

struct queryable_index just_queryable_index
    (struct updateable_index index)
{
    struct queryable_index result;
    result.spec = index.spec;
    result.file = index.file;
    return result;
}
如何操作索引文件的机制由所有键的固定长度、所有值的固定长度和键的比较函数定义。例如:

struct comparer
{
    void * extra;
    int (*function)(
        void *, // closure over extra
        char *, // 1st value to be compared
        char *  // 2nd value to be compared
    );
};
struct index_spec
{
    size_t keylen, vallen;  // fixed lengths for keys and values
    struct comparer comp;   // comparison function for keys
};
struct queryable_index
{
    struct index_spec spec;
    FILE * file;            // opened in read mode
};

struct updateable_index
{
    struct index_spec spec;
    FILE * file;            // opened in read/write mode
};

struct queryable_index open_queryable_index
    (struct index_spec, const char *);

struct updateable_index open_updateable_index
    (struct index_spec spec, const char * filename);

struct queryable_index just_queryable_index
    (struct updateable_index index)
{
    struct queryable_index result;
    result.spec = index.spec;
    result.file = index.file;
    return result;
}
如果库在可查询索引和可更新索引之间建立了区别,并且在需要可查询索引时使用了可更新索引的机制,而不是相反,这将是一个非常好的做法(尽管不是强制性的)。例如:

struct comparer
{
    void * extra;
    int (*function)(
        void *, // closure over extra
        char *, // 1st value to be compared
        char *  // 2nd value to be compared
    );
};
struct index_spec
{
    size_t keylen, vallen;  // fixed lengths for keys and values
    struct comparer comp;   // comparison function for keys
};
struct queryable_index
{
    struct index_spec spec;
    FILE * file;            // opened in read mode
};

struct updateable_index
{
    struct index_spec spec;
    FILE * file;            // opened in read/write mode
};

struct queryable_index open_queryable_index
    (struct index_spec, const char *);

struct updateable_index open_updateable_index
    (struct index_spec spec, const char * filename);

struct queryable_index just_queryable_index
    (struct updateable_index index)
{
    struct queryable_index result;
    result.spec = index.spec;
    result.file = index.file;
    return result;
}

我所知道的最好的实现是。它是一个高性能嵌入式数据库系统,具有非常好的B树实现,由Sleepycat开发,后来被Oracle收购

它是用C编写的,支持您所关注的使用场景。它是开源的,如果您希望构建自己的实现,那么代码是寻找灵感的好地方

玩得开心

LevelDB: “leveldb库提供一个持久的键值存储。键和值是任意字节数组。这些键在键值存储中根据用户指定的比较器函数排序。”


leveldb主要基于LSM树,而不是B+树。