1 #ifndef _VECTOR_H
2 #define _VECTOR_H
3 
4 #include <stdlib.h>
5 #include <string.h>
6 
7 typedef struct {
8   size_t length;
9   int array[1];
10 } vector;
11 
12 #define v_length(v)	((v)->length)
13 #define v_elem(v,i)	((v)->array[i])
14 
15 vector *v_new(int length);
16 vector *v_new_init(int length, ...);
17 vector *v_new_zero(int length);
18 #define v_free(v)	(afree(v))
19 void v_free1(vector *v);  /* a compiled version */
20 
21 vector *v_new_copy(vector *v);
22 #define v_copy(d, v)            \
23         memcpy((d)->array, (v)->array, (d)->length * sizeof(int))
24 
25 #define v_set_zero(v)	(memset((v)->array, 0, (v)->length * sizeof(int)))
26 int v_sum(vector *v);
27 int v_lesseq(vector *v1, vector *v2);
28 void v_mult(vector *dst, int c, vector *src);
29 void v_div(vector *dst, vector *src, int c);
30 int v_max(vector *v);
31 
32 int v_elm_cmp(const void *, const void *);
33 #define v_sort(v)	\
34   qsort((v)->array, (v)->length, sizeof(int), v_elm_cmp);
35 #define v_sort_part(v, first, n)	\
36   qsort((v)->array + (first), (n), sizeof(int), v_elm_cmp);
37 
38 int i_gcd(int x, int y);
39 int v_gcd(vector *v);
40 
41 void v_print(vector *v);
42 void v_printnl(vector *v);
43 
44 #include "set.h"
45 #include "hashtab.h"
46 int v_cmp(vector *v1, vector *v2);
47 hashkey_t v_hash(vector *v);
48 
49 void print_vec_set(set *s);
50 void free_vec_set(set *s);
51 
52 void print_vec_lincomb(hashtab *ht, int opt_zero);
53 void free_vec_lincomb(hashtab *ht);
54 
55 
56 typedef struct {
57   vector *first, *second;
58 } vecpair;
59 
60 #define vp_first(vp)	((vp)->first)
61 #define vp_second(vp)	((vp)->second)
62 
63 vecpair *vp_new(vector *v1, vector *v2);
64 vecpair *vp_new_unordered(vector *v1, vector *v2);
65 void vp_free(vecpair *vp);
66 
67 void print_vp_lincomb(hashtab *ht);
68 void free_vp_lincomb(hashtab *ht);
69 
70 int vp_cmp(vecpair *vp1, vecpair *vp2);
71 hashkey_t vp_hash(vecpair *vp);
72 
73 
74 #include "list.h"
75 void print_vec_list(list *lst);
76 void free_vec_list(list *lst);
77 
78 list *find_extreme_vectors(list *veclist, int take_max);
79 
80 #endif
81