+// Allocate
+tuple *tuple_create(int arity,...) {
+ va_list ap;
+ int i;
+ tuple *t = (tuple *)malloc( arity * sizeof( void* ) );
+ for ( i = 0; i < arity; i++ ) {
+ (*t)[i] = va_arg( ap, void* );
+ }
+ return t;
+}
+
+tupleschema *tupleschema_create(int arity,tuple *columns) {
+ tupleschema *ts = (tupleschema*) malloc( sizeof( tupleschema ) );
+ (*ts) = (tupleschema) {
+ .functions = {
+ .hashcode = tupleitem_hashcode,
+ .haskey = tupleitem_haskey,
+ .itemkey = tupleitem_itemkey,
+ .releasekey = tupleitem_releasekey
+ },
+ .arity = arity,
+ .columns = (itemkeyfun**) columns
+ };
+ return ts;
+}
+
+#define COPYA(T,P,N) (T*) memcpy( malloc( N * sizeof(T) ), P, N * sizeof( T ) )
+#define COPY(T,P) COPYA(T,P,1)
+
+// Duplicate a tupleschema with optionally some columns reset.
+tupleschema *tupleschema_mask(tupleschema *schema,...) {
+ tupleschema *masked = COPY(tupleschema,schema);
+ masked->columns = COPYA( itemkeyfun*, schema->columns, schema->arity );
+ va_list ap;
+ int i;
+ for ( ;; ) {
+ i = va_arg( ap, int );
+ if ( i < 0 || i >= schema->arity ) {
+ break;
+ }
+ masked->columns[i] = 0;
+ };
+ return masked;
+}