| 165 | } |
| 166 | |
| 167 | class KeySetImpl<in out K> implements KeySet<K> { |
| 168 | head: MapKey<K> | undefined = undefined |
| 169 | tail: MapKey<K> | undefined = undefined |
| 170 | add(key: MapKey<K>): void { |
| 171 | if (key !== this.tail) { |
| 172 | if (this.tail === undefined) { |
| 173 | this.head = key |
| 174 | this.tail = key |
| 175 | } else { |
| 176 | const previous = key.previous |
| 177 | const next = key.next |
| 178 | if (next !== undefined) { |
| 179 | key.next = undefined |
| 180 | if (previous !== undefined) { |
| 181 | previous.next = next |
| 182 | next.previous = previous |
| 183 | } else { |
| 184 | this.head = next |
| 185 | this.head.previous = undefined |
| 186 | } |
| 187 | } |
| 188 | this.tail.next = key |
| 189 | key.previous = this.tail |
| 190 | this.tail = key |
| 191 | } |
| 192 | } |
| 193 | } |
| 194 | remove(): MapKey<K> | undefined { |
| 195 | const key = this.head |
| 196 | if (key !== undefined) { |
| 197 | const next = key.next |
| 198 | if (next !== undefined) { |
| 199 | key.next = undefined |
| 200 | this.head = next |
| 201 | this.head.previous = undefined |
| 202 | } else { |
| 203 | this.head = undefined |
| 204 | this.tail = undefined |
| 205 | } |
| 206 | } |
| 207 | return key |
| 208 | } |
| 209 | } |
| 210 | |
| 211 | /** @internal */ |
| 212 | export const makeKeySet = <K>(): KeySet<K> => new KeySetImpl<K>() |
nothing calls this directly
no outgoing calls
no test coverage detected