Java 中 Btree 或 B+tree 的现有实现

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2574661/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 09:24:37  来源:igfitidea点击:

Existing implementation of Btree or B+tree in Java

javadata-structuresb-tree

提问by rohit

I am doing a project in which I require btree or b+tree data structure. Does anyone know of an existing implementation of btree or b+tree (with insert, delete, search algorithms)? It should accept string as input and form btree or b+tree of these string.

我正在做一个需要 btree 或 b+tree 数据结构的项目。有谁知道 btree 或 b+tree 的现有实现(带有插入、删除、搜索算法)?它应该接受字符串作为输入并形成这些字符串的 btree 或 b+tree。

采纳答案by J?rn Schou-Rode

In the lack of details about the problem that you need to solve, I am going to allow myself to suggest an alternative solution that mightsolve your problem: use a red/black tree instead.

由于缺乏有关您需要解决的问题的详细信息,我将允许自己提出可能解决您的问题的替代解决方案:改用红/黑树。

The red/black tree can be thought of as a b-tree, as explained on Wikipedia:

红/黑树可以被认为是一个 b 树,如Wikipedia上所解释的:

A red-black tree is similar in structure to a B-tree of order 4, where each node can contain between 1 to 3 values and (accordingly) between 2 to 4 child pointers. In such B-tree, each node will contain only one value matching the value in a black node of the red-black tree, with an optional value before and/or after it in the same node, both matching an equivalent red node of the red-black tree [...]

红黑树在结构上类似于 4 阶 B 树,其中每个节点可以包含 1 到 3 个值和(相应地)2 到 4 个子指针。在这样的 B 树中,每个节点将只包含一个与红黑树的黑色节点中的值匹配的值,在同一节点之前和/或之后有一个可选值,两者都匹配红黑树的一个等效红色节点红黑树 [...]

Java has two built-in classes, TreeMapand TreeSet, providing red/black trees. None of these will take a string as input and grow a tree from it, but you might be able to implement something similar "around" one of those classes.

Java 有两个内置类,TreeMapTreeSet,提供红/黑树。这些都不会将字符串作为输入并从中生长一棵树,但是您可能能够“围绕”其中一个类实现类似的东西。

回答by Kevin Day

jdbmhas a very solid implementation of b+tree. Also h+tree which is an interesting related data structure.

jdbm有一个非常可靠的 b+tree 实现。还有 h+tree,这是一个有趣的相关数据结构。

回答by Charles Goodwin

You could try Electric's BTree(author page here).

你可以试试 Electric 的BTree这里的作者页面)。

回答by Justin

I've had to implement my own and open sourced the code.

我不得不实现自己的代码并开源。