diff options
author | David Thompson <dthompson@vistahigherlearning.com> | 2020-09-29 20:03:13 -0400 |
---|---|---|
committer | David Thompson <dthompson@vistahigherlearning.com> | 2020-09-29 20:04:20 -0400 |
commit | b00da409c86f4120332bd7a36c71daf0a03375da (patch) | |
tree | eda2509d43113f3d18618256509db54d656c483b | |
parent | 14c986ff914080882686cb2b2c12dbe874ac64e5 (diff) |
node: Add unique ids with global index.
-rw-r--r-- | starling/node.scm | 11 |
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))) |