utils: Refactor update-graph.

Make update-graph follow a little bit more the guidelines here:
https://docs.racket-lang.org/style/Choosing_the_Right_Construct.html
This commit is contained in:
Sergiu Ivanov 2020-03-20 21:42:10 +01:00
parent 519f3759ea
commit 435ee34acb

View file

@ -277,16 +277,20 @@
;;; functions. If gr is an weighted graph, the result is a weighted ;;; functions. If gr is an weighted graph, the result is a weighted
;;; graph. If gr is an unweighted graph, the result is an unweighted ;;; graph. If gr is an unweighted graph, the result is an unweighted
;;; graph. ;;; graph.
(define (update-graph gr #:v-func [v-func identity] #:e-func [e-func identity]) (define (update-graph gr
(let ([edges (for/list ([e (in-edges gr)]) #:v-func [v-func identity]
(match-let ([(list u v) e]) #:e-func [e-func identity])
(if (unweighted-graph? gr) (define edges
(list (v-func u) (v-func v)) (for/list ([e (in-edges gr)])
(list (e-func (edge-weight gr u v)) (match-let ([(list u v) e])
(v-func u) (v-func v)))))]) (cond
(if (unweighted-graph? gr) [(unweighted-graph? gr) (list (v-func u) (v-func v))]
(unweighted-graph/directed edges) [else (list (e-func (edge-weight gr u v))
(weighted-graph/directed edges)))) (v-func u) (v-func v))]))))
(cond
[(unweighted-graph? gr) (unweighted-graph/directed edges)]
[else
(weighted-graph/directed edges)]))
;;; =============== ;;; ===============