/
label.cljc
66 lines (53 loc) · 1.59 KB
/
label.cljc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
(ns blossom.label
(:require [blossom.context]
[blossom.constants :as c]
[blossom.endpoint :as endpoint]))
(defprotocol PLabelable
(add-label [graph node label]
"Add a label to a node")
(label [graph node]
"Return the label on a node")
(remove-label [graph node]
"Remove a label from a node")
(remove-all-labels [graph]
"remove all labels from the graph")
(unlabeled? [graph node])
(labeled? [graph node])
(s-blossom? [graph node])
(t-blossom? [graph node])
(breadcrumb? [graph node])
(set-endp [graph node endpoint])
(remove-endp [graph node])
(endp [graph node])
(some-endp? [graph node])
(no-endp? [graph node]))
(extend-type blossom.context.Context
PLabelable
(add-label [this node t]
(update this :label assoc node t))
(remove-label [this node]
(add-label this node c/FREE))
(label [this b]
(nth (:label this) b))
(unlabeled? [this v]
(= c/FREE (label this v)))
(labeled? [this v]
(not= c/FREE (label this v)))
(s-blossom? [this v]
(= c/S-BLOSSOM (label this v)))
(t-blossom? [this v]
(= c/T-BLOSSOM (label this v)))
(breadcrumb? [this v]
(= c/BREADCRUMB (label this v)))
(set-endp [this b endpoint]
(update this :label-end assoc b endpoint))
(remove-endp [this b]
(set-endp this b c/NO-ENDP))
(endp [this b]
(nth (:label-end this) b))
(some-endp? [graph node]
(endpoint/some-endp? (endp graph node)))
(no-endp? [graph node]
(endpoint/no-endp? (endp graph node)))
(remove-all-labels [this]
(assoc this :label (vec (repeat (* 2 (:nvertex this)) c/FREE)))))