c++ - 如何使用 Judy 阵列

标签 c++ data-structures

我对 Judy Arrays 很感兴趣并尝试使用它。但是我无法使用它做任何有用的事情。每次它给我转换错误时。示例 C++ 代码和下面给出的错误。

#include "Judy.h"
#include <iostream>

using namespace std;

int main()
{
    int      Rc_int;                           // return code - integer
    Word_t   Rc_word;                          // return code - unsigned word
    Word_t   Index = 12, Index1 = 34, Index2 = 55, Nth;
    Word_t  PValue;                            // pointer to return value
    //Pvoid_t PJLArray = NULL;                 // initialize JudyL array


    Pvoid_t JudyArray = NULL;
    char      String[100];

    PWord_t _PValue;
    JSLI( JudyArray, _PValue, (uint8_t *) String);  

    return(0);

} // main()

这给了我错误

m.cpp: In function ‘int main()’:
m.cpp:19: error: invalid conversion from ‘long unsigned int**’ to ‘void**’
m.cpp:19: error:   initializing argument 1 of ‘void** JudySLIns(void**, const uint8_t*, J_UDY_ERROR_STRUCT*)’

请任何人帮助我找出我正在做的错误是什么.. 谢谢

最佳答案

根据 the documentation ,您将 _PValueJudyArray 参数颠倒了。让你的电话看起来像这样:

JSLI( _PValue, JudyArray, (uint8_t *) String);  

此外,尽量不要将其编译为 C++ 代码。到目前为止,您的测试没有使用任何 C++ 功能。我敢打赌它会编译为 C 代码。看起来 JudyArray 依赖于 C 将在 void * 和其他指针类型之间进行某些类型的隐式转换这一事实。

如果是这种情况,我不知道该怎么办。您收到的错误消息告诉我 JSLI 是一个宏。为了修复您在此答案的评论中的错误消息,您必须进入宏内部并添加类型转换。

C 中允许这些类型的隐式转换,否则使用 malloc 将总是需要丑陋的转换。 C++ 故意不允许它们,因为 new 的语义要求将 malloc 的结果强制转换为不重要的正确类型。

出于这个原因,我认为这个库不能在 C++ 中有效使用。

关于c++ - 如何使用 Judy 阵列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6420458/

相关文章:

algorithm - 什么是Splay树、红黑树、AVL树、B树和T树?

java - 在此实例中保存数据的结构(Hashmap/ArrayList 等)?

c++ - 使用Qt的QTimer函数在OpenGl中制作动画

c++ - 如何优化 std::set 交集算法 (C++)

c++ - 需要帮助使用 g++ 编译 vcglib 代码

java - 哈希码实现的变化如何影响哈希集

python - 在 python 中替代 c++ STD::map(需要快速的 lower_bound 方法)

C - 构建动态分配的指针数组,指向由文件输入填充的结构

python - 用 C++ 加速 Python

c++ - 如何将 unique_ptr 用于 pimpl?