-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathnode.lisp
More file actions
39 lines (30 loc) · 971 Bytes
/
Copy pathnode.lisp
File metadata and controls
39 lines (30 loc) · 971 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
(in-package #:graph-utils)
(defun print-node (node stream depth)
(declare (ignore depth))
(format stream "#<NODE ~A" (node-id node))
(when (node-weight node)
(format stream "(~A) " (node-weight node)))
(format stream ": ~A>" (node-value node)))
(defstruct (node
(:constructor %make-node)
(:print-function print-node))
value
id
weight)
(let ((id 0))
(defun next-node-id ()
(incf id)))
(defun make-node (&key value id weight)
(let ((id (or id (next-node-id))))
(%make-node :value value :weight weight :id id)))
(defmethod node= (n1 n2)
(= (node-id n1) (node-id n2)))
(defmethod node-eql (n1 n2)
(and (= (node-id n1) (node-id n2))
(eql (node-value n1) (node-value n2))))
(defmethod node-equal (n1 n2)
(and (= (node-id n1) (node-id n2))
(equal (node-value n1) (node-value n2))))
(defmethod node-equalp (n1 n2)
(and (= (node-id n1) (node-id n2))
(equalp (node-value n1) (node-value n2))))