Skip to content

Commit

Permalink
[Refs #12] Don't add nodes to an index if they already exist
Browse files Browse the repository at this point in the history
  • Loading branch information
eudoxia0 committed Oct 12, 2015
1 parent 2e2aecb commit d013dd2
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions src/core.lisp
Expand Up @@ -67,10 +67,28 @@
:documentation "A vector of package indices."))
(:documentation "Holds system documentation, and the internal package indices."))

(defmacro do-packages ((package index) &body body)
"Iterate over every package in the index."
`(loop for ,package across (index-packages ,index) do
,@body))

(defmacro do-nodes ((node package-index) &body body)
"Iterate over every node in a package index."
`(loop for ,node across (package-index-nodes ,package-index) do
,@body))

(defun add-package-index (index package-index)
(unless (find-package-index index (package-index-name package-index))
(vector-push-extend package-index (index-packages index))))

(defun node-exists-p (index node)
"Does the node exist in the package index."
(do-packages (package index)
(do-nodes (test-node package)
(when (node= test-node node)
(return-from node-exists-p t))))
nil)

(defun add-node (index node)
"Add a node to an index, finding the proper package index."
(let* ((symbol (node-name node))
Expand All @@ -81,7 +99,8 @@
:test #'equal
:key #'package-index-name))))
(when package-index
(vector-push-extend node (package-index-nodes package-index)))))
(unless (node-exists-p index node)
(vector-push-extend node (package-index-nodes package-index))))))

;;; Parsers

Expand Down Expand Up @@ -151,16 +170,6 @@
(parse-system index system-or-list))
index))

(defmacro do-packages ((package index) &body body)
"Iterate over every package in the index."
`(loop for ,package across (index-packages ,index) do
,@body))

(defmacro do-nodes ((node package-index) &body body)
"Iterate over every node in a package index."
`(loop for ,node across (package-index-nodes ,package-index) do
,@body))

(defun find-package-index (index package-name)
"Return the package-index with that name, or NIL."
(let ((results (remove-if-not #'(lambda (package-index)
Expand Down

0 comments on commit d013dd2

Please sign in to comment.