From b1f5d40ad9660e7f087381f3c6cb91d56b4f6a9c Mon Sep 17 00:00:00 2001 From: Guilherme Affonso Date: Thu, 5 May 2022 19:54:12 +0900 Subject: [PATCH] Add fill-count to count deleted members in hash-tables (fixes #405) --- lisp/l/hashtab.l | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lisp/l/hashtab.l b/lisp/l/hashtab.l index da1807331..ef3d049fc 100644 --- a/lisp/l/hashtab.l +++ b/lisp/l/hashtab.l @@ -12,6 +12,7 @@ ((key :type vector) (value :type vector) (size :type :integer) + (fill-count :type :integer) (count :type :integer) (hash-function) (test-function) @@ -45,11 +46,13 @@ (:enter (sym val) (let ((entry (send self :find sym))) (when (>= entry size) ;new entry? - (when (> count (/ size rehash-size)) + (when (> fill-count (/ size rehash-size)) (send self :extend) (setq entry (send self :find sym)) ) + (setq entry (- entry size)) (inc count) - (setq entry (- entry size))) + (if (eq (svref key entry) empty) + (inc fill-count))) (svset key entry sym) (svset value entry val) val)) @@ -74,6 +77,7 @@ x size size altsize altsize x + fill-count 0 count 0) (dotimes (i altsize) (setq x (svref altkey i)) @@ -133,6 +137,7 @@ empty (gensym "EMPTY") deleted (gensym "DEL") not-found nofound + fill-count 0 count 0 rehash-size rehash) (dotimes (i s) (svset key i empty))