Changeset 09da99 in git for ntl/src/GF2XVec.c
- Timestamp:
- Nov 3, 2003, 6:33:49 PM (21 years ago)
- Branches:
- (u'fieker-DuVal', '117eb8c30fc9e991c4decca4832b1d19036c4c65')(u'spielwiese', 'c5facdfddea2addfd91babd8b9019161dea4b695')
- Children:
- 70fea801cbe08a22d1b0e9d8d1d410144e0e91f6
- Parents:
- be2bb37dcbd03b120f14559d378b21b104d907c4
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
ntl/src/GF2XVec.c
rbe2bb3 r09da99 6 6 NTL_START_IMPL 7 7 8 const long MaxAllocBlock = 10000;9 10 8 11 9 void GF2XVec::SetSize(long n, long d) 12 10 { 13 11 if (n < 0 || d <= 0) Error("bad args to GF2XVec::SetSize()"); 12 14 13 if (v) 15 Error(" GF2XVec initialized more than once");14 Error("illegal GF2XVec initialization"); 16 15 17 if (d >= (1L << (NTL_BITS_PER_LONG-4))/NTL_BITS_PER_LONG) 18 Error("size too big in GF2XVec::SetSize"); 19 20 if (n >= long((1L << (NTL_BITS_PER_LONG-4))/sizeof(GF2X))) 21 Error("length too big in GF2XVec::SetSize"); 16 len = n; 17 bsize = d; 22 18 23 19 if (n == 0) return; 24 20 25 long size = (d+2); 26 long AllocAmt = MaxAllocBlock / size; 27 if (AllocAmt == 0) AllocAmt = 1; 28 29 v = (GF2X*) malloc(n * (sizeof (GF2X))); 21 v = (GF2X*) NTL_MALLOC(n, sizeof(GF2X), 0); 30 22 if (!v) Error("out of memory in GF2XVec::SetSize()"); 31 23 32 24 long i = 0; 33 25 long m; 34 _ntl_ulong *p, *q;35 26 long j; 36 27 37 28 while (i < n) { 38 m = min((n-i), AllocAmt); 39 p = (_ntl_ulong *) malloc(m*size*(sizeof (_ntl_ulong))); 40 if (!p) Error("out of memory in GF2XVec::SetSize()"); 41 for (j = 0, q = p+2; j < m; j++, i++, q += size) { 42 q[-2] = (d << 1) | 1; 43 q[-1] = 0; 44 v[i].xrep.rep = q; 45 } 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; 46 33 } 34 } 47 35 48 len = n;49 bsize = d;50 }51 36 52 37 void GF2XVec::kill() 53 38 { 54 39 long n = len; 55 long d = bsize; 40 41 len = 0; bsize = 0; 42 56 43 if (n == 0) return; 57 58 long size = (d+2);59 long AllocAmt = MaxAllocBlock / size;60 if (AllocAmt == 0) AllocAmt = 1;61 44 62 45 long i = 0; … … 64 47 65 48 while (i < n) { 66 m = min((n-i), AllocAmt); 67 free(v[i].xrep.rep-2); 49 m = WV_BlockDestroy(v[i].xrep); 68 50 i += m; 69 51 } 70 52 71 53 free(v); 72 73 v = 0; len = 0; bsize = 0; 54 v = 0; 74 55 } 75 56
Note: See TracChangeset
for help on using the changeset viewer.