Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试编写 B+Tree 的通用 C++ 实现。我的问题来自于 B+Tree 中有两种节点;内部节点包含指向子节点的键和指针,叶节点包含键和值,内部节点中的指针既可以指向其他内部节点,也可以指向叶节点。我不知道如何用模板建模这种关系(我不想使用强制转换或虚拟类)。
希望有一个解决我的问题的方法或更好的方法来在 C++ 中实现 B+Tree。
最简单的方法:
bool mIsInternalPointer; union { InternalNode<T>* mInternalNode; LeafNode<T>* mLeafNode; };
这可以通过使用来稍微简化boost::variant:)
boost::variant