@@ -6,13 +6,16 @@ Question: when decompressing, should we always assume that the coloring was opti
66=#
77
88"""
9- cycle_until(iterator, max_length ::Integer)
9+ cycle_range(k::Integer, n ::Integer)
1010
11- Concatenate copies of `iterator ` to fill a vector of length `max_length ` (with one partial copy allowed at the end).
11+ Concatenate copies of `1:k ` to fill a vector of length `n ` (with one partial copy allowed at the end).
1212"""
13- function cycle_until (iterator, max_length:: Integer )
14- a = repeat (iterator, div (max_length, length (iterator)) + 1 )
15- return resize! (a, max_length)
13+ function cycle_range (k:: Integer , n:: Integer )
14+ color = Vector {Int} (undef, n)
15+ for i in eachindex (color)
16+ color[i] = 1 + (i - 1 ) % k
17+ end
18+ return color
1619end
1720
1821# # Diagonal
@@ -67,7 +70,7 @@ function coloring(
6770 algo:: GreedyColoringAlgorithm ;
6871 kwargs... ,
6972)
70- color = cycle_until (1 : 2 , size (A, 2 ))
73+ color = cycle_range (1 : 2 , size (A, 2 ))
7174 bg = BipartiteGraph (A)
7275 return ColumnColoringResult (A, bg, color)
7376end
@@ -78,7 +81,7 @@ function coloring(
7881 algo:: GreedyColoringAlgorithm ;
7982 kwargs... ,
8083)
81- color = cycle_until (1 : 2 , size (A, 1 ))
84+ color = cycle_range (1 : 2 , size (A, 1 ))
8285 bg = BipartiteGraph (A)
8386 return RowColoringResult (A, bg, color)
8487end
@@ -123,7 +126,7 @@ function coloring(
123126 algo:: GreedyColoringAlgorithm ;
124127 kwargs... ,
125128)
126- color = cycle_until (1 : 3 , size (A, 2 ))
129+ color = cycle_range (1 : 3 , size (A, 2 ))
127130 bg = BipartiteGraph (A)
128131 return ColumnColoringResult (A, bg, color)
129132end
@@ -134,7 +137,7 @@ function coloring(
134137 algo:: GreedyColoringAlgorithm ;
135138 kwargs... ,
136139)
137- color = cycle_until (1 : 3 , size (A, 1 ))
140+ color = cycle_range (1 : 3 , size (A, 1 ))
138141 bg = BipartiteGraph (A)
139142 return RowColoringResult (A, bg, color)
140143end
0 commit comments