Commit fab1d7d
committed
Replace Array with Set for uncollapsed cells tracking
Optimize uncollapsed cell tracking by using Set instead of Array,
eliminating O(n) deletion overhead.
Changes:
- Add hash and eql? methods to Cell class for Set compatibility
- Replace Array with Set for @uncollapsed_cells collection
- Update percent() to use .size instead of .length
- Update prepend_empty_row() to use .add() instead of <<
- Rewrite find_lowest_entropy() to iterate Set instead of indexed access
- Update random_cell() to convert Set to Array for sampling
Performance impact:
- Cell deletion operations: O(n) → O(1)
- 20x20 grid: ~4.51s average (vs ~4.86s with Array)
- ~7% improvement, scales better with larger grids
The Set data structure is semantically correct for tracking a collection
of unique cells where order doesn't matter and membership testing/deletion
are frequent operations.1 parent 78c6230 commit fab1d7d
2 files changed
+25
-18
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
23 | 31 | | |
24 | 32 | | |
25 | 33 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
1 | 3 | | |
2 | 4 | | |
3 | 5 | | |
| |||
25 | 27 | | |
26 | 28 | | |
27 | 29 | | |
28 | | - | |
| 30 | + | |
29 | 31 | | |
30 | 32 | | |
31 | 33 | | |
| |||
64 | 66 | | |
65 | 67 | | |
66 | 68 | | |
67 | | - | |
| 69 | + | |
68 | 70 | | |
69 | 71 | | |
70 | 72 | | |
| |||
90 | 92 | | |
91 | 93 | | |
92 | 94 | | |
93 | | - | |
| 95 | + | |
94 | 96 | | |
95 | 97 | | |
96 | 98 | | |
| |||
99 | 101 | | |
100 | 102 | | |
101 | 103 | | |
102 | | - | |
| 104 | + | |
103 | 105 | | |
104 | 106 | | |
105 | 107 | | |
| |||
177 | 179 | | |
178 | 180 | | |
179 | 181 | | |
180 | | - | |
181 | | - | |
182 | | - | |
183 | | - | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
184 | 185 | | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | 186 | | |
189 | | - | |
190 | | - | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
191 | 191 | | |
192 | 192 | | |
193 | | - | |
| 193 | + | |
194 | 194 | | |
195 | | - | |
| 195 | + | |
196 | 196 | | |
197 | | - | |
198 | | - | |
199 | 197 | | |
200 | | - | |
| 198 | + | |
| 199 | + | |
201 | 200 | | |
202 | 201 | | |
203 | 202 | | |
0 commit comments