1 | (in-package #:abcl.test.lisp) |
---|
2 | |
---|
3 | #| |
---|
4 | (deftest weak-hash-table.1 |
---|
5 | (labels ((random-key () |
---|
6 | (coerce (/ (random 10000) (random 10000)) |
---|
7 | 'single-float))) |
---|
8 | (let ((ht (make-hash-table :weakness :keys)) |
---|
9 | (dotimes (i 1000) |
---|
10 | (setf (gethash (random-key) ht) (random 100000)) |
---|
11 | (sys::hash-table-entries ht) |
---|
12 | |
---|
13 | |# |
---|
14 | |
---|
15 | (defun random-object () |
---|
16 | "A randomly constructed object that is eligible for garbage collection." |
---|
17 | (coerce (/ (random 10000) (1+ (random 10000))) |
---|
18 | 'single-float)) |
---|
19 | |
---|
20 | (deftest weak-hash-table.1 |
---|
21 | (let* ((ht (make-hash-table :weakness :key)) |
---|
22 | (entries 0)) |
---|
23 | (dotimes (i 100000) |
---|
24 | (setf (gethash (random-object) ht) (random 100000)) |
---|
25 | (let ((new-entries (sys::hash-table-count ht))) |
---|
26 | (when (and new-entries |
---|
27 | (> entries new-entries)) |
---|
28 | (format t "~&Previously ~A entries, now ~A." |
---|
29 | entries new-entries)) |
---|
30 | (setf entries new-entries)))) |
---|
31 | nil) |
---|
32 | |
---|
33 | (deftest weak-hash-table.2 |
---|
34 | (let* ((ht (make-hash-table :weakness :value)) |
---|
35 | (entries 0)) |
---|
36 | (dotimes (i 100000) |
---|
37 | (setf (gethash (random-object) ht) (random 100000)) |
---|
38 | (let ((new-entries (sys::hash-table-count ht))) |
---|
39 | (when (and new-entries |
---|
40 | (> entries new-entries)) |
---|
41 | (format t "~&Previously ~A entries, now ~A." |
---|
42 | entries new-entries)) |
---|
43 | (setf entries new-entries)))) |
---|
44 | nil) |
---|
45 | |
---|
46 | (deftest weak-hash-table.3 |
---|
47 | (let* ((ht (make-hash-table :weakness :key-and-value)) |
---|
48 | (entries 0)) |
---|
49 | (dotimes (i 100000) |
---|
50 | (setf (gethash (random-object) ht) (random 100000)) |
---|
51 | (let ((new-entries (sys::hash-table-count ht))) |
---|
52 | (when (and new-entries |
---|
53 | (> entries new-entries)) |
---|
54 | (format t "~&Previously ~A entries, now ~A." |
---|
55 | entries new-entries)) |
---|
56 | (setf entries new-entries)))) |
---|
57 | nil) |
---|
58 | |
---|
59 | (deftest weak-hash-table.4 |
---|
60 | (let* ((ht (make-hash-table :weakness :key-or-value)) |
---|
61 | (entries 0)) |
---|
62 | (dotimes (i 100000) |
---|
63 | (setf (gethash (random-object) ht) (random 100000)) |
---|
64 | (let ((new-entries (sys::hash-table-count ht))) |
---|
65 | (when (and new-entries |
---|
66 | (> entries new-entries)) |
---|
67 | (format t "~&Previously ~A entries, now ~A." |
---|
68 | entries new-entries)) |
---|
69 | (setf entries new-entries)))) |
---|
70 | nil) |
---|
71 | |
---|
72 | |
---|
73 | |
---|
74 | |
---|
75 | |
---|
76 | |
---|