1 /****************************************
2 *  Computer Algebra System SINGULAR     *
3 ****************************************/
4 /***************************************************************
5  *  File:    sbuckets.h
6  *  Purpose: declaration of routines for sorting and adding up polys using
7  *           a bucket sort
8  *  Note:    If you need to extract the leading momonial of a bucket,
9  *           use kbuckets, instead.
10  *  Author:  obachman (Olaf Bachmann)
11  *  Created: 9/00
12  *******************************************************************/
13 #ifndef S_BUCKETS_H
14 #define S_BUCKETS_H
15 #include "polys/monomials/ring.h"
16 class sBucket; typedef sBucket*           sBucket_pt;
17 
18 //////////////////////////////////////////////////////////////////////////
19 // Creation/Destruction of buckets
20 //
21 sBucket_pt    sBucketCreate(ring r);
22 void          sBucketDestroy(sBucket_pt *bucket);
23 
24 //////////////////////////////////////////////////////////////////////////
25 // New API:
26 //
27 
28 /// Copy sBucket non-intrusive!!!
29 sBucket_pt    sBucketCopy(const sBucket_pt bucket);
30 
31 /// Returns bucket ring
32 ring sBucketGetRing(const sBucket_pt bucket);
33 
34 /// Test whether bucket is empty!?
35 bool sIsEmpty(const sBucket_pt bucket);
36 
37 
38 
39 /////////////////////////////////////////////////////////////////////////////
40 // Convertion from/to SBpolys
41 //
42 
43 // Converts p into a bucket poly (SBpoly) and destroys p
44 // Assumes length <= 0 || pLength(p) == length
45 // void sBucketInit(sBucket_pt bucket, poly p, int length);
46 
47 // creates and returns new bucket, initializes it with p
48 // sBucket_pt sBucketInit( poly p, int length, ring r = currRing);
49 
50 // Converts SBpoly into a poly and clears bucket
51 // i.e., afterwards SBpoly == 0
52 // assumes all monomials in bucket are different
53 void sBucketClearMerge(sBucket_pt bucket, poly *p, int *length);
54 
55 // Converts SBpoly into a poly and clears bucket
56 // i.e., afterwards SBpoly == 0
57 // bucket may contain equal monials
58 void sBucketClearAdd(sBucket_pt bucket, poly *p, int *length);
59 
60 // Converts SBpoly into a poly and detroys bucket
sBucketDestroyMerge(sBucket_pt bucket,poly * p,int * length)61 inline void sBucketDestroyMerge(sBucket_pt bucket, poly *p, int *length)
62 {
63   sBucketClearMerge(bucket, p, length);
64   sBucketDestroy(&bucket);
65 }
66 
67 // Converts SBpoly into a poly and detroys bucket
sBucketDestroyAdd(sBucket_pt bucket,poly * p,int * length)68 inline void sBucketDestroyAdd(sBucket_pt bucket, poly *p, int *length)
69 {
70   sBucketClearAdd(bucket, p, length);
71   sBucketDestroy(&bucket);
72 }
73 
74 void sBucketDeleteAndDestroy(sBucket_pt *bucket_pt);
75 
76 poly sBucketPeek(sBucket_pt b);
77 //////////////////////////////////////////////////////////////////////////
78 
79 /// Merges p into Spoly: assumes Bpoly and p have no common monoms
80 /// destroys p!
81 void sBucket_Merge_p(sBucket_pt bucket, poly p, int lp);
82 void sBucket_Merge_m(sBucket_pt bucket, poly p);
83 
84 /// adds poly p to bucket
85 /// destroys p!
86 void sBucket_Add_p(sBucket_pt bucket, poly p, int lp);
87 void sBucket_Add_m(sBucket_pt bucket, poly p);
88 
89 
90 //////////////////////////////////////////////////////////////////////////
91 ///
92 /// Sorts p with bucketSort: assumes all monomials of p are different
93 ///
94 poly sBucketSortMerge(poly p, const ring r);
95 
96 //////////////////////////////////////////////////////////////////////////
97 ///
98 /// Sorts p with bucketSort: p may have equal monomials
99 ///
100 poly sBucketSortAdd(poly p, const ring r);
101 
102 
103 //////////////////////////////////////////////////////////////////////////
104 void sBucketCanonicalize(sBucket_pt bucket);
105 char* sBucketString(sBucket_pt bucket);
106 void sBucketPrint(sBucket_pt bucket);
107 #endif // P_BUCKET_SORT
108