{"ScriptPreparationCode":"function generateRandomBitmasks(count = 100) {\r\n const bitmasks = new Array(count);\r\n for (let i = 0; i \u003C count; i\u002B\u002B) {\r\n let bitLength = Math.floor(Math.random() * (32 - 5 \u002B 1)) \u002B 5;\r\n bitmasks[i] = Math.floor(Math.random() * (1 \u003C\u003C bitLength));\r\n }\r\n return bitmasks;\r\n}\r\n\r\nvar bitmasks = generateRandomBitmasks();\r\nvar packed = packBitmasks(bitmasks);\r\nvar packedV8 = packBitmasksV8(bitmasks);\r\n\r\nfunction packBitmasks(bitmasks) {\r\n let totalBits = bitmasks.length * 32;\r\n let packedSize = Math.ceil(totalBits / 8);\r\n let packed = new Uint8Array(packedSize);\r\n \r\n let bitIndex = 0;\r\n\r\n for (let i = 0; i \u003C bitmasks.length; i\u002B\u002B) {\r\n let value = bitmasks[i];\r\n\r\n for (let b = 0; b \u003C 32; b\u002B\u002B) {\r\n if (bitIndex \u003E= totalBits) break;\r\n let bytePos = bitIndex \u003E\u003E 3;\r\n let bitPos = bitIndex % 8;\r\n if (value \u0026 (1 \u003C\u003C b)) {\r\n packed[bytePos] |= (1 \u003C\u003C bitPos);\r\n }\r\n bitIndex\u002B\u002B;\r\n }\r\n }\r\n\r\n return packed;\r\n}\r\n\r\nfunction unpackBitmasks(packed, length) {\r\n let bitmasks = new Uint32Array(length);\r\n let bitIndex = 0;\r\n\r\n for (let i = 0; i \u003C length; i\u002B\u002B) {\r\n let value = 0;\r\n for (let b = 0; b \u003C 32; b\u002B\u002B) {\r\n if (bitIndex \u003E= packed.length * 8) break;\r\n let bytePos = bitIndex \u003E\u003E 3;\r\n let bitPos = bitIndex % 8;\r\n if (packed[bytePos] \u0026 (1 \u003C\u003C bitPos)) {\r\n value |= (1 \u003C\u003C b);\r\n }\r\n bitIndex\u002B\u002B;\r\n }\r\n bitmasks[i] = value;\r\n }\r\n\r\n return bitmasks;\r\n}\r\n\r\nfunction packBitmasksV8(bitmasks) {\r\n let packed = new Uint8Array(bitmasks.length * 4);\r\n let packedView = new Uint32Array(packed.buffer);\r\n\r\n for (let i = 0, len = bitmasks.length; i \u003C len; i\u002B\u002B) {\r\n packedView[i] = bitmasks[i];\r\n }\r\n\r\n return packed;\r\n}\r\n\r\nfunction unpackBitmasksV8(packed) {\r\n let packedView = new Uint32Array(packed.buffer);\r\n let bitmasks = new Array(packedView.length);\r\n\r\n for (let i = 0, len = packedView.length; i \u003C len; i\u002B\u002B) {\r\n bitmasks[i] = packedView[i];\r\n }\r\n\r\n return bitmasks;\r\n}\r\n","TestCases":[{"Name":"Pack","Code":"packBitmasks(bitmasks)","IsDeferred":false},{"Name":"UnPack","Code":"unpackBitmasks(packed)","IsDeferred":false},{"Name":"Pack (Optimized)","Code":"packBitmasksV8(bitmasks)","IsDeferred":false},{"Name":"UnPack (Optimized)","Code":"unpackBitmasksV8(packedV8)","IsDeferred":false}]}