在JavaScript中复合B-Tree索引

时间:2022-08-27 10:59:32

I am researching how to implement a b-tree in JavaScript that can support indexing compound fields. Example object:

我正在研究如何在JavaScript中实现支持索引复合字段的b树。例对象:

{
    "name": "Jim",
    "age": 14
}

A compound index on both "name" and "age" fields would allow fast full matching, prefix matching and range searches on either the "name" field or the "name" AND "age" field.

“name”和“age”字段的复合索引将允许在“name”字段或“name”字段或“age”字段中快速进行完全匹配、前缀匹配和范围搜索。

How would a b-tree index be coded so that the above can be achieved (in JavaScript or pseudo-code)?

如何编写b-tree索引以实现上述目标(使用JavaScript或伪代码)?

An off-the-shelf solution would also be useful but I am primarily interested in the nitty-gritty internals of the solution so a well explained process of indexing and retrieval would be the most useful answer.

一个现成的解决方案也很有用,但我主要对解决方案的本质感兴趣,因此一个解释良好的索引和检索过程将是最有用的答案。

Also any books or technical articles on the subject that anyone might be familiar with would help too!

任何关于这个主题的书籍或技术文章,任何人都可能熟悉,也会有所帮助!

1 个解决方案

#1


1  

Just make two B-Trees, one that only indexes on name, and another that indexes on name and then age. Now make an interface that allows for lookup in either tree, and offer insertion/deletion methods that do it in both trees to keep them in sync.

只做两个b -树,一个只索引名字,另一个索引名字和年龄。现在创建一个允许在任何树中查找的接口,并提供插入/删除方法,以便在两个树中进行查找,以保持它们的同步。

#1


1  

Just make two B-Trees, one that only indexes on name, and another that indexes on name and then age. Now make an interface that allows for lookup in either tree, and offer insertion/deletion methods that do it in both trees to keep them in sync.

只做两个b -树,一个只索引名字,另一个索引名字和年龄。现在创建一个允许在任何树中查找的接口,并提供插入/删除方法,以便在两个树中进行查找,以保持它们的同步。