|
1 | 1 | ;; -*- eldoc-documentation-function: eldoc-documentation-default -*- |
2 | 2 | ;; scheme-complete eldoc is bizarrely slow in this buffer |
| 3 | +(begin ; meze only supports one expression per file |
3 | 4 |
|
4 | 5 | (define *nice-n-buckets* |
5 | 6 | '#(2 2 3 5 5 7 7 11 11 13 13 17 17 19 19 23 23 23 23 29 29 31 31 31 31 |
|
162 | 163 | (let loop ((from-idx 0) |
163 | 164 | (to-idx 0)) |
164 | 165 | ;;(display from-idx) (newline) (display to-idx) (newline) (newline) |
165 | | - (cond ((or (>= from-idx (hash-table-next-entry ht)) |
166 | | - (unfilled? (vector-ref (hash-table-keys-vector ht) from-idx))) |
| 166 | + (cond ((>= from-idx (hash-table-next-entry ht)) |
167 | 167 | (vector-fill! (hash-table-keys-vector ht) |
168 | 168 | *unfilled* |
169 | 169 | (hash-table-size ht) |
|
175 | 175 | (hash-table-next-entry-set! ht (hash-table-size ht))) |
176 | 176 | ((deletion? (vector-ref (hash-table-keys-vector ht) from-idx)) |
177 | 177 | (unless fast? |
178 | | - (compact-array-delete! (hash-table-compact-index ht) |
179 | | - (vector-ref (hash-table-values-vector ht) from-idx))) |
| 178 | + (let ((deleted-bucket (vector-ref (hash-table-values-vector ht) from-idx))) |
| 179 | + (compact-array-delete! (hash-table-compact-index ht) |
| 180 | + deleted-bucket) |
| 181 | + (let loop ((deleted-bucket deleted-bucket) |
| 182 | + (examine-bucket (+ deleted-bucket 1))) |
| 183 | + (let ((examine-bucket |
| 184 | + (modulo examine-bucket |
| 185 | + (compact-array-length |
| 186 | + (hash-table-compact-index ht))))) |
| 187 | + (let ((collision-idx |
| 188 | + (compact-array-ref (hash-table-compact-index ht) |
| 189 | + examine-bucket))) |
| 190 | + (when collision-idx |
| 191 | + (let* ((key (vector-ref (hash-table-keys-vector ht) |
| 192 | + collision-idx)) |
| 193 | + (new-bucket |
| 194 | + (if (deletion? key) |
| 195 | + (vector-ref (hash-table-values-vector ht) |
| 196 | + collision-idx) |
| 197 | + (hash-table-bucket-for-key ht key)))) |
| 198 | + (if (eqv? new-bucket deleted-bucket) |
| 199 | + (begin |
| 200 | + (compact-array-set! (hash-table-compact-index ht) |
| 201 | + deleted-bucket |
| 202 | + collision-idx) |
| 203 | + (compact-array-delete! (hash-table-compact-index ht) |
| 204 | + examine-bucket) |
| 205 | + (loop examine-bucket (+ examine-bucket 1))) |
| 206 | + (loop deleted-bucket (+ examine-bucket 1)))))))))) |
180 | 207 | (loop (+ from-idx 1) to-idx)) |
181 | 208 | ((eqv? from-idx to-idx) (loop (+ from-idx 1) (+ to-idx 1))) |
182 | 209 | (else |
|
233 | 260 |
|
234 | 261 | ;; add to the entries arrays, setting the bucket in the compact index |
235 | 262 | (define (hash-table-add-entry! ht bucket key value) |
236 | | - (if (>= (hash-table-next-entry ht) |
237 | | - (vector-length (hash-table-keys-vector ht))) |
238 | | - (hash-table-grow-entries! ht)) |
| 263 | + (when (>= (hash-table-next-entry ht) |
| 264 | + (vector-length (hash-table-keys-vector ht))) |
| 265 | + (if (eqv? (hash-table-size ht) (hash-table-next-entry ht)) |
| 266 | + (hash-table-grow-entries! ht) |
| 267 | + (begin |
| 268 | + (hash-table-grow-entries! ht) |
| 269 | + (set! bucket (hash-table-bucket-for-key ht key))))) |
239 | 270 | (when (hash-table-compact-index-must-grow? ht) |
240 | 271 | (hash-table-grow-compact-index! ht) |
241 | 272 | (set! bucket (hash-table-bucket-for-key ht key))) |
|
416 | 447 |
|
417 | 448 | (define (hash-table-pop! ht) |
418 | 449 | (unless (hash-table-mutable? ht) |
419 | | - (assertion-violation 'hash-table-delete! |
| 450 | + (assertion-violation 'hash-table-pop! |
420 | 451 | "hash table is immutable" |
421 | 452 | ht)) |
422 | 453 | (when (hash-table-empty? ht) |
|
425 | 456 | ht)) |
426 | 457 | (let* ((idx (- (hash-table-next-entry ht) 1)) |
427 | 458 | (key (vector-ref (hash-table-keys-vector ht) idx)) |
428 | | - (value (vector-ref (hash-table-values-vector ht) idx))) |
429 | | - (vector-set! (hash-table-keys-vector ht) idx *unfilled*) |
430 | | - (vector-set! (hash-table-values-vector ht) idx *unfilled*) |
| 459 | + (value (vector-ref (hash-table-values-vector ht) idx)) |
| 460 | + (bucket (hash-table-bucket-for-key ht key))) |
| 461 | + (vector-set! (hash-table-keys-vector ht) idx *deletion*) |
| 462 | + (vector-set! (hash-table-values-vector ht) idx bucket) |
431 | 463 | (hash-table-size-set! ht (- (hash-table-size ht) 1)) |
432 | | - (hash-table-next-entry-set! ht idx) |
| 464 | + (hash-table-prune-dead-entries-at-end! ht) |
433 | 465 | (values key value))) |
434 | 466 |
|
435 | 467 | (define (hash-table-clear! ht) |
|
635 | 667 | ht)) |
636 | 668 |
|
637 | 669 | (define (hash-table-prune! proc ht) |
| 670 | + (define original-size (hash-table-size ht)) |
638 | 671 | (unless (hash-table-mutable? ht) |
639 | 672 | (assertion-violation 'hash-table-prune! |
640 | 673 | "hash table is immutable" |
641 | 674 | ht)) |
642 | 675 | (let loop ((cur (hash-table-cursor-first ht)) (n-deleted 0)) |
643 | 676 | (if (hash-table-cursor-at-end? ht cur) |
644 | 677 | (begin |
645 | | - (hash-table-size-set! ht (- (hash-table-size ht) n-deleted)) |
646 | 678 | (hash-table-prune-dead-entries-at-end! ht) |
647 | | - (when (> (- (hash-table-next-entry ht) (hash-table-size ht)) |
| 679 | + (when (> (- (hash-table-next-entry ht) original-size) |
648 | 680 | (* 1/3 (hash-table-size ht))) |
649 | 681 | (hash-table-prune-dead-entries! ht #f)) |
650 | 682 | n-deleted) |
651 | 683 | (let-values (((k v) (hash-table-cursor-key+value ht cur))) |
652 | 684 | (if (and (proc k v) |
653 | 685 | (hash-table-delete-one! ht k)) |
654 | | - (loop (hash-table-cursor-next ht cur) (+ n-deleted 1)) |
| 686 | + (begin |
| 687 | + (hash-table-size-set! ht (- (hash-table-size ht) 1)) |
| 688 | + (loop (hash-table-cursor-next ht cur) (+ n-deleted 1))) |
655 | 689 | (loop (hash-table-cursor-next ht cur) n-deleted)))))) |
656 | 690 |
|
657 | 691 | (define (hash-table-copy ht mutable?) |
|
679 | 713 | (hash-table-for-each |
680 | 714 | (lambda (k v) |
681 | 715 | (unless (hash-table-contains? ht_1 k) |
682 | | - (hash-table-set! ht_2 k v))) |
| 716 | + (hash-table-set! ht_1 k v))) |
683 | 717 | ht_2) |
684 | 718 | ht_1) |
685 | 719 |
|
|
771 | 805 | "hash table is immutable" |
772 | 806 | ht)) |
773 | 807 | (hash-table-set! ht key (updater (hash-table-ref/default ht key default)))) |
| 808 | + |
| 809 | +) |
0 commit comments