Added the interface specification for windowing. There is no change in the implementation. The nWindows parameter is currently ignored.
diff --git a/median.c b/median.c index e47bb61..a2062a4 100644 --- a/median.c +++ b/median.c
@@ -23,7 +23,7 @@ size_t occupancy; // Number of occupants for this buffer. unsigned char data[0]; // Start of the data block, cast as unsigned char. median_data_t - median_data[0]; // The data for this buffer cast as median_data_t. + median_data[0]; // The data for this buffer cast as median_data_t. }; // ---------------------------------------------------------------------------- @@ -318,7 +318,9 @@ // ---------------------------------------------------------------------------- // Suggest the size of the buffer needed for a fixed epsilon and maxN. // ---------------------------------------------------------------------------- -median_error_t median_suggest_buffer_size(double epsilon, size_t maxN, +median_error_t median_suggest_buffer_size(double epsilon, + size_t maxN, + size_t nWindows, size_t *suggested_size) { // First check for sane parameters. @@ -374,14 +376,14 @@ // Initialize an allocated buffer. // ---------------------------------------------------------------------------- median_error_t median_init_buffer(void *buffer, size_t buffer_size, - double epsilon, size_t maxN, + double epsilon, size_t maxN, size_t nWindows, median_buffer_t *initialized_buffer) { // Initialize. size_t expectedSize = 0; median_error_t error = MEDIAN_OK; // First run median_suggest_buffer_size - if ((error = median_suggest_buffer_size(epsilon, maxN, &expectedSize)) != + if ((error = median_suggest_buffer_size(epsilon, maxN, nWindows, &expectedSize)) != MEDIAN_OK) return error; // Ensure that the buffer is large enough.
diff --git a/median.h b/median.h index d4a83a2..0b1ceba 100644 --- a/median.h +++ b/median.h
@@ -55,15 +55,23 @@ // The default size of the largest possible dataset. static const size_t MEDIAN_MAX_N_DEFAULT = 1024 * 1024 * 1024; // 1G. +static const size_t N_WINDOWS_DEFAULT = 1; + // This routine returns a suggested size for a buffer to hold all the // state needed for a median calculation. Here epsilon is the permissible error. // maxN is the largest dataset that we anticipate. If maxN is set to // MEDIAN_MAX_N_UNKNOWN (or zero), then we assume MEDIAN_MAX_N_DEFAULT to be the -// value of maxN. The value return parameter is conventionally the last one. In +// value of maxN. +// nWindows is the number of concurrently active windows. The default value +// for nWindows is 1 (aka N_WINDOWS_DEFAULT). If no windowing is desired, +// N_WINDOWS_DEFAULT should be used. +// The value return parameter is conventionally the last one. In // this case, it contains the suggested_size of the buffer, assuming that the // return value is MEDIAN_ERROR_OK. In all reasonable calls, the returned value // will be MEDIAN_ERROR_OK. -median_error_t median_suggest_buffer_size(double epsilon, size_t maxN, +median_error_t median_suggest_buffer_size(double epsilon, + size_t maxN, + size_t nWindows, size_t *suggested_size); // Suggest a size of the buffer for scratch space. This is needed // so that the buffer is not corrupted by the output and merge steps. @@ -89,7 +97,7 @@ // is initialized. In all reasonable calls, the returned value will be // MEDIAN_ERROR_OK. median_error_t median_init_buffer(void *buffer, size_t buffer_size, - double epsilon, size_t maxN, + double epsilon, size_t maxN, size_t nWindows, median_buffer_t *initialized_buffer); // This frees up any internal resource consumed with the buffer, including // mutex locks and other provisioned resources.
diff --git a/median.main.c b/median.main.c index 15cbb36..1aca550 100644 --- a/median.main.c +++ b/median.main.c
@@ -15,11 +15,11 @@ // 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); + assert(median_suggest_buffer_size(.001, TEST_SIZE, N_WINDOWS_DEFAULT, &n) == MEDIAN_OK); void* b = malloc(n); assert(b); median_buffer_t buf; - assert(median_init_buffer(b, n, .001, TEST_SIZE, &buf) == MEDIAN_OK); + assert(median_init_buffer(b, n, .001, TEST_SIZE, N_WINDOWS_DEFAULT, &buf) == MEDIAN_OK); // Initialize the spare buffer. assert(median_suggest_scratch_buffer_size(buf, &n) == MEDIAN_OK);