libfor - 整数压缩 C 语言库


Apache
跨平台
C/C++

软件简介

libfor 是一个 ANSI C 库,是参考框架(Frame Of Reference)整数压缩的快速标量实现。

libfor 可以压缩顺序或者乱序的数列,另外,此库可以在压缩数据上直接执行操作:

  • 选择:在指定索引处返回一个值;

  • 线性搜索:对于未排序数列,或者短排序数列

  • 下界搜索:对排序数列的二进制搜索

示例代码:

#define LEN 100
uint32_t in[LEN] = {0};
uint8_t out[512];

// Fill |in| with numbers of your choice
for (int i = 0; i < LEN; i++)
  in[i] = i;

// Now compress; can also use for_compress_sorted() if the numbers
// are sorted. This is slightly faster.
uint32_t size = for_compress_unsorted(&in[0], &out[0], LEN);
printf("compressing %u integers (%u bytes) into %u bytes\n",
        LEN, LEN * 4, size);

// Decompress again
uint32_t decompressed[LEN];
for_uncompress(&out[0], &decompressed[0], LEN);