In computer science and software engineering, a Judy array is a data structure that has high performance, low memory usage and implements anassociative array. 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.[1]

Judy arrays are both speed- and memory-efficient[clarification needed], with no tuning or configuration required and therefore they can sometime replace common in-memory dictionary implementations (like red-black trees or hash tables) and work better with very large data sets[dubious – discuss][citation needed].

Roughly speaking, Judy arrays are highly-optimised 256-ary radix trees.[2] 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.[3]

https://code.google.com/p/judyarray/这里是一个简单高效的实现

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

#include <stdio.h>
#include <string.h>
#include <stdlib.h> #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。。。

Judy Array - Example的更多相关文章

  1. Judy Array API介绍

    本文介绍https://code.google.com/p/judyarray/这个JudyArray实现的API. judy_open:新建一个JudyArray,并返回指向这个JudyArray的 ...

  2. [Erlang 0126] 我们读过的Erlang论文

    我在Erlang Resources 豆瓣小站上发起了一个征集活动 [链接] ,"[征集] 我们读过的Erlang论文",希望大家来参加.发起这样一个活动的目的是因为Erlang相 ...

  3. PHP7函数大全(4553个函数)

    转载来自: http://www.infocool.net/kb/PHP/201607/168683.html a 函数 说明 abs 绝对值 acos 反余弦 acosh 反双曲余弦 addcsla ...

  4. 一些鲜为人知却非常实用的数据结构 - Haippy

    原文:http://www.udpwork.com/item/9932.html 作为程序猿(媛),你必须熟知一些常见的数据结构,比如栈.队列.字符串.链表.二叉树.哈希,但是除了这些常见的数据结构以 ...

  5. array_column php 函数 自定义版本 php_version<5.5

    <?php if(!function_exists('array_column')) { /* * array_column() for PHP 5.4 and lower versions * ...

  6. Trie(前缀树/字典树)及其应用

    Trie,又经常叫前缀树,字典树等等.它有很多变种,如后缀树,Radix Tree/Trie,PATRICIA tree,以及bitwise版本的crit-bit tree.当然很多名字的意义其实有交 ...

  7. javascript中的Array对象 —— 数组的合并、转换、迭代、排序、堆栈

    Array 是javascript中经常用到的数据类型.javascript 的数组其他语言中数组的最大的区别是其每个数组项都可以保存任何类型的数据.本文主要讨论javascript中数组的声明.转换 ...

  8. ES5对Array增强的9个API

    为了更方便的对Array进行操作,ES5规范在Array的原型上新增了9个方法,分别是forEach.filter.map.reduce.reduceRight.some.every.indexOf ...

  9. JavaScript Array对象

    介绍Js的Array 数组对象. 目录 1. 介绍:介绍 Array 数组对象的说明.定义方式以及属性. 2. 实例方法:介绍 Array 对象的实例方法:concat.every.filter.fo ...

随机推荐

  1. 深入分析Java Web技术内幕 修订版 pdf

    百度网盘:http://pan.baidu.com/s/1slHCCw9

  2. Java技术栈

    内容: 1.Java基础(JavaSE) 2.数据结构与算法与设计模式 3.计算机理论知识 4.数据库 5.Java web(JavaEE) 6.消息队列 7.Linux及服务器相关 8.分布式相关 ...

  3. Github入门 - Github基本使用及Github桌面版使用

    知识内容: 1.版本控制 2.Git介绍 3.Github介绍及基本使用 4.Github桌面版介绍及安装 5.Github桌面版基础使用 6.Github桌面版进阶使用 参考: http://www ...

  4. uva-10160-枚举

    若当前搜索到的城市n前面1-n-1编号的城市中有没有通电的,则永远也无法输送电力给那个城市,因为在剪枝时附加了和此结点连接的最大结点小于当前的结点 这段 for(int i = 1; i < c ...

  5. 57. 激活office时出下以下问题的解决方案

      我们拿出一段来分析一下(我所知道的不多)SKU ID:1b686580-9fb1-4b88-bfba-eae7c0da31adLICENSE NAME: Office 15, OfficeProP ...

  6. linux获取日志指定行数范围内的内容

    假如我要获取“浅浅岁月拂满爱人袖”到“落入凡尘伤情着我”之间的内容. 1.首先得到他们所在的行号: -n选项显示行号 但是有时候grep后显示的是“匹配到二进制文件(标准输入)”,说明搜索的字符串在某 ...

  7. myeclipse2016-ci破解疑难杂症问题整理

    感谢网上的各位大神,在你们的基础,我又整理了下安装成功的心得,破解不成功时一定注意下红色字体内容,避免被坑,都是教训. 试了网上N种破解工具+方法,Myeclipse 2016装了很多遍(本人官网下载 ...

  8. 基于OpenGL编写一个简易的2D渲染框架-13 使用例子

    这是重构渲染器的最后一部分了,将会给出一个 demo,测试模板测试.裁剪测试.半透明排序等等: 上图是本次 demo 的效果图,中间的绿色图形展现的是模板测试. 模板测试 void init(Pass ...

  9. vue深入了解组件——插槽

    一.插槽内容 Vue实现了一套内容分发的API,这套API基于当前的Web Components规范草案,将 <slot>  元素作为承载分发的内容的出口. 它允许你像这样合成组件: &l ...

  10. playbook相关

    ansible-playbook site.yml  -f 10 ansible-playbook常用参数说明: -f  10          启用10个并发进程数执行playbook -u  RM ...