source: git/ntl/src/ZZVec.c @ 6ce030f

spielwiese
Last change on this file since 6ce030f was 287cc8, checked in by Hans Schönemann <hannes@…>, 14 years ago
ntl 5.5.2 git-svn-id: file:///usr/local/Singular/svn/trunk@12402 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 1.4 KB
Line 
1
2#include <NTL/ZZVec.h>
3
4#include <NTL/new.h>
5
6NTL_START_IMPL
7
8void ZZVec::SetSize(long n, long d)
9{
10   if (n < 0 || d <= 0) Error("bad args to ZZVec::SetSize()");
11
12   if (v)
13      Error("illegal ZZVec initialization");
14
15   len = n;
16   bsize = d;
17
18   if (n == 0) return;
19
20   v = (ZZ*) NTL_MALLOC(n, sizeof(ZZ), 0);
21   if (!v) Error("out of memory in ZZVec::SetSize()");
22
23   long i = 0;
24   long m;
25   long j;
26
27   while (i < n) {
28      m = ZZ_BlockConstructAlloc(v[i], d, n-i);
29      for (j = 1; j < m; j++)
30         ZZ_BlockConstructSet(v[i], v[i+j], j);
31      i += m;
32   }
33}
34
35void ZZVec::kill()
36{
37   long n = len;
38
39   len = 0; bsize = 0;
40
41   if (n == 0) return;
42
43   long i = 0;
44   long m;
45
46   while (i < n) {
47      m = ZZ_BlockDestroy(v[i]);
48      i += m;
49   }
50
51   free(v);
52   v = 0;
53}
54
55
56ZZVec& ZZVec::operator=(const ZZVec& a)
57{
58   if (this == &a)
59      return *this;
60
61   kill();
62   SetSize(a.len, a.bsize);
63
64   long i;
65   for (i = 0; i < a.len; i++)
66      v[i] = (a.v)[i];
67
68  return *this;
69}
70
71ZZVec::ZZVec(const ZZVec& a)
72{
73   v = 0; len = 0; bsize = 0;
74
75   SetSize(a.len, a.bsize);
76
77   long i;
78   for (i = 0; i < a.len; i++)
79      v[i] = (a.v)[i];
80}
81
82void ZZVec::swap_impl(ZZVec& x, ZZVec& y)
83{
84   ZZ* t1;
85   long t2;
86
87   t1 = x.v;
88   x.v = y.v;
89   y.v = t1;
90
91   t2 = x.len;
92   x.len = y.len;
93   y.len = t2;
94
95   t2 = x.bsize;
96   x.bsize = y.bsize;
97   y.bsize = t2;
98}
99
100NTL_END_IMPL
Note: See TracBrowser for help on using the repository browser.