blob: bff30d123ac9e5116d8ed1042f93e24736b76d5a [file] [log] [blame]
#include <stdio.h> // fprintf, stderr
#include <stdlib.h> // size_t
#include <assert.h> // assert
#include "median.h"
#include "hex.h"
#define TEST_SIZE 1024*1024*256 // 256M
// A sinple main routine meant as an example,
// and also to unit test most of the intersting
// functions of the median module.
int main(int argc, char * argv[]) {
// Call suggest buffer size to determine the size of the buffer
// we need to build the data structure.
size_t n = 0;
// Allocate the buffer of the required size. And then
// initialize it (median_init_buffer).
assert(median_suggest_buffer_size(.001, TEST_SIZE , &n) == MEDIAN_OK);
void * b = malloc(n);
median_buffer_t buf;
assert(median_init_buffer(b, n, .001, TEST_SIZE, &buf) == MEDIAN_OK);
// Initialize the spare buffer.
assert(median_suggest_scratch_buffer_size(buf, &n) == MEDIAN_OK);
void * s = malloc(n);
median_scratch_buffer_t scratch;
assert(median_init_scratch_buffer(s,n,buf,&scratch) == MEDIAN_OK);
// Insert some data.
for(median_data_t i = 1; i < TEST_SIZE; i++) { // 1G
assert(median_insert_data(buf,i,scratch) == MEDIAN_OK);
}
median_data_t median;
assert(median_output_median(buf, &median,scratch) == MEDIAN_OK);
fprintf(stderr, "And the median is %x\n", (unsigned)median);
// All done, return 0
return 0;
}