Skip to content

Instantly share code, notes, and snippets.

@mejedi
Created June 7, 2013 16:33
Show Gist options
  • Save mejedi/5730557 to your computer and use it in GitHub Desktop.
Save mejedi/5730557 to your computer and use it in GitHub Desktop.
#include <stddef.h>
enum T_field_enum { amount_of_money_e, gender_e, age_e, code_e, height_e, /*<<<<<- add fields here */ last_e };
struct T_cash_account_row {
unsigned code:20; // 0 - 1000000
unsigned gender:1; // 0 - 1
unsigned age:7; // 0 - 100
unsigned amount_of_money:20;// 0 - 1000000
unsigned height:9; // 0 – 300
};
struct T_range_filters {
struct T_cash_account_row begin, end;
/* bytes array or bitset from https://gist.github.com/jmbr/667605 */
unsigned char use_filter[last_e];
};
typedef size_t (*search_fn) (
struct T_cash_account_row const*const __restrict array_ptr,
const size_t c_array_size,
struct T_cash_account_row *const __restrict result_ptr,
struct T_range_filters const*const __restrict range_filters);
#define BEGINF(n) \
static size_t search ## n ( \
struct T_cash_account_row const*const __restrict array_ptr, \
const size_t c_array_size, \
struct T_cash_account_row *const __restrict result_ptr, \
struct T_range_filters const*const __restrict range_filters) { \
size_t result_size = 0; \
size_t i; \
for(i = 0; i < c_array_size; ++i) \
if (1
#define COMPAR(field) \
&& array_ptr[i].field >= range_filters->begin.field && \
array_ptr[i].field <= range_filters->end.field
#define ENDF(n) \
) /* if */ { \
result_ptr[result_size++] = array_ptr[i]; \
} \
return result_size; \
}
#include "gen.inl"
#undef BEGINF
#undef COMPAR
#undef ENDF
search_fn dispatch_table[] = {
#define BEGINF(n) \
[n] = search ## n,
#define COMPAR(field)
#define ENDF(n)
#include "gen.inl"
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment