| 134 | it('sort is stable', () => { |
| 135 | // Heap's algorithm for permutations |
| 136 | function* permutations<T>(input: T[]) { |
| 137 | let pos = 1 |
| 138 | let stack = input.map(() => 0) |
| 139 | |
| 140 | yield input.slice() |
| 141 | |
| 142 | while (pos < input.length) { |
| 143 | if (stack[pos] < pos) { |
| 144 | let k = pos % 2 == 0 ? 0 : stack[pos] |
| 145 | ;[input[k], input[pos]] = [input[pos], input[k]] |
| 146 | yield input.slice() |
| 147 | ++stack[pos] |
| 148 | pos = 1 |
| 149 | } else { |
| 150 | stack[pos] = 0 |
| 151 | ++pos |
| 152 | } |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | let classes = ['duration-initial', 'duration-75', 'duration-150', 'duration-700', 'duration-1000'] |
| 157 | |