diff options
| author | Loic Guegan <manzerberdes@gmx.com> | 2019-02-24 10:30:57 +0100 |
|---|---|---|
| committer | Loic Guegan <manzerberdes@gmx.com> | 2019-02-24 10:30:57 +0100 |
| commit | 5725987c8dfd55d4ee0282f0a37779e06052f3c6 (patch) | |
| tree | d985acea2fdb3149804ea630c06662d5a8d0796c /src/union-find/quick-union.lisp | |
| parent | d0f6e2ff9cdf4c35e99b54fa765aca7f46ed6a24 (diff) | |
Re-organize code
Diffstat (limited to 'src/union-find/quick-union.lisp')
| -rw-r--r-- | src/union-find/quick-union.lisp | 42 |
1 files changed, 0 insertions, 42 deletions
diff --git a/src/union-find/quick-union.lisp b/src/union-find/quick-union.lisp deleted file mode 100644 index bf2ff3d..0000000 --- a/src/union-find/quick-union.lisp +++ /dev/null @@ -1,42 +0,0 @@ -;;;; 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))) - (dotimes (id n) - (vector-push id nodes)) - nodes)) - -(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))) - -(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))) - (setf (elt new-network (find-root new-network n1)) - (find-root new-network n2)) - new-network)) - - -;;; 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 destructive version of union_" - `(setf ,network (union_ ,network ,n1 ,n2))) - |
