From d2b7a6a7e2739869f8b718c80cad7c9515f10070 Mon Sep 17 00:00:00 2001 From: Marius Peter Date: Thu, 20 Nov 2025 14:08:21 +0100 Subject: Replace nutrient-value alists with hashes everywhere. --- models/nutrient.rkt | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'models/nutrient.rkt') diff --git a/models/nutrient.rkt b/models/nutrient.rkt index 91be68f..d79801f 100644 --- a/models/nutrient.rkt +++ b/models/nutrient.rkt @@ -5,7 +5,7 @@ nutrient-id nutrient-name nutrient-formula - nutrient-value-pair/c + nutrient-value-hash/c (contract-out [create-nutrient! (-> string? string? nutrient?)] [get-nutrients (-> (listof nutrient?))] [get-nutrient @@ -18,7 +18,9 @@ (->* (nutrient?) (#:name (or/c #f string?) #:formula (or/c #f string?)) (or/c nutrient? #f))] - [delete-nutrient! (-> nutrient? void?)])) + [delete-nutrient! (-> nutrient? void?)] + [residuals->nutrient-value-hash + (-> (listof residual-vector/c) nutrient-value-hash/c)])) (require racket/contract db @@ -30,7 +32,15 @@ #:property prop:custom-write (λ (v out _) (fprintf out "#<~a ~a>" (nutrient-id v) (nutrient-name v)))) -(define nutrient-value-pair/c (cons/c nutrient? (and/c real? (>=/c 0)))) +(define nutrient-value-hash/c (hash/c nutrient? (and/c real? (>=/c 0)) #:immutable #t)) + +;; vector/c id, nutrient name, nutrient formula, value (ppm) +(define residual-vector/c (vector/c exact-nonnegative-integer? string? string? real?)) + +(define (residuals->nutrient-value-hash residuals) + (for/hash ([r (in-list residuals)]) + (match-define (vector n-id n-name n-formula value-ppm) r) + (values (nutrient n-id n-name n-formula) value-ppm))) ;; CREATE -- cgit v1.2.3