1 // cl_find_univpoly_ring().
6 CL_PROVIDE(cl_UP_named)
9 #include "cl_univpoly.h"
16 // Create a new univariate polynomial ring with a named variable.
18 static inline cl_heap_univpoly_ring* cl_make_univpoly_ring (const cl_ring& r, const cl_symbol& varname)
20 cl_heap_univpoly_ring* UPR = cl_make_univpoly_ring(r);
21 UPR->add_property(new cl_varname_property(cl_univpoly_varname_key,varname));
26 // The table of univariate polynomial rings with named variable.
27 // A weak hash table (cl_ring,cl_symbol) -> cl_univpoly_ring.
29 #include "cl_rcpointer2_hashweak_rcpointer.h"
31 // An entry can be collected when the value (the ring) isn't referenced any more
32 // except from the hash table, and when the keys (the base ring and the name)
33 // are't referenced any more except from the hash table and the ring. Note that
34 // the ring contains exactly one reference to the base ring and exactly one
35 // reference to the name (on the property list).
37 static cl_boolean maygc_htentry (const cl_htentry_from_rcpointer2_to_rcpointer& entry)
39 if (!entry.key1.pointer_p() || (entry.key1.heappointer->refcount == 2))
40 if (!entry.key2.pointer_p() || (entry.key2.heappointer->refcount == 2))
41 if (!entry.val.pointer_p() || (entry.val.heappointer->refcount == 1))
46 static const cl_wht_from_rcpointer2_to_rcpointer univpoly_ring_table = cl_wht_from_rcpointer2_to_rcpointer(maygc_htentry);
48 static inline cl_univpoly_ring* get_univpoly_ring (const cl_ring& r, const cl_symbol& v)
50 return (cl_univpoly_ring*) univpoly_ring_table.get(r,v);
53 static inline void store_univpoly_ring (const cl_univpoly_ring& R)
55 univpoly_ring_table.put(R->basering(), ((cl_varname_property*)(R->get_property(cl_univpoly_varname_key)))->varname,
60 const cl_univpoly_ring cl_find_univpoly_ring (const cl_ring& r, const cl_symbol& varname)
62 var cl_univpoly_ring* ring_in_table = get_univpoly_ring(r,varname);
64 var cl_univpoly_ring R = cl_make_univpoly_ring(r,varname);
65 store_univpoly_ring(R);
66 ring_in_table = get_univpoly_ring(r,varname);
70 return *ring_in_table;
73 CL_PROVIDE_END(cl_UP_named)