diff options
| author | Loic GUEGAN <loic.guegan@yahoo.fr> | 2019-01-27 20:29:42 +0100 |
|---|---|---|
| committer | Loic GUEGAN <loic.guegan@yahoo.fr> | 2019-01-27 20:29:42 +0100 |
| commit | 2dfdbfbb498d0584a8147279464039c49bea515a (patch) | |
| tree | e4f757e812a7a895f4efa5a5d059562817d2c1c3 /src/quick-union.lisp | |
| parent | 30765ae30d516eda228447408b59be03712f5b17 (diff) | |
Update comments
Diffstat (limited to 'src/quick-union.lisp')
| -rw-r--r-- | src/quick-union.lisp | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/src/quick-union.lisp b/src/quick-union.lisp index ca61703..9b4e9d8 100644 --- a/src/quick-union.lisp +++ b/src/quick-union.lisp @@ -1,4 +1,13 @@ -;; Create network nodes +;;;; Quick Union Algorithm +;;;; This algorithm solve dynamic connectivity +;;;; problem by providing a way to find if there +;;;; is a path between two nodes in a dynamic graph. +;;;; It is an improved version of the Quick Find algorithm +;;;; It optimize the union function + + +;;; Base functions + (defun create-network (n) "Build a quick-find network using a dynamic vector" (let ((nodes (make-array n :fill-pointer 0))) @@ -6,20 +15,12 @@ (vector-push id nodes)) nodes)) -;; Find the root of a node (defun find-root (network node) "Find the root of a sub-tree in the network." (do ((id node value) (value (elt network node) (elt network value))) ((= id value) id))) -;; Check if two nodes are connected -(defmacro connected (network n1 n2) - "Return true if n1 and n2 are connected and nil otherwise. connection represent -the find operation on the Quick Union algorithm" - `(= (find-root ,network ,n1) (find-root ,network ,n2))) - -;; Link two nodes together (defun union_ (network n1 n2) "Connect to sub-tree together. union represent the union operation on the Quick Union algorithm" (let ((new-network (copy-seq network))) @@ -27,7 +28,15 @@ the find operation on the Quick Union algorithm" (find-root new-network n2)) new-network)) -;; A consed version of union_ + +;;; Macro definitions + +(defmacro connected (network n1 n2) + "Return true if n1 and n2 are connected and nil otherwise. connection represent +the find operation on the Quick Union algorithm" + `(= (find-root ,network ,n1) (find-root ,network ,n2))) + (defmacro nunion_ (network n1 n2) + "A consed version of union_" `(setf ,network (union_ ,network ,n1 ,n2))) |
