Skip to content

Commit

Permalink
binsearch (untested)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinmera committed Jun 14, 2024
1 parent c1ec1dd commit d75c049
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions accessor.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,26 @@
:component-type (component-type accessor)
:element-type (element-type accessor))))

(defun find-sparse-index (accessor i end)
())
(defun find-sparse-index (accessor index end)
(declare (type (unsigned-byte 32) index end))
(declare (type sequences:sequence accessor))
(declare (optimize speed))
(cond ((= 0 end))
((= 1 end)
(when (= index (the (unsigned-byte 32) (elt accessor 0))) 0))
(T
(labels ((recurse (start end)
(declare (type (unsigned-byte 32) start end))
(when (< start end)
(let* ((i (+ start (truncate (- end start) 2)))
(element (the (unsigned-byte 32) (elt accessor i))))
(cond ((< index element)
(recurse start i))
((< element index)
(recurse (1+ i) end))
(T
i))))))
(recurse 0 end)))))

(defmethod sequences:elt ((accessor sparse-accessor) i)
(let ((sparse-i (find-sparse-index (sparse-indices accessor) i (sparse-size accessor))))
Expand Down

0 comments on commit d75c049

Please sign in to comment.