From b00da409c86f4120332bd7a36c71daf0a03375da Mon Sep 17 00:00:00 2001 From: David Thompson Date: Tue, 29 Sep 2020 20:03:13 -0400 Subject: node: Add unique ids with global index. --- starling/node.scm | 11 +++++++++++ 1 file changed, 11 insertions(+) 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 () + ;; 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 @@ )) +(define-method (initialize (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))) -- cgit v1.2.3