-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Compress masked_content in aux inputs
Showing
4 changed files
with
59 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
const compressVector = (vector, targetNumber) => { | ||
let otherNumbers = []; | ||
let targetNumberIndices = []; | ||
let inRun = false; | ||
let startIdx = 0; | ||
let targetCount = 0; | ||
|
||
for (let i = 0; i < vector.length; i++) { | ||
if (vector[i] === targetNumber) { | ||
if (!inRun) { | ||
inRun = true; | ||
startIdx = i; | ||
} | ||
targetCount++; | ||
} else { | ||
if (inRun) { | ||
inRun = false; | ||
targetNumberIndices.push([startIdx, i - 1]); | ||
} | ||
otherNumbers.push(vector[i]); | ||
} | ||
} | ||
|
||
if (inRun) { | ||
targetNumberIndices.push([startIdx, vector.length - 1]); | ||
} | ||
|
||
return [ | ||
otherNumbers, | ||
targetNumberIndices | ||
]; | ||
}; | ||
|
||
const decompressVector = (compressedVector, targetNumber) => { | ||
let decompressedVector = [...compressedVector[0]]; | ||
let offset = 0; | ||
for (let i = 0; i < compressedVector[1].length; i++) { | ||
let start = compressedVector[1][i][0] + offset; | ||
let end = compressedVector[1][i][1] + offset; | ||
let length = end - start + 1; | ||
decompressedVector.splice(start, 0, ...Array(length).fill(targetNumber)); | ||
start += length; | ||
offset += end - start + 1; | ||
} | ||
return decompressedVector; | ||
}; | ||
|
||
module.exports = { | ||
compressVector: compressVector, | ||
decompressVector: decompressVector | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters