e5341bd1a807a1ae298630b4d5e964d28e39139b
[rrq/rrqmisc.git] / vector / Tuple.c
1 #include <stdarg.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <Tuple.h>
5
6 Tuple *Tuple_calloc(int arity) {
7     Tuple *t = (Tuple *) malloc( sizeof( Tuple ) + arity * sizeof( void* ) );
8     t->types = 0;
9     memset( t->elements, 0, arity * sizeof( void* ) );
10     return t;
11 }
12
13 // Allocate
14 Tuple *Tuple_create(int arity,...) {
15     va_list ap;
16     int i;
17     Tuple *t = (Tuple *) malloc( sizeof( Tuple ) + arity * sizeof( void* ) );
18     t->types = 0; // unknown types
19     va_start( ap, arity );
20     for ( i = 0; i < arity; i++ ) {
21         t->elements[i] = va_arg( ap, void* );
22     }
23     va_end( ap );
24     return t;
25 }
26
27 Tuple *Tuple_clone(int arity,Tuple *t) {
28     Tuple *ct = (Tuple *)malloc( sizeof( Tuple ) + arity * sizeof( void* ) );
29     memcpy( ct, t, arity * sizeof( void* ) );
30     return ct;
31 }
32
33 #if 0
34 unsigned long Tuple_mask(int arity,Tuple *t) {
35     unsigned long mask = 0;
36     while ( arity-- > 0 ) {
37         mask <<= 1;
38         if ( t->elements[ arity ] ) {
39             mask |= 1;
40         }
41     }
42     return mask;
43 }
44 #endif