chiark / gitweb /
Lots of tidying up.
[lisp] / aa-tree.lisp
index 6c42746b1c5896c1b611d38e63eabe37a7d9f3b9..a08d52d7cccc8656ca6bded4a2ec859f35538074 100644 (file)
@@ -1,7 +1,5 @@
 ;;; -*-lisp-*-
 ;;;
-;;; $Id$
-;;;
 ;;; Andersson tree implementation
 ;;;
 ;;; (c) 2006 Straylight/Edgeware
@@ -27,9 +25,7 @@
 ;;; Package.
 
 (defpackage #:aa-tree
-  (:use #:common-lisp #:mdw.base)
-  (:export #:make-aa-tree #:aa-tree-p #:aa-tree-key<
-          #:getaa #:updateaa #:mapaa #:doaa #:aa-tree-iterator #:remaa))
+  (:use #:common-lisp #:mdw.base))
 (in-package #:aa-tree)
 
 ;;;--------------------------------------------------------------------------
@@ -51,6 +47,7 @@ (defstruct (tree-node
 
 (deftype tree-node () 'simple-vector)
 
+(export '(make-aa-tree aa-tree aa-tree-p aa-tree-key<))
 (defstruct (aa-tree
             (:predicate treep)
             (:constructor make-aa-tree
@@ -103,6 +100,7 @@ (defun get-tree-stack (tree)
        (do ((need (ash size 1) (ash need 1)))
            ((>= need want) (setf (tree-stack tree) (make-array need)))))))
 
+(export 'getaa)
 (defun getaa (tree key &optional default)
   "Look up the given KEY in an Andersson TREE; if the KEY was found, return
    the corresponding data and t, otherwise return DEFAULT and nil."
@@ -195,6 +193,7 @@ (defun (setf getaa) (data tree key &optional ignore)
     (cond (node (setf (node-data node) data))
          (t (fixup-insert tree stack sp (make-tree-node key data)) data))))
 
+(export 'updateaa)
 (defun updateaa (tree key func)
   "Search TREE for an item with the given KEY.  If it was found, call FUNC
    with arguments of the node's data and t, and store its result as the
@@ -208,6 +207,7 @@ (defun updateaa (tree key func)
               (fixup-insert tree stack sp (make-tree-node key data))
               data)))))
 
+(export 'remaa)
 (defun remaa (tree key)
   "Deletes the node with the given KEY from an Andersson TREE.  Returns t if
    the node was found and deleted, or nil if it wasn't there to begin with."
@@ -266,6 +266,7 @@ (defun remaa (tree key)
        ;; Store the new root.
        (setf (tree-root tree) node)))))
 
+(export 'aa-tree-iterator)
 (defun aa-tree-iterator (tree)
   "Returns a tree iterator function for TREE.  The function returns three
    values.  For each node in the tree, it returns t, the key and the value;
@@ -287,6 +288,7 @@ (defun aa-tree-iterator (tree)
                         (pushleft (node-right node))
                         (values t (node-key node) (node-data node)))))))))))
 
+(export 'mapaa)
 (defun mapaa (func tree)
   "Apply FUNC to each key and value in the TREE."
   (labels ((walk (node)
@@ -297,6 +299,7 @@ (defun mapaa (func tree)
     (walk (tree-root tree))
     nil))
 
+(export 'doaa)
 (defmacro doaa ((key value tree &optional result) &body body)
   "Iterate over the items of TREE; for each one, bind KEY to its key and
    VALUE to the associated data, and evaluate BODY, which is an implicit