source: git/ntl/src/GF2XVec.c @ 287cc8

spielwiese
Last change on this file since 287cc8 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/GF2XVec.h>
3
4#include <NTL/new.h>
5
6NTL_START_IMPL
7
8
9void GF2XVec::SetSize(long n, long d)
10{
11   if (n < 0 || d <= 0) Error("bad args to GF2XVec::SetSize()");
12
13   if (v)
14      Error("illegal GF2XVec initialization");
15
16   len = n;
17   bsize = d;
18
19   if (n == 0) return;
20
21   v = (GF2X*) NTL_MALLOC(n, sizeof(GF2X), 0);
22   if (!v) Error("out of memory in GF2XVec::SetSize()");
23
24   long i = 0;
25   long m;
26   long j;
27
28   while (i < n) {
29      m = WV_BlockConstructAlloc(v[i].xrep, d, n-i);
30      for (j = 1; j < m; j++)
31         WV_BlockConstructSet(v[i].xrep, v[i+j].xrep, j);
32      i += m;
33   }
34}
35
36
37void GF2XVec::kill()
38{
39   long n = len;
40
41   len = 0; bsize = 0;
42
43   if (n == 0) return;
44
45   long i = 0;
46   long m;
47
48   while (i < n) {
49      m = WV_BlockDestroy(v[i].xrep);
50      i += m;
51   }
52
53   free(v);
54   v = 0;
55}
56
57
58GF2XVec& GF2XVec::operator=(const GF2XVec& a)
59{
60   if (this == &a)
61      return *this;
62
63   kill();
64   SetSize(a.len, a.bsize);
65
66   long i;
67   for (i = 0; i < a.len; i++)
68      v[i] = (a.v)[i];
69
70   return *this;
71}
72
73GF2XVec::GF2XVec(const GF2XVec& a)
74{
75   v = 0; len = 0; bsize = 0;
76
77   SetSize(a.len, a.bsize);
78
79   long i;
80   for (i = 0; i < a.len; i++)
81      v[i] = (a.v)[i];
82}
83
84void GF2XVec::swap_impl(GF2XVec& x, GF2XVec& y)
85{
86   GF2X* t1;
87   long t2;
88
89   t1 = x.v;
90   x.v = y.v;
91   y.v = t1;
92
93   t2 = x.len;
94   x.len = y.len;
95   y.len = t2;
96
97   t2 = x.bsize;
98   x.bsize = y.bsize;
99   y.bsize = t2;
100}
101
102NTL_END_IMPL
Note: See TracBrowser for help on using the repository browser.