Use nested config structure
This commit is contained in:
1 parent
581a510960
commit
30dbf0cf40
15 files changed
+366
-251
No files matched your search
@@ -3,6 +3,7 @@
|
||||
const filterParser = require("./filter-parser");
|
||||
const filterCnf = require("./filter-cnf");
|
||||
const satSolver = require("./sat-solver");
|
||||
const funcCache = require("./func-cache");
|
||||
|
||||
function* permute(arr) {
|
||||
if (arr.length <= 1) {
|
||||
@@ -24,6 +25,10 @@ class Filter {
|
||||
else this.ast = filterParser.parse(str);
|
||||
}
|
||||
|
||||
static parse(str) {
|
||||
return new Filter(str);
|
||||
}
|
||||
|
||||
toString() {
|
||||
if (!this.string)
|
||||
if (this.ast) this.string = filterParser.stringify(this.ast);
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
"use strict";
|
||||
|
||||
let cache1 = new WeakMap();
|
||||
let cache2 = new WeakMap();
|
||||
|
||||
function get(func, k) {
|
||||
let c1 = cache1.get(func);
|
||||
if (!c1) cache1.set(func, (c1 = new Map()));
|
||||
if (c1.has(k)) return c1.get(k);
|
||||
const c2 = cache2.get(func);
|
||||
const v = c2 && c2.has(k) ? c2.get(k) : func(k);
|
||||
c1.set(k, v);
|
||||
return v;
|
||||
}
|
||||
|
||||
function getter(func) {
|
||||
return k => get(func, k);
|
||||
}
|
||||
|
||||
function purge() {
|
||||
cache2 = cache1;
|
||||
cache1 = new WeakMap();
|
||||
}
|
||||
|
||||
exports.get = get;
|
||||
exports.getter = getter;
|
||||
exports.purge = purge;
|
||||
Reference in new issue
Block a user