File: example.c

package info (click to toggle)
libstreamvbyte 0.4.1-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 344 kB
  • sloc: ansic: 2,952; makefile: 69
file content (24 lines) | stat: -rw-r--r-- 763 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>

#include "streamvbyte.h"

int main() {
	int N = 5000;
	uint32_t * datain = malloc(N * sizeof(uint32_t));
	uint8_t * compressedbuffer = malloc(streamvbyte_max_compressedbytes(N));
	uint32_t * recovdata = malloc(N * sizeof(uint32_t));
	for (int k = 0; k < N; ++k)
		datain[k] = 120;
	size_t compsize = streamvbyte_encode(datain, N, compressedbuffer); // encoding
	// here the result is stored in compressedbuffer using compsize bytes
	size_t compsize2 = streamvbyte_decode(compressedbuffer, recovdata,
					N); // decoding (fast)
	assert(compsize == compsize2);
	free(datain);
	free(compressedbuffer);
	free(recovdata);
	printf("Compressed %d integers down to %d bytes.\n",N,(int) compsize);
	return 0;
}