-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cbfba3a
commit d7afe8d
Showing
5 changed files
with
59 additions
and
12 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,25 @@ | ||
// longest common prefix | ||
const findOverlap = (from, to) => { | ||
let all = [] | ||
for (let i = 0; i < from.length; i += 1) { | ||
if (from[i] === to[i]) { | ||
all.push(from[i]) | ||
} else { | ||
break | ||
} | ||
} | ||
return all.join('') | ||
} | ||
|
||
// run-length encode any shared prefix | ||
let compress = function (key, val) { | ||
let prefix = findOverlap(key, val) | ||
if (prefix.length < 1) { | ||
return val | ||
} | ||
let out = prefix.length + val.substr(prefix.length) | ||
return out | ||
} | ||
|
||
export default compress | ||
// console.log(compress('fixture', 'fixturing')) |
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 |
---|---|---|
@@ -1,18 +1,28 @@ | ||
import keyVal from './key-val.js' | ||
|
||
const pack = function (model) { | ||
let out = '' | ||
model.rules.forEach(obj => { | ||
let r = [] | ||
Object.keys(obj).forEach(k => { | ||
r.push(k + '|' + obj[k] + ',') | ||
let val = keyVal(k, obj[k])// compress any shared prefix | ||
if (!val) { | ||
console.log('=-=-=-= here -=-=-=-') | ||
console.log(k, obj[k]) | ||
} | ||
r.push(k + ':' + val + ',') | ||
}) | ||
out += r.join('') | ||
}) | ||
out += '==' | ||
let r = [] | ||
Object.keys(model.exceptions).forEach(k => { | ||
r.push(k + '|' + model.exceptions[k]) | ||
Object.keys(model.exceptions || {}).forEach(k => { | ||
let val = keyVal(k, model.exceptions[k])// compress any shared prefix | ||
r.push(k + ':' + val) | ||
}) | ||
out += r.join(',') | ||
return out | ||
} | ||
export default pack | ||
export default pack | ||
|
||
// rei:ere, erei:are, rrei:nere, arei:3, herei:are, lirei:4, nirei:4, tirei:4,== |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.