Changeset 2f436b in git for Singular/prCopy.cc
- Timestamp:
- Dec 31, 2000, 4:14:47 PM (23 years ago)
- Branches:
- (u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
- Children:
- e609098c45a74ac91c002ffa7ece5eebe7f8c002
- Parents:
- 33ec1145a109507ad3e3cf4a69a847b703358e93
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Singular/prCopy.cc
r33ec11 r2f436b 2 2 * Computer Algebra System SINGULAR * 3 3 ****************************************/ 4 /* $Id: prCopy.cc,v 1.1 0 2000-12-08 14:43:46 SingularExp $ */4 /* $Id: prCopy.cc,v 1.11 2000-12-31 15:14:43 obachman Exp $ */ 5 5 /* 6 6 * ABSTRACT - implementation of functions for Copy/Move/Delete for Polys … … 14 14 #include "ring.h" 15 15 #include "ideals.h" 16 17 // define to 0 to never revert, 18 // 1 to always revert 19 // undef if revert as given by parameter 20 // #define REVERT 0 21 22 // a sorting of polys based on buckets 23 class pBucketPoly 24 { 25 public: 26 poly p; 27 long length; 28 long max_length; 29 }; 30 31 static inline poly p_BucketSort(poly p, const ring r) 32 { 33 #if PDEBUG > 0 34 long l_orig = pLength(p); 35 #endif 36 37 long max_length = 1; 38 long i; 39 long l_p; 40 pBucketPoly buckets[BIT_SIZEOF_LONG - 3]; 41 poly q; 42 43 buckets[0].p = p; 44 buckets[0].length = 1; 45 buckets[0].max_length = 2; 46 q = pNext(p); 47 pNext(buckets[0].p) = NULL; 48 49 while (q != NULL) 50 { 51 p = q; 52 pIter(q); 53 pNext(p) = NULL; 54 i = 0; 55 l_p = 1; 56 while (1) 57 { 58 if (buckets[i].p == NULL) 59 { 60 buckets[i].p = p; 61 buckets[i].length = l_p; 62 break; 63 } 64 buckets[i].p = p_Merge_q(buckets[i].p, p, r); 65 buckets[i].length += l_p; 66 if (buckets[i].length <= buckets[i].max_length) 67 break; 68 p = buckets[i].p; 69 l_p = buckets[i].length; 70 buckets[i].p = NULL; 71 buckets[i].length = 0; 72 i++; 73 if (i == max_length) 74 { 75 buckets[i].p = p; 76 buckets[i].length = l_p; 77 buckets[i].max_length = 1 << (i + 1); 78 max_length = i+1; 79 break; 80 } 81 } 82 } 83 84 i = 0; 85 while (buckets[i].p == NULL) i++; 86 p = buckets[i].p; 87 for (i++; i<max_length; i++) 88 { 89 if (buckets[i].p != NULL) 90 p = p_Merge_q(buckets[i].p, p, r); 91 } 92 93 p_Test(p, r); 94 #if PDEBUG > 0 95 assume(l_orig == pLength(p)); 96 #endif 97 return p; 98 } 99 100 // Sorts poly, reverts it first -- this way, almost sorted polys's 101 // don't have n^2 sorting property 102 poly prSortR(poly p, ring r, BOOLEAN revert) 103 { 104 if (p == NULL) return NULL; 105 poly qq, result = NULL; 106 107 #ifdef REVERT 108 #if REVERT == 1 109 revert = 1; 110 #elif REVERT == 0 111 revert = 0; 112 #endif 113 #endif 114 if (revert) 115 { 116 // there must be a bug here: consider m1->m2 117 while (p != NULL) 118 { 119 qq = p; 120 pIter(p); 121 qq->next = result; 122 result = qq; 123 } 124 p = result; 125 } 126 127 return p_BucketSort(p, r); 128 } 16 #include "sbuckets.h" 129 17 130 18 static inline void … … 330 218 } 331 219 332 /////////////////////////////////////////////////////////////////////////333 // prDelete334 typedef void (*prDeleteProc_t)(poly &src_p, ring src_r);335 336 static inline void prDeleteR_NSimple(poly &p, ring r)337 {338 poly next;339 340 while (p != NULL)341 {342 next = pNext(p);343 omFreeBin(p, r->PolyBin);344 p = next;345 }346 }347 348 static inline void prDeleteR_NoNSimple(poly &p, ring r)349 {350 poly next;351 352 while (p != NULL)353 {354 next = pNext(p);355 nDelete(&pGetCoeff(p));356 omFreeBin(p, r->PolyBin);357 p = next;358 }359 }360 361 void prDelete(poly &p)362 {363 if (rField_has_simple_Alloc(currRing))364 prDeleteR_NSimple(p, currRing);365 else366 prDeleteR_NoNSimple(p, currRing);367 }368 369 void prDeleteR(poly &p, ring r)370 {371 if (rField_has_simple_Alloc(r))372 prDeleteR_NSimple(p, r);373 else374 prDeleteR_NoNSimple(p, r);375 }376 377 378 static inline void idrDelete(ideal &id, ring r, prDeleteProc_t prproc)379 {380 if (id == NULL) return;381 int i = IDELEMS(id);382 383 for (; i>=0; i--)384 prproc(id->m[i], r);385 386 omFreeSize(id->m, IDELEMS(id)*sizeof(poly));387 omFreeBin(id, sip_sideal_bin);388 id = NULL;389 }390 391 void idrDelete(ideal &id)392 {393 prDeleteProc_t prproc;394 if (rField_has_simple_Alloc(currRing))395 prproc = prDeleteR_NSimple;396 else397 prproc = prDeleteR_NoNSimple;398 399 idrDelete(id, currRing, prproc);400 }401 402 void idrDeleteR(ideal &id, ring r)403 {404 prDeleteProc_t prproc;405 if (rField_has_simple_Alloc(r))406 prproc = prDeleteR_NSimple;407 else408 prproc = prDeleteR_NoNSimple;409 410 idrDelete(id, r, prproc);411 }412 413 414 415
Note: See TracChangeset
for help on using the changeset viewer.