1 // cl_find_univpoly_ring().
6 CL_PROVIDE(cl_UP_unnamed)
9 #include "cl_univpoly.h"
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.)
20 #include "cl_rcpointer_hashweak_rcpointer.h"
22 // An entry can be collected when the value (the ring) isn't referenced any more
23 // except from the hash table, and when the key (the base ring) isn't referenced
24 // any more except from the hash table and the ring. Note that the ring contains
25 // exactly one reference to the base ring.
27 static cl_boolean maygc_htentry (const cl_htentry_from_rcpointer_to_rcpointer& entry)
29 if (!entry.key.pointer_p() || (entry.key.heappointer->refcount == 2))
30 if (!entry.val.pointer_p() || (entry.val.heappointer->refcount == 1))
35 static const cl_wht_from_rcpointer_to_rcpointer univpoly_ring_table = cl_wht_from_rcpointer_to_rcpointer(maygc_htentry);
37 static inline cl_univpoly_ring* get_univpoly_ring (const cl_ring& r)
39 return (cl_univpoly_ring*) univpoly_ring_table.get(r);
42 static inline void store_univpoly_ring (const cl_univpoly_ring& R)
44 univpoly_ring_table.put(R->basering(),R);
48 const cl_univpoly_ring cl_find_univpoly_ring (const cl_ring& r)
50 var cl_univpoly_ring* ring_in_table = get_univpoly_ring(r);
52 var cl_univpoly_ring R = cl_make_univpoly_ring(r);
53 store_univpoly_ring(R);
54 ring_in_table = get_univpoly_ring(r);
58 return *ring_in_table;
61 CL_PROVIDE_END(cl_UP_unnamed)