Changeset 7693
 Timestamp:
 Nov 20, 2007, 3:06:48 PM (13 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

branches/working0710/ccl/lib/hash.lisp
r7511 r7693 210 210 211 211 212 (defun starthashtableiterator (hash state) 213 (let (vector locked) 214 (unless (hashtablep hash) 215 (setf (hti.hashtable state) nil) ; for finishhashtableiterator 216 (reportbadarg hash 'hashtable)) 217 218 (withoutinterrupts 219 (setf (hti.hashtable state) hash) 220 (setf (hti.lock state) (setq locked (not (eq :readonly (lockhashtableformap hash))))) 221 (when locked (%lockgclock)) 222 (setq vector (nhash.vector hash)) 223 (setf (hti.vector state) vector) 224 (setf (hti.index state) (nhash.vectorsize vector)) 225 (setf (hti.previterator state) (nhash.iterator hash) 226 (nhash.iterator hash) state) 227 (when (%needsrehashingp hash) 228 (%rehash hash))))) 229 230 ;;; this is as fast as the lappy version 231 232 (defun dohashtableiteration (state) 233 (let ((vector (hti.vector state)) 234 (index (hti.index state)) 235 key value) 236 (declare (optimize (speed 3) (safety 0))) 237 (if (setf (hti.index state) 238 (if index 239 (loop 240 (if (eq index 0)(return (setq index nil))) 241 (locally (declare (fixnum index)) 242 (setq index ( index 1)) 243 (let* ((vectorindex (index>vectorindex index))) 244 (declare (fixnum vectorindex)) 245 (setq key (%svref vector vectorindex)) 246 (unless (or (eq key (%unboundmarker)) 247 (eq key (%slotunboundmarker))) 248 (setq value (%svref vector (the fixnum (1+ vectorindex)))) 249 (return index))))))) 250 (let* ((hash (hti.hashtable state))) 251 (setf (nhash.vector.cacheidx (setq vector (nhash.vector hash))) index 252 (nhash.vector.cachekey vector) key 253 (nhash.vector.cachevalue vector) value) 254 (values t key value))))) 255 256 (defun finishhashtableiterator (state) 257 (withoutinterrupts 258 (let ((hash (hti.hashtable state)) 259 (locked (hti.lock state))) 260 (when hash 261 (setf (hti.hashtable state) nil) 262 (when locked 263 (unlockhashtable hash nil) 264 (%unlockgclock)) 265 (when (eq state (nhash.iterator hash)) 266 (setf (nhash.iterator hash) (hti.previterator state))) 267 (setf 268 (hti.index state) nil 269 (hti.vector state) nil 270 (hti.lock state) nil))))) 212 213 (defun nexthashtableiteration (state) 214 (do* ((hash (nhti.hashtable state)) 215 (index (nhti.index state) (1+ index)) 216 (keys (nhti.keys state)) 217 (nkeys (nhti.nkeys state)) 218 (missing (cons nil nil))) 219 ((>= index nkeys) 220 (setf (nhti.index state) nkeys) 221 (values nil nil nil)) 222 (declare (fixnum index nkeys) 223 (simplevector keys) 224 (dynamicextent missing)) 225 (let* ((key (svref keys index)) 226 (value (gethash key hash missing))) 227 (unless (eq value missing) 228 (setf (nhti.index state) (1+ index)) 229 (return (values t key value)))))) 230 231 271 232 272 233 (defun maphash (function hashtable)
Note: See TracChangeset
for help on using the changeset viewer.