[plt-scheme] equal? operator
>>(define PROOS-STORE (make-hash-table 'equal 'weak))
>>
>>(define (pobject-from-oid oid _class)
>> (let ((class (proos-class _class)))
>> (if (eq? class #f)
>> (error (string-append "proos class definition for " _class " not
>>found"))
>> (let* ((obj (hash-table-get PROOS-STORE (list oid) (lambda () #f))))
>> (oodb-dbg "PROOS-STORE: " oid obj)
>> (if (eq? obj #f)
>> (let ((obj (class 'from-oid oid)))
>> (hash-table-put! PROOS-STORE (list oid) (make-weak-box obj))
>> (oodb-dbg "PROOS-STORE: " oid obj)
>> obj)
>> (weak-box-value obj))))))
>>
>>oid's are 32<oid<64bit integers. I noticed a normal hash table
>>(make-hash-table 'weak)
>>will not find my oids (they're to big). Now I resorted to (list oid) for
>>the key in the hash
>>table *and* an 'equal property on the hash tables. But can It be done
>>safely without the
>>(list ...)?
>>
>>
>
>Yes -- because `equal?' works fine on bigints. Also -- why to you
>make weak boxes? -- The hash table stores values weakly anyay...
>
>
I'm not sure about that. 1. KEYs of type integer (32bit) will not be
collected (they're not
weak appearently). 2. KEYs of type integer (64bit) on a 64 bit
architecture may thus also
be not weak.
Also, the values don't seem weak to me.
In my case, there's a circular reference. The oid is stored in the
object created by (class 'from-oid oid).
If I do not put the created object in a weak-box, the weak key will
never be collected. E.g.:
>(define a (car (psearch (all test-class))))
>(define b (car (psearch (all test-class))))
>(eq? a b)
#t
>(proos-store->list)
((23423523523234342 #roos))
>(set! a #f)
>(set! b #f)
>(collect-garbage)
>(proos-store->list)
((23423523523234342 #roos))
Because the #roos object references the stored oid, the oid is still
referenced, and
the weakness premisse doesn't do its work. Now my implementation:
>(define a (car (psearch (all test-class))))
>(define b (car (psearch (all test-class))))
>(eq? a b)
#t
>(proos-store->list)
((23423523523234342 <weak-box>))
>(set! a #f)
>(set! b #f)
>(collect-garbage)
>(proos-store->list)
()
Because a and b do not reference the #roos object in the weak-box anymore,
the weak-box can be collected. because the weak-box is collected, the
key can
be collected.
Somehow, it works.
Best whishes,
Hans