C++ 文字处理应用

C++ 文字处理应用,c++,C++,我正在尝试实现一种数据结构,它允许我尽快在数据库中查找数字。假设我有一个数据库,有5450个不同的数字。我主要关心的是速度,而不是内存效率。我在网上找到了这篇关于多路树的文章:。所以我决定实现一个10路树,其中每个节点都是一个大小为10的数组,但是我在如何为结构创建类方面有点困难。下面是我提出的一个大致轮廓: class MSTNode{ bool isDigit; //is it one of the digit in the number int arrayNode[]; MS

我正在尝试实现一种数据结构,它允许我尽快在数据库中查找数字。假设我有一个数据库,有5450个不同的数字。我主要关心的是速度,而不是内存效率。我在网上找到了这篇关于多路树的文章:。所以我决定实现一个10路树,其中每个节点都是一个大小为10的数组,但是我在如何为结构创建类方面有点困难。下面是我提出的一个大致轮廓:

class MSTNode{
  bool isDigit; //is it one of the digit in the number
  int arrayNode[];

  MST(bool isWord): isWord(isWord){
    arrayNode[] = [0,1,2,3,4,5,6,7,8,9];
  }
}


class MST{
  MSTNode * root;

  //What functions should be included in this class?
 //Insert Function?
 //Search Function?
}

我只需要一点帮助就可以了。如果有人能指出我上述设计的潜在问题,我将不胜感激。应该包括什么?什么不应该?基本上,我需要帮助来设计数据结构。无论如何,我都不想从你那里得到免费代码。我只需要在设计开始时得到帮助,其余的我都可以实现。

您可能会遇到以下情况:

class MSTNode{
public:
    void Insert(unsigned int n) {
        // GetOrCreate MSTNode in the first digit of n
        // and recursively call insert with n without this digit
        // once no more digit, set the isFinal flag.
    }

    bool Search(unsigned int n) const {
        // Get MSTNode of the first digit of n
        // if nullptr, return false.
        // and recursively call Search with n without this digit
        // once no more digit, return the isFinal flag.
    }

private:
  std::unique_ptr<MSTNode> arrayNode[10];
  bool isFinal = false; //is it one of the digit in the number
};
类MSTNode{
公众:
无效插入(无符号整数n){
//GetOrCreate MSTNode位于n的第一位
//并递归调用带有n的insert,而不使用此数字
//一旦不再有数字,设置isFinal标志。
}
布尔搜索(无符号整数n)常量{
//获取n的第一个数字的MSTNode
//如果为空,则返回false。
//并递归调用带有n的搜索,而不使用此数字
//一旦没有更多的数字,返回isFinal标志。
}
私人:
std::unique_ptr arrayNode[10];
bool isFinal=false;//它是数字中的一个数字吗
};

使用第一个
MSTNode
根。

这个问题似乎与主题无关,因为它是关于代码审查的。您是否试图重新发明?或多或少,我试图发明一个具有O(log(base 10)N)的树。问题是每个节点都应该有一个大小为10的数组实现这一点的一种方法是让数组包含指向节点(或NULL)的指针。非常感谢。只有一个简单的问题。我需要初始化arrayNode数组吗?老实说,这是我第一次看到这个独特的_ptr@JoeCool:std::unique的默认构造函数已将指针设置为
nullptr
。因此不需要显式初始化。