From f830bbd48213d236429201741edd6ec70e7053f9 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Wed, 14 Apr 2021 20:58:42 -0400 Subject: node: Change id system to a numeric one. --- starling/node.scm | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/starling/node.scm b/starling/node.scm index 704c2ad..4c7e56e 100644 --- a/starling/node.scm +++ b/starling/node.scm @@ -135,10 +135,18 @@ (class-slots class)) instance)) +(define make-id + (let ((n -1)) + (lambda () + (set! n (+ n 1)) + n))) + (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")) + ;; Maybe if/when there's a serialization system this will need to be + ;; more robust so as to preserve ids across processes. + (id #:getter id #:init-thunk make-id) ;; 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) @@ -173,7 +181,7 @@ (define-method (initialize (node ) initargs) (next-method) ;; Add node to global index. - (hashq-set! (nodes-by-id node) (id node) node)) + (hashv-set! (nodes-by-id node) (id node) node) (define (for-each-child proc node) (for-each proc (children node))) -- cgit v1.2.3