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. 「CQOI2016」K 远点对

    /* 考虑暴力 可以n ^ 2枚举点对 然后用一个容量为2k的小根堆来维护第k大 kd-tree呢就是来将这个暴力优化, 每次先找远的并且最远距离不如堆顶的话就不继续找下去 貌似挺难构造数据卡的 */ ...

  2. Oauth2.0(六):Resource Owner Password Credentials 授权和 Client Credentials 授权

    这两种简称 Password 方式和 Client 方式吧,都只适用于应用是受信任的场景.一个典型的例子是同一个企业内部的不同产品要使用本企业的 Oauth2.0 体系.在有些情况下,产品希望能够定制 ...

  3. faker之python构造虚拟数据

    python中可以使用faker来制造一些虚拟数据 首选安装faker pip install Faker 老版的叫法是faker-factory,但是已不适用 使用faker.Factory.cre ...

  4. 红帽配置Centos仓库[红帽Redhat7替换Centos7网络源]

    1.卸载红帽yum源 rpm -e $(rpm -qa|grep yum) --nodeps 2.删除所有repo相关文件 rm -rf /etc/yum.conf rm -rf /etc/yum.r ...

  5. leetcode66

    public class Solution { public int[] PlusOne(int[] digits) { ]; < ) { digits[digits.Length - ]++; ...

  6. apache http get 和 post 请求

    1.首先要把jar依赖进项目 <dependency> <groupId>org.apache.httpcomponents</groupId> <artif ...

  7. as3 代码优化

    1 代码写法 1 定义局部变量 定义局部变量的时候,一定要用关键字var来定义,因为在Flash播放器中,局部变量的运行速度更快,而且在他们的作用域外是不耗占系统资源的.当一个函数调用结束的时候,相应 ...

  8. Git----分支管理之bug分支04

    ---恢复内容开始--- 软件开发中,bug就像家常便饭一样,有了bug就需要修复,在Git中,由于分支是如此强大,所以,每个bug都可以通过一个临时分支来修复,修复后,合并分支,然后将临时分支删除. ...

  9. mysql的collation-字符集

    utf8_general_ci               :排序规则 utf8 -- UTF-8 Unicode     :字符集 一.通过my.cnf文件增加(一劳永逸)两个参数:1.在[mysq ...

  10. pycharm ideavimrc设置备忘

    文件存放位置 windows下 C:\Users\你的用户名\.ideavimrc 注:如果要映射pycharm 中的一些命令可以 在pycharm 中 edit->Macros->Sta ...