GithubHelp home page GithubHelp logo

golombset's Introduction

golombset

Golombset is a pure-C, header-file-only implementation of Golomb compressed set, which is an compressed form of Bloom filter.

It compresses every zero-range of Bloom filter (e.g. 0000...1) using Golomb coding. Please refer to Golomb-coded sets: smaller than Bloom filters for more information about the algorithm.

Encode

// buffer to store the encoded data
char buf[1024];

// setup encoder context; dst, dst_max, fixed_bits_length MUST be set
golombset_encoder_t ctx;
memset(&ctx, 0, sizeof(ctx));
ctx.dst = buf;
ctx.dst_max = buf + sizeof(buf);
ctx.fixed_bits_length = 5; // number of bits used to store `fixed_bits`

// encode values (values must be pre-sorted)
int ret = golombset_encode(&ctx, values, num_values, GOLOMBSET_ENCODE_CALC_FIXED_BITS);

// encoded values will be stored in `buf`, the length is `ctx.dst - buf` bytes

The encode function returns zero on success. The function returns a non-zero value if size of the buffer is too small; applications must repeat the entire process with a larger buffer to generate the encoded data.

Decode

// buffer to srote the decoded data
unsigned values[1024];
size_t num_values = sizeof(values) / sizeof(values[0]);

// setup decoder context; src, src_max, fixd_bits_length MUST be set
golombset_decoder_t ctx;
memset(&ctx, 0, sizeof(ctx));
ctx.src = encoded_bytes;
ctx.src_max = length_of_encoded_bytes;
ctx.fixed_bits_length = 5;

// decode the values
int ret = golombset_decode(&ctx, &values, &num_values, 0);

The decode function returns zero on success. The function returns a non-zero value if size of the buffer is too small; applications must repeat the entire process with a larger buffer to generate the decoded data.

golombset's People

Contributors

kazuho avatar

Stargazers

Zane Chiang avatar  avatar misoobu avatar ik5 avatar west avatar Naoya Murakami avatar Hayato Mikami avatar  avatar John Papandriopoulos avatar Alexander Böhn avatar Ben Wills avatar Taichi Nakashima avatar Haruka Asakura avatar Tatsuhiro Tsujikawa avatar KAWAMORITA Mitsuaki avatar Angus H. avatar MURAOKA Taro avatar Daichi Hirata avatar Hideaki Ohno avatar Kiyoshi Nomo avatar Santa Zhang avatar The Dude avatar

Watchers

 avatar Tatsuhiro Tsujikawa avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.