]> www.ginac.de Git - cln.git/blob - src/polynomial/elem/cl_UP_unnamed.cc
The patch of 2005-05-01 made it impossible to test the type of a cl_UP
[cln.git] / src / polynomial / elem / cl_UP_unnamed.cc
1 // find_univpoly_ring().
2
3 // General includes.
4 #include "cl_sysdep.h"
5
6 CL_PROVIDE(cl_UP_unnamed)
7
8 // Specification.
9 #include "cln/univpoly.h"
10
11
12 // Implementation.
13
14 #include "cl_UP.h"
15
16 // The table of univariate polynomial rings without named variable.
17 // A weak hash table cl_ring -> cl_univpoly_ring.
18 // (It could also be a weak hashuniq table cl_ring -> cl_univpoly_ring.)
19
20 #include "cl_rcpointer_hashweak_rcpointer.h"
21
22 namespace cln {
23
24 // An entry can be collected when the value (the ring) isn't referenced any more
25 // except from the hash table, and when the key (the base ring) isn't referenced
26 // any more except from the hash table and the ring. Note that the ring contains
27 // exactly one reference to the base ring.
28
29 static cl_boolean maygc_htentry (const cl_htentry_from_rcpointer_to_rcpointer& entry)
30 {
31         if (!entry.key.pointer_p() || (entry.key.heappointer->refcount == 2))
32                 if (!entry.val.pointer_p() || (entry.val.heappointer->refcount == 1))
33                         return cl_true;
34         return cl_false;
35 }
36
37 static const cl_wht_from_rcpointer_to_rcpointer univpoly_ring_table = cl_wht_from_rcpointer_to_rcpointer(maygc_htentry);
38
39 static inline cl_univpoly_ring* get_univpoly_ring (const cl_ring& r)
40 {
41         return (cl_univpoly_ring*) univpoly_ring_table.get(r);
42 }
43
44 static inline void store_univpoly_ring (const cl_univpoly_ring& R)
45 {
46         univpoly_ring_table.put(R->basering(),R);
47 }
48
49
50 const cl_univpoly_ring find_univpoly_ring (const cl_ring& r)
51 {
52         var cl_univpoly_ring* ring_in_table = get_univpoly_ring(r);
53         if (!ring_in_table) {
54                 var cl_univpoly_ring R = cl_make_univpoly_ring(r);
55                 store_univpoly_ring(R);
56                 ring_in_table = get_univpoly_ring(r);
57                 if (!ring_in_table)
58                         cl_abort();
59         }
60         return *ring_in_table;
61 }
62
63 }  // namespace cln
64
65 CL_PROVIDE_END(cl_UP_unnamed)