close Warning: Can't synchronize with repository "(default)" (The repository directory has changed, you should resynchronize the repository with: trac-admin $ENV repository resync '(default)'). Look in the Trac log for more information.

Changeset 3989 for branches


Ignore:
Timestamp:
2016-05-30T21:02:49-07:00 (8 years ago)
Author:
Marek Rychlik
Message:

* empty log message *

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/f4grobner/priority-queue.lisp

    r3985 r3989  
    3838(in-package :priority-queue)
    3939
    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."))
    4344
    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))))))
    5054 
    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))))
    5360
    5461(defun priority-queue-remove (pq)
Note: See TracChangeset for help on using the changeset viewer.