Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Avoid infinite loop when hash-table has no empty members #405

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions lisp/l/hashtab.l
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
(defmethod hash-table
(:size () size)
(:find (s)
(let* ((hash (abs (mod (funcall hash-function s) size))) (entry) (empty-pos))
(let* ((hash (abs (mod (funcall hash-function s) size)))
(first-hash hash)
(entry) (empty-pos))
(while t
(setq entry (svref key hash))
(if (funcall test-function entry s) (return-from :find hash))
Expand All @@ -37,7 +39,11 @@
(return-from :find (+ empty-pos size)))
(when (eq entry deleted)
(if (null empty-pos) (setq empty-pos hash)))
(if (>= (inc hash) size) (setq hash 0)))
(if (>= (inc hash) size) (setq hash 0))
(when (eq hash first-hash) ;; looped through all hash elements
(if empty-pos
(return-from :find (+ empty-pos size))
(error "hash-table is full"))))
nil))
(:get (s)
(let ((entry (send self :find s)))
Expand Down