Changeset 3989 for branches/f4grobner
- Timestamp:
- 2016-05-30T21:02:49-07:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/f4grobner/priority-queue.lisp
r3985 r3989 38 38 (in-package :priority-queue) 39 39 40 (defstruct (priority-queue (:constructor priority-queue-construct)) 41 (heap (make-heap)) 42 test) 40 (defclass priority-queue () 41 ((heap :initarg :heap :accessor priority-queue-heap) 42 (test :initarg :ters :accessor priority-queue-test)) 43 (:documentation "Representa a priority queue.")) 43 44 44 (defun make-priority-queue (&key (element-type 'fixnum) 45 (test #'<=) 46 (element-key #'identity)) 47 (priority-queue-construct 48 :heap (make-heap :element-type element-type) 49 :test #'(lambda (x y) (funcall test (funcall element-key y) (funcall element-key x))))) 45 (defmethod initialize-instance ((self priority-queue) 46 &key 47 (element-type 'fixnum) 48 (test #'<=) 49 (element-key #'identity)) 50 (with-slots (heap test) 51 self 52 (setf heap (make-heap :element-type element-type) 53 test #'(lambda (x y) (funcall test (funcall element-key y) (funcall element-key x)))))) 50 54 51 (defun priority-queue-insert (pq item) 52 (heap-insert (priority-queue-heap pq) item (priority-queue-test pq))) 55 (defgeneric enqueue (self item) 56 (:method ((self priority-queue) (item t)) 57 (with-slots (heap test) 58 self 59 (heap-insert heap item test)))) 53 60 54 61 (defun priority-queue-remove (pq)
Note:
See TracChangeset
for help on using the changeset viewer.