summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--starling/node.scm11
1 files changed, 11 insertions, 0 deletions
diff --git a/starling/node.scm b/starling/node.scm
index d42a00c..ff7d0db 100644
--- a/starling/node.scm
+++ b/starling/node.scm
@@ -61,6 +61,12 @@
#:replace (pause))
(define-class <node> ()
+ ;; Auto-generated process-unique identifier. As of now I don't see
+ ;; a need for globally unique identifiers and this is much faster.
+ (id #:getter id #:init-form (gensym "node"))
+ ;; Global index of all nodes by their unique id.
+ (nodes-by-id #:getter nodes-by-id #:allocation #:class
+ #:init-thunk make-weak-value-hash-table)
;; Symbolic name. Used for easy lookup of children within a parent.
(name #:getter name #:init-form #f #:init-keyword #:name)
;; An integer value that determines priority order for
@@ -89,6 +95,11 @@
<redefinable-class>
<class>))
+(define-method (initialize (node <node>) initargs)
+ (next-method)
+ ;; Add node to global index.
+ (hashq-set! (nodes-by-id node) (id node) node))
+
(define (for-each-child proc node)
(for-each proc (children node)))