From f398d10d158768ffecc157379b89ab261428ec5e Mon Sep 17 00:00:00 2001 From: Sergiu Ivanov Date: Mon, 14 Aug 2023 13:32:27 +0200 Subject: [PATCH] Type rs->ht-str-triples. --- rs.rkt | 14 +++++++++++++- scribblings/rs.scrbl | 11 +++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/rs.rkt b/rs.rkt index 53d1f5f..07f5a89 100644 --- a/rs.rkt +++ b/rs.rkt @@ -8,7 +8,7 @@ make-reaction enabled? list-enabled union-products apply-rs str-triple->reaction ht-str-triples->rs read-org-rs read-context-sequence - reaction->str-triple + reaction->str-triple rs->ht-str-triples ) (module+ test @@ -155,6 +155,18 @@ (test-case "reaction->str-triple" (check-equal? (reaction->str-triple (make-reaction '(x y) '(z t) '(k i))) '("x y" "z t" "i k")))) + + (: rs->ht-str-triples (-> ReactionSystem (HashTable ReactionName (Listof String)))) + (define (rs->ht-str-triples rs) + (for/hash : (HashTable ReactionName (Listof String)) + ([(a r) (in-hash rs)]) + (values a (reaction->str-triple r)))) + + (module+ test + (test-case "rs->ht-str-triples" + (define rs (hash 'a (make-reaction '(x) '(y) '(z)) + 'b (make-reaction '(x y) '() '(t)))) + (rs->ht-str-triples rs))) ) (require graph "utils.rkt" "generic.rkt") diff --git a/scribblings/rs.scrbl b/scribblings/rs.scrbl index 2188c61..ddf394b 100644 --- a/scribblings/rs.scrbl +++ b/scribblings/rs.scrbl @@ -173,6 +173,17 @@ Converts a reaction to a triple of strings. (reaction->str-triple (make-reaction '(x y) '(z t) '(k i))) ]} +@defproc[(rs->ht-str-triples [rs ReactionSystem]) + (HashTable ReactionName (Listof String))]{ + +Converts a reaction system to a hash table mapping +@racket[ReactionNames]s to triples of strings. + +@ex[ +(rs->ht-str-triples (hash 'a (make-reaction '(x) '(y) '(z)) + 'b (make-reaction '(x y) '() '(z)))) +]} + @section{Dynamics of reaction systems}