{"ScriptPreparationCode":"var SparseSet1 = (input) =\u003E {\r\n const dense = input !== undefined ? new Array(input.length) : [];\r\n const sparse = [];\r\n\r\n const has = (value) =\u003E {\r\n return dense[sparse[value]] === value;\r\n };\r\n\r\n const add = (value) =\u003E {\r\n if (has(value)) return false;\r\n\r\n sparse[value] = dense.push(value) - 1;\r\n\r\n return true;\r\n };\r\n\r\n const remove = (value) =\u003E {\r\n if (!has(value)) return;\r\n\r\n const index = sparse[value];\r\n const swapped = dense.pop();\r\n if (swapped !== value) {\r\n dense[index] = swapped;\r\n sparse[swapped] = index;\r\n }\r\n };\r\n\r\n if (input !== undefined) {\r\n for (let i = 0; i \u003C input.length; i\u002B\u002B) {\r\n dense[i] = input[i];\r\n sparse[input[i]] = i;\r\n }\r\n }\r\n\r\n return {\r\n dense,\r\n sparse,\r\n has,\r\n add,\r\n remove,\r\n };\r\n};\r\n\r\nclass SparseSet {\r\n constructor(input) {\r\n this.dense = input !== undefined ? new Array(input.length) : [];\r\n this.sparse = [];\r\n\r\n if (input !== undefined) {\r\n for (let i = 0; i \u003C input.length; i\u002B\u002B) {\r\n this.dense[i] = input[i];\r\n this.sparse[input[i]] = i;\r\n }\r\n }\r\n }\r\n\r\n has(value) {\r\n return this.dense[this.sparse[value]] === value;\r\n };\r\n\r\n add(value) {\r\n if (this.has(value)) return false;\r\n\r\n this.sparse[value] = this.dense.push(value) - 1;\r\n\r\n return true;\r\n };\r\n\r\n remove(value) {\r\n if (!this.has(value)) return;\r\n\r\n const index = this.sparse[value];\r\n const swapped = this.dense.pop();\r\n if (swapped !== value) {\r\n this.dense[index] = swapped;\r\n this.sparse[swapped] = index;\r\n }\r\n };\r\n};\r\nvar SparseSet2 = SparseSet;","TestCases":[{"Name":"Object literal","Code":"var set = SparseSet1([64, 11, 97, 1, 24, 25, 67, 100, 120, 130, 1001, 8, 2163]);\r\nfor(let i = 1000; i \u003C 1100; i\u002B\u002B) {\r\n set.add(i);\r\n}\r\nfor(let i = 0; i \u003C 100; i\u002B\u002B) {\r\n set.remove(i);\r\n}","IsDeferred":false},{"Name":"Class","Code":"var set = new SparseSet2([64, 11, 97, 1, 24, 25, 67, 100, 120, 130, 1001, 8, 2163]);\r\nfor(let i = 1000; i \u003C 1100; i\u002B\u002B) {\r\n set.add(i);\r\n}\r\nfor(let i = 0; i \u003C 100; i\u002B\u002B) {\r\n set.remove(i);\r\n}","IsDeferred":false}]}