Ignore:
Timestamp:
06/07/11 15:38:11 (10 years ago)
Author:
Mark Evenson
Message:

Implementation of hashtables with weak keys and/or values.

MAKE-HASH-TABLE now has an optional :WEAKNESS argument that can take
the values :KEY, :VALUE, :KEY-AND-VALUE, or :KEY-OR-VALUE. :KEY means
that the key of an entry must be live to guarantee that the entry is
preserved. VALUE means that the value of an entry must be live to
guarantee that the entry is preserved. :KEY-AND-VALUE means that both
the key and the value must be live to guarantee that the entry is
preserved. :KEY-OR-VALUE means that either the key or the value must
be live to guarantee that the entry is preserved.

The tests simply excercise the various types of weak hash tables
enough that a GC phase should show that the table indeed does decrease
in size.

Changed the defition of functions in HashTableFunctions? to match
current docstring/pf_XXX() naming conventions.

This implementation is only lightly tested in single-threaded use, and
untested in multiple threading scenarios.

Addresses ticket:140.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/abcl/src/org/armedbear/lisp/make-hash-table.lisp

    r11391 r13309  
    3333
    3434(defun make-hash-table (&key (test 'eql) (size 11) (rehash-size 1.5)
    35            (rehash-threshold 0.75))
     35                             (rehash-threshold 0.75)
     36                             (weakness nil))
    3637  (setf test (coerce-to-function test))
    3738  (unless (and (integerp size) (>= size 0))
    3839    (error 'type-error :datum size :expected-type '(integer 0)))
    39   (let ((size (max 11 (min size array-dimension-limit))))
    40     (%make-hash-table test size rehash-size rehash-threshold)))
     40  (let ((size (max 11 (min size array-dimension-limit)))
     41        (weakness-types '(or (eql :key) (eql :value)
     42                             (eql :key-and-value)
     43                             (eql :key-or-value))))
     44    (if weakness
     45        (if (not (typep weakness weakness-types))
     46            (error 'type-error :datum weakness
     47                   :expected-type weakness-types)
     48            (%make-weak-hash-table test size rehash-size
     49                                   rehash-threshold weakness))
     50  (%make-hash-table test size
     51                          rehash-size rehash-threshold))))
     52
     53   
     54 
Note: See TracChangeset for help on using the changeset viewer.