1 // find_univpoly_ring().
6 CL_PROVIDE(cl_UP_unnamed)
9 #include "cln/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"
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.
29 static cl_boolean maygc_htentry (const cl_htentry_from_rcpointer_to_rcpointer& entry)
31 if (!entry.key.pointer_p() || (entry.key.heappointer->refcount == 2))
32 if (!entry.val.pointer_p() || (entry.val.heappointer->refcount == 1))
37 static const cl_wht_from_rcpointer_to_rcpointer univpoly_ring_table = cl_wht_from_rcpointer_to_rcpointer(maygc_htentry);
39 static inline cl_univpoly_ring* get_univpoly_ring (const cl_ring& r)
41 return (cl_univpoly_ring*) univpoly_ring_table.get(r);
44 static inline void store_univpoly_ring (const cl_univpoly_ring& R)
46 univpoly_ring_table.put(R->basering(),R);
50 const cl_univpoly_ring find_univpoly_ring (const cl_ring& r)
52 var cl_univpoly_ring* ring_in_table = get_univpoly_ring(r);
54 var cl_univpoly_ring R = cl_make_univpoly_ring(r);
55 store_univpoly_ring(R);
56 ring_in_table = get_univpoly_ring(r);
58 throw runtime_exception();
60 return *ring_in_table;
65 CL_PROVIDE_END(cl_UP_unnamed)