1 | |
---|
2 | /**************************************************************************\ |
---|
3 | |
---|
4 | MODULE: vec_ZZ_p |
---|
5 | |
---|
6 | SUMMARY: |
---|
7 | |
---|
8 | Provides vectors over ZZ_p, along with some related operations. |
---|
9 | |
---|
10 | \**************************************************************************/ |
---|
11 | |
---|
12 | #include <NTL/ZZ_p.h> |
---|
13 | #include <NTL/vec_ZZ.h> |
---|
14 | #include <NTL/vector.h> |
---|
15 | |
---|
16 | NTL_vector_decl(ZZ_p,vec_ZZ_p) |
---|
17 | |
---|
18 | NTL_io_vector_decl(ZZ_p,vec_ZZ_p) |
---|
19 | // I/O operators are defined |
---|
20 | |
---|
21 | NTL_eq_vector_decl(ZZ_p,vec_ZZ_p) |
---|
22 | // operators == and != are defined |
---|
23 | |
---|
24 | void mul(vec_ZZ_p& x, const vec_ZZ_p& a, const ZZ_p& b); |
---|
25 | void mul(vec_ZZ_p& x, const vec_ZZ_p& a, long b); |
---|
26 | |
---|
27 | void mul(vec_ZZ_p& x, const ZZ_p& a, const vec_ZZ_p& b); |
---|
28 | void mul(vec_ZZ_p& x, long a, const vec_ZZ_p& b); |
---|
29 | // x = a * b |
---|
30 | |
---|
31 | void add(vec_ZZ_p& x, const vec_ZZ_p& a, const vec_ZZ_p& b); |
---|
32 | // x = a + b |
---|
33 | |
---|
34 | void sub(vec_ZZ_p& x, const vec_ZZ_p& a, const vec_ZZ_p& b); |
---|
35 | // x = a - b |
---|
36 | |
---|
37 | void clear(vec_ZZ_p& x); |
---|
38 | // x = 0 (length unchanged) |
---|
39 | |
---|
40 | void negate(vec_ZZ_p& x, const vec_ZZ_p& a); |
---|
41 | // x = -a |
---|
42 | |
---|
43 | long IsZero(const vec_ZZ_p& a); |
---|
44 | // test if a is the zero vector |
---|
45 | |
---|
46 | |
---|
47 | void InnerProduct(ZZ_p& x, const vec_ZZ_p& a, const vec_ZZ_p& b); |
---|
48 | // x = sum_{i=0}^{n-1} a[i]*b[i], where n = min(a.length(), |
---|
49 | // b.length()) |
---|
50 | |
---|
51 | void InnerProduct(ZZ_p& x, const vec_ZZ_p& a, const vec_ZZ_p& b, |
---|
52 | long offset); |
---|
53 | // x = sum_{i=offset}^n a[i]*b[i-offset], where n = min(a.length(), |
---|
54 | // b.length()+offset) |
---|
55 | |
---|
56 | void VectorCopy(vec_ZZ_p& x, const vec_ZZ_p& a, long n); |
---|
57 | vec_ZZ_p VectorCopy(const vec_ZZ_p& a, long n); |
---|
58 | // x = a copy of a of length exactly n. |
---|
59 | // The input is truncated or padded with zeroes, as necessary. |
---|
60 | |
---|
61 | |
---|
62 | |
---|
63 | |
---|
64 | |
---|
65 | // operator notation: |
---|
66 | |
---|
67 | vec_ZZ_p operator+(const vec_ZZ_p& a, const vec_ZZ_p& b); |
---|
68 | vec_ZZ_p operator-(const vec_ZZ_p& a, const vec_ZZ_p& b); |
---|
69 | |
---|
70 | vec_ZZ_p operator-(const vec_ZZ_p& a); |
---|
71 | |
---|
72 | |
---|
73 | // vector/scalar multiplication: |
---|
74 | |
---|
75 | vec_ZZ_p operator*(const vec_ZZ_p& a, const ZZ_p& b); |
---|
76 | vec_ZZ_p operator*(const vec_ZZ_p& a, long b); |
---|
77 | |
---|
78 | vec_ZZ_p operator*(const ZZ_p& a, const vec_ZZ_p& b); |
---|
79 | vec_ZZ_p operator*(long a, const vec_ZZ_p& b); |
---|
80 | |
---|
81 | // inner product: |
---|
82 | |
---|
83 | ZZ_p operator*(const vec_ZZ_p& a, const vec_ZZ_p& b); |
---|
84 | |
---|
85 | |
---|
86 | // assignment operator notation: |
---|
87 | |
---|
88 | vec_ZZ_p& operator+=(vec_ZZ_p& x, const vec_ZZ_p& a); |
---|
89 | vec_ZZ_p& operator-=(vec_ZZ_p& x, const vec_ZZ_p& a); |
---|
90 | |
---|
91 | vec_ZZ_p& operator*=(vec_ZZ_p& x, const ZZ_p& a); |
---|
92 | vec_ZZ_p& operator*=(vec_ZZ_p& x, long a); |
---|
93 | |
---|
94 | |
---|
95 | |
---|
96 | // Implementation note: the BlockConstruct routine has been customized |
---|
97 | // for ZZ_p so that when a vec_ZZ_p is grown, space for the needed |
---|
98 | // elements is allocated in one contiguous chunk. This saves on calls to |
---|
99 | // malloc and free, and should also yield better locality of reference. |
---|
100 | // One connsequence of this is that swapping an element of a vec_ZZ_p |
---|
101 | // with another ZZ_p can not be implemented by pointer swap, and will in |
---|
102 | // this case be done by copy. |
---|