You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
block -> if block#2 === nullthenhold block#0 else block#2)
104
+
105
+
runLengthEncode1 = x -> (
106
+
blocks := apply(x, item -> (item, 1, null));
107
+
done := false;
108
+
whilenot done do (
109
+
next := runLengthEncodeSuccessors runLengthEncodeDuplicates blocks;
110
+
done = #next === #blocks;
111
+
blocks = next);
112
+
newclass x from runLengthEncodeOutput blocks)
113
+
66
114
runLengthEncode = method(Dispatch => Thing)
67
-
runLengthEncodeVisibleList := x -> (
68
-
local xx;
69
-
while (xx=runLengthEncode0 x; #x =!= #xx) do x=xx;
70
-
xx
71
-
)
72
-
runLengthEncode0 = x -> (
73
-
if #x === 0thenreturn x;
74
-
dupout := true;
75
-
whilefirst(dupout,dupout = false) do x = newclass x from (
76
-
i0 := null;
77
-
lastout := oi := symbol oi;
78
-
m := 0;
79
-
dupin := null;
80
-
for i inappend(x,symbol x) list
81
-
(o -> (if lastout === o then dupout = trueelse lastout = o; o))(
82
-
if i === oi and dupin =!= falsethen (dupin = true; m = m+1; continue)
83
-
elseif succ(oi,i) and dupin =!= truethen (
84
-
if dupin === nullthen i0 = oi;
85
-
dupin = false;
86
-
oi = i;
87
-
m = m+1;
88
-
continue)
89
-
elsefirst(
90
-
if oi === symbol oi then (oi = i; m = 1 ; continue) else
91
-
if m === 1thenhold oi elseif dupin === truethenhold m : expression oi else (ifinstance(i0,BinaryOperation) then i0#1 elseexpression i0) .. (ifinstance(oi,BinaryOperation) then oi#2 elseexpression oi),
92
-
(dupin = null; oi = i; m = 1))));
93
-
x)
94
-
95
-
rle = method(Dispatch => Thing)
96
-
rle VisibleList := x -> apply(runLengthEncode x, rle)
97
-
rle Holder := x -> rle x#0
98
-
rle Option := x -> x#0 => rle x#1
99
-
rle Thing := identity
115
+
runLengthEncodeVisibleList := x -> apply(runLengthEncode1 x, runLengthEncode)
116
+
runLengthEncodeHolder := x -> holdunsequencerunLengthEncode x#0
117
+
runLengthEncodeOption := x -> x#0 => runLengthEncode x#1
0 commit comments