6 #define COLUMN def->columns
8 unsigned long tupleitem_hashcode(itemkeyfun *this,void *key) {
9 tupleschema *def = (tupleschema *) this;
10 tuple *kp = (tuple*) key;
12 unsigned long value = 0;
13 for ( ; i < def->arity; i++ ) {
16 value += COLUMN[i]->hashcode( COLUMN[i], (*kp)[i] );
23 * This callback function determines whether an item has a
26 int tupleitem_haskey(itemkeyfun *this,void *item,void *key) {
27 tupleschema *def = (tupleschema *) this;
28 tuple *kp = (tuple*) key;
29 tuple *tp = (tuple*) item;
32 for ( ; i < def->arity; i++ ) {
34 haskey &= COLUMN[i]->haskey( COLUMN[i], (*tp)[i], (*kp)[i] );
42 * This callback function returns the key of an item by considering
45 void *tupleitem_itemkey(itemkeyfun *this,void *item) {
46 tupleschema *def = (tupleschema *) this;
47 tuple *tp = (tuple*) item;
50 for ( i = 0 ; i < def->arity; i++ ) {
55 void **parts = calloc( keylen, sizeof( void* ) );
56 for ( i = 0, j = 0; i < def->arity; i++ ) {
58 parts[j++] = COLUMN[i]->itemkey( COLUMN[i], (*tp)[i] );
65 * This callback function handles a key obtained from the itemkey
66 * callback function to reclaim temporary allocation.
68 void tupleitem_releasekey(itemkeyfun *this,void *key) {
69 tupleschema *def = (tupleschema *) this;
70 tuple *kp = (tuple*) key;
72 for ( i = 0, j = 0; i < def->arity; i++ ) {
74 COLUMN[i]->releasekey( COLUMN[i], (*kp)[j++] );
81 tuple *tuple_create(int arity,...) {
84 tuple *t = (tuple *)malloc( arity * sizeof( void* ) );
85 for ( i = 0; i < arity; i++ ) {
86 (*t)[i] = va_arg( ap, void* );
91 tupleschema *tupleschema_create(int arity,tuple *columns) {
92 tupleschema *ts = (tupleschema*) malloc( sizeof( tupleschema ) );
93 (*ts) = (tupleschema) {
95 .hashcode = tupleitem_hashcode,
96 .haskey = tupleitem_haskey,
97 .itemkey = tupleitem_itemkey,
98 .releasekey = tupleitem_releasekey
101 .columns = (itemkeyfun**) columns
106 #define COPYA(T,P,N) (T*) memcpy( malloc( N * sizeof(T) ), P, N * sizeof( T ) )
107 #define COPY(T,P) COPYA(T,P,1)
109 // Duplicate a tupleschema with optionally some columns reset.
110 tupleschema *tupleschema_mask(tupleschema *schema,...) {
111 tupleschema *masked = COPY(tupleschema,schema);
112 masked->columns = COPYA( itemkeyfun*, schema->columns, schema->arity );
116 i = va_arg( ap, int );
117 if ( i < 0 || i >= schema->arity ) {
120 masked->columns[i] = 0;