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:
parent
519f3759ea
commit
435ee34acb
1 changed files with 14 additions and 10 deletions
22
utils.rkt
22
utils.rkt
|
@ -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]
|
||||||
|
#:e-func [e-func identity])
|
||||||
|
(define edges
|
||||||
|
(for/list ([e (in-edges gr)])
|
||||||
(match-let ([(list u v) e])
|
(match-let ([(list u v) e])
|
||||||
(if (unweighted-graph? gr)
|
(cond
|
||||||
(list (v-func u) (v-func v))
|
[(unweighted-graph? gr) (list (v-func u) (v-func v))]
|
||||||
(list (e-func (edge-weight gr u v))
|
[else (list (e-func (edge-weight gr u v))
|
||||||
(v-func u) (v-func v)))))])
|
(v-func u) (v-func v))]))))
|
||||||
(if (unweighted-graph? gr)
|
(cond
|
||||||
(unweighted-graph/directed edges)
|
[(unweighted-graph? gr) (unweighted-graph/directed edges)]
|
||||||
(weighted-graph/directed edges))))
|
[else
|
||||||
|
(weighted-graph/directed edges)]))
|
||||||
|
|
||||||
|
|
||||||
;;; ===============
|
;;; ===============
|
||||||
|
|
Loading…
Reference in a new issue