1 // find_univpoly_ring().
6 CL_PROVIDE(cl_UP_named)
9 #include "cln/univpoly.h"
18 // Create a new univariate polynomial ring with a named variable.
20 static inline cl_heap_univpoly_ring* cl_make_univpoly_ring (const cl_ring& r, const cl_symbol& varname)
22 cl_heap_univpoly_ring* UPR = cl_make_univpoly_ring(r);
23 UPR->add_property(new cl_varname_property(cl_univpoly_varname_key,varname));
29 // The table of univariate polynomial rings with named variable.
30 // A weak hash table (cl_ring,cl_symbol) -> cl_univpoly_ring.
32 #include "cl_rcpointer2_hashweak_rcpointer.h"
36 // An entry can be collected when the value (the ring) isn't referenced any more
37 // except from the hash table, and when the keys (the base ring and the name)
38 // are't referenced any more except from the hash table and the ring. Note that
39 // the ring contains exactly one reference to the base ring and exactly one
40 // reference to the name (on the property list).
42 static cl_boolean maygc_htentry (const cl_htentry_from_rcpointer2_to_rcpointer& entry)
44 if (!entry.key1.pointer_p() || (entry.key1.heappointer->refcount == 2))
45 if (!entry.key2.pointer_p() || (entry.key2.heappointer->refcount == 2))
46 if (!entry.val.pointer_p() || (entry.val.heappointer->refcount == 1))
51 static const cl_wht_from_rcpointer2_to_rcpointer univpoly_ring_table = cl_wht_from_rcpointer2_to_rcpointer(maygc_htentry);
53 static inline cl_univpoly_ring* get_univpoly_ring (const cl_ring& r, const cl_symbol& v)
55 return (cl_univpoly_ring*) univpoly_ring_table.get(r,v);
58 static inline void store_univpoly_ring (const cl_univpoly_ring& R)
60 univpoly_ring_table.put(R->basering(), ((cl_varname_property*)(R->get_property(cl_univpoly_varname_key)))->varname,
65 const cl_univpoly_ring find_univpoly_ring (const cl_ring& r, const cl_symbol& varname)
67 var cl_univpoly_ring* ring_in_table = get_univpoly_ring(r,varname);
69 var cl_univpoly_ring R = cl_make_univpoly_ring(r,varname);
70 store_univpoly_ring(R);
71 ring_in_table = get_univpoly_ring(r,varname);
75 return *ring_in_table;
80 CL_PROVIDE_END(cl_UP_named)