Judy Array - Example
“
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的更多相关文章
- Judy Array API介绍
本文介绍https://code.google.com/p/judyarray/这个JudyArray实现的API. judy_open:新建一个JudyArray,并返回指向这个JudyArray的 ...
- [Erlang 0126] 我们读过的Erlang论文
我在Erlang Resources 豆瓣小站上发起了一个征集活动 [链接] ,"[征集] 我们读过的Erlang论文",希望大家来参加.发起这样一个活动的目的是因为Erlang相 ...
- PHP7函数大全(4553个函数)
转载来自: http://www.infocool.net/kb/PHP/201607/168683.html a 函数 说明 abs 绝对值 acos 反余弦 acosh 反双曲余弦 addcsla ...
- 一些鲜为人知却非常实用的数据结构 - Haippy
原文:http://www.udpwork.com/item/9932.html 作为程序猿(媛),你必须熟知一些常见的数据结构,比如栈.队列.字符串.链表.二叉树.哈希,但是除了这些常见的数据结构以 ...
- array_column php 函数 自定义版本 php_version<5.5
<?php if(!function_exists('array_column')) { /* * array_column() for PHP 5.4 and lower versions * ...
- Trie(前缀树/字典树)及其应用
Trie,又经常叫前缀树,字典树等等.它有很多变种,如后缀树,Radix Tree/Trie,PATRICIA tree,以及bitwise版本的crit-bit tree.当然很多名字的意义其实有交 ...
- javascript中的Array对象 —— 数组的合并、转换、迭代、排序、堆栈
Array 是javascript中经常用到的数据类型.javascript 的数组其他语言中数组的最大的区别是其每个数组项都可以保存任何类型的数据.本文主要讨论javascript中数组的声明.转换 ...
- ES5对Array增强的9个API
为了更方便的对Array进行操作,ES5规范在Array的原型上新增了9个方法,分别是forEach.filter.map.reduce.reduceRight.some.every.indexOf ...
- JavaScript Array对象
介绍Js的Array 数组对象. 目录 1. 介绍:介绍 Array 数组对象的说明.定义方式以及属性. 2. 实例方法:介绍 Array 对象的实例方法:concat.every.filter.fo ...
随机推荐
- Determining IP information for eth0...failed 错误解决
问题描述:虚拟机使用wget命令上网,执行service network restart后出现如下错误Determining IP information for eth0...failed解决办法: ...
- 使用nproxy代理本地服务到内网
前端开发中:很多场景需要在局域网下的其他手机或设备查看网页, 问题来了, web服务部署在本机的某个端口上(8080),只能通过本机浏览器访问, 怎样能让局域网下的其他设备也访问呢?可能你会说 关闭 ...
- Helm 入门安装指南
Helm 是 Kubernetes 生态系统中的一个软件包管理工具.本文将介绍 Helm 中的相关概念和基本工作原理,并通过一个具体的示例学习如何使用 Helm 打包.分发.安装.升级及回退 Kube ...
- 配置IIS,以在局域网内访问发布的web站点
在windows 7或win8 中 配置IIS, 以在局域网内访问自己发布的web 网站或应用程序.主要配置步骤如下: 1. 打开 win7 或 win8 控制面板,选择: 打开或关闭windws 功 ...
- python写批量weblogic爆破脚本
前言: 整理笔记的时候,发现了weblogic的攻击方法.心里打着算盘看看怎么写 个批量的弱口令爆破脚本.得出了以下思路 思路: 1.利用钟馗之眼采集weblogic的网站,将IP写入到txt 2.添 ...
- svn+apache+ssl快速部署
在svn+apache文章中已经成功搭建了web-svn,由于在http网络上数据都是以明文传输,公司的源码需要一定的保密机制,基于安全考虑现整合web-svn+ssl.构建安全的svn服务器, 1. ...
- 《GPU高性能编程CUDA实战》附录一 高级原子操作
▶ 本章介绍了手动实现原子操作.重构了第五章向量点积的过程.核心是通过定义结构Lock及其运算,实现锁定,读写,解锁的过程. ● 章节代码 #include <stdio.h> #incl ...
- 29. 在Linux上使用unzip解压以默认编码解压,中文文件名会出现乱码
解决办法: 下载p7zip-9.13-1.el5.rf.x86_64.rpm和p7zip-plugins-9.13-1.el5.rf.x86_64.rpm包 用以下方法安装后,使用7z x filen ...
- 【转】Ultra simple ISO-7816 Interface
原文出自 http://hilbert-space.de/?p=135 While laying out a PCB for my SWP reader project I realized that ...
- Yii常用变量
调用YII框架中 jquery:Yii::app()->clientScript->registerCoreScript('jquery'); 调用YII框架中 jquery:Yii::a ...