博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Judy Array - Example
阅读量:5317 次
发布时间:2019-06-14

本文共 2284 字,大约阅读时间需要 7 分钟。

In  and , a Judy array is a  that has high performance, low memory usage and implements an. Unlike normal arrays, Judy arrays may be sparse, that is, they may have large ranges of unassigned indices. They can be used for storing and looking up values using integer or string keys. The key benefits of using a Judy array is its scalability, high performance, memory efficiency and ease of use.

Judy arrays are both speed- and memory-efficient[], with no tuning or configuration required and therefore they can sometime replace common in-memory dictionary implementations (like  or ) and work better with very large data sets[ ][].

Roughly speaking, Judy arrays are highly-optimised 256-ary . To make memory consumption small, Judy arrays use over 20 different compression techniques to compress trie nodes.

The Judy array was invented by Douglas Baskins and named after his sister.

这里是一个简单高效的实现

下面是用上面Judy Array的一个简单的Example。

#include 
#include
#include
#include "judy64nb.c"typedef struct data{ int a; int b;}data;int main(){ Judy *judy; void *cell; data *p; char *key1 = "IEatCrab"; char *key2 = "IEatCrabToo"; char *key3 = "CrabEatWorm"; data data1 = {1, 1}; data data2 = {2, 2}; judy = judy_open(100, 0); cell = judy_cell(judy, key1, strlen(key1)); *(data*)cell = data1; cell = judy_slot(judy, key2, strlen(key2)); if(cell == NULL){ cell = judy_cell(judy, key2, strlen(key2)); (*(data*)cell) = data2; } cell = judy_slot(judy, key3, strlen(key3)); if(cell == NULL){ p = (data*)judy_data(judy, sizeof(data)); p->a = 3; p->b = 3; cell = judy_cell(judy, key3, strlen(key3)); *(data**)cell = p; } cell = judy_slot(judy, key1, strlen(key1)); printf("%d %d\n", ((data*)cell)->a, ((data*)cell)->b); cell = judy_slot(judy, key2, strlen(key2)); printf("%d %d\n", ((data*)cell)->a, ((data*)cell)->b); cell = judy_slot(judy, key3, strlen(key3)); p = *(data**)cell; printf("%d %d\n", p->a, p->b); judy_close(judy); return 0;}

  上面的代码中给出了利用Judy Array的三种存储key-value的方法。

 

  顺便吐槽一下,judy array的这个版本中的函数命名太S**K。。。

 

转载于:https://www.cnblogs.com/cobbliu/p/3400257.html

你可能感兴趣的文章
Recover Binary Search Tree
查看>>
Java 实践:生产者与消费者
查看>>
[转]IOCP--Socket IO模型终结篇
查看>>
(五)归一化
查看>>
hdu 4737 A Bit Fun 尺取法
查看>>
使用信号量
查看>>
《数据分析实战》--第三章 python实现
查看>>
crontab command not found
查看>>
记录-springMVC访问web-inf下文件问题+在jsp页面导入jquery插件路径不对问题
查看>>
对于C语言中数组名是指针的理解
查看>>
实验八 接口与实现接口的类
查看>>
mac OSx 安装 mysqlclient
查看>>
Scala for the Impatients---(10)Traits
查看>>
简单的姓名号码查询系统
查看>>
PostgreSQL 保留关键字添加方法之一,不带参数的函数
查看>>
你的博客可能被爬了
查看>>
赛前热手 (天梯赛暴力题)
查看>>
.net 冒泡排序示例
查看>>
Uva(10330)
查看>>
vlan学习
查看>>