aboutsummaryrefslogtreecommitdiffstats
path: root/lib/LiquidDict.jsm
diff options
context:
space:
mode:
authorJesús <heckyel@hyperbola.info>2019-12-30 16:10:54 -0500
committerJesús <heckyel@hyperbola.info>2019-12-30 16:10:54 -0500
commitd1d3aaa224ec068dc8d267e4d64255f88b6641a0 (patch)
tree9e6b679c529dca7217becc7856ea6aac2d3069f7 /lib/LiquidDict.jsm
parentfa6fb12f089ff0170d0f3ee93b6ce7131a6a2254 (diff)
downloadematrix-d1d3aaa224ec068dc8d267e4d64255f88b6641a0.tar.lz
ematrix-d1d3aaa224ec068dc8d267e4d64255f88b6641a0.tar.xz
ematrix-d1d3aaa224ec068dc8d267e4d64255f88b6641a0.zip
fix syntax libraries
Diffstat (limited to 'lib/LiquidDict.jsm')
-rw-r--r--lib/LiquidDict.jsm92
1 files changed, 46 insertions, 46 deletions
diff --git a/lib/LiquidDict.jsm b/lib/LiquidDict.jsm
index 65de9c5..a3b6c00 100644
--- a/lib/LiquidDict.jsm
+++ b/lib/LiquidDict.jsm
@@ -17,7 +17,7 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see {http://www.gnu.org/licenses/}.
- Home: https://gitlab.com/vannilla/ematrix
+ Home: https://libregit.org/heckyel/ematrix
uMatrix Home: https://github.com/gorhill/uMatrix
*/
@@ -40,13 +40,13 @@ function meltBucket(dict, len, bucket) {
--dict.frozenCount;
if (bucket.charAt(0) === ' ') {
- bucket.trim().split(' ').map(function (e) {
- map[e] = true;
- });
+ bucket.trim().split(' ').map(function (e) {
+ map[e] = true;
+ });
} else {
- for (let i=0; i<bucket.length; i+=len) {
- map[bucket.substring(i, len)] = true;
- }
+ for (let i=0; i<bucket.length; i+=len) {
+ map[bucket.substring(i, len)] = true;
+ }
}
return map;
@@ -55,10 +55,10 @@ function meltBucket(dict, len, bucket) {
function melt(dict) {
let buckets = dict.dict;
for (let key in buckets) {
- let bucket = buckets[key];
- if (typeof bucket === 'string') {
- buckets[key] = meltBucket(dict, key.charCodeAt(0) & 0xFF, bucket);
- }
+ let bucket = buckets[key];
+ if (typeof bucket === 'string') {
+ buckets[key] = meltBucket(dict, key.charCodeAt(0) & 0xFF, bucket);
+ }
}
}
@@ -69,7 +69,7 @@ function freezeBucket(dict, bucket) {
++dict.frozenCount;
if (wlen * words.length < dict.cutoff) {
- return ' ' + words.join(' ') + ' ';
+ return ' ' + words.join(' ') + ' ';
}
return words.sort().join('');
@@ -78,31 +78,31 @@ function freezeBucket(dict, bucket) {
LiquidDict.prototype.makeKey = function (word) {
let len = word.length;
if (len > 255) {
- len = 255;
+ len = 255;
}
let i = len >> 2;
return String.fromCharCode((word.charCodeAt(0) & 0x03) << 14
- | (word.charCodeAt(i) & 0x03) << 12
- | (word.charCodeAt(i+i) & 0x03) << 10
- | (word.charCodeAt(i+i+i) & 0x03) << 8
- | len);
+ | (word.charCodeAt(i) & 0x03) << 12
+ | (word.charCodeAt(i+i) & 0x03) << 10
+ | (word.charCodeAt(i+i+i) & 0x03) << 8
+ | len);
};
LiquidDict.prototype.test = function (word) {
let key = this.makeKey(word);
let bucket = this.dict[key];
-
+
if (bucket === undefined) {
- return false;
+ return false;
}
if (typeof bucket === 'object') {
- return bucket[word] !== undefined;
+ return bucket[word] !== undefined;
}
if (bucket.charAt(0) === ' ') {
- return bucket.indexOf(' ' + word + ' ') >= 0;
+ return bucket.indexOf(' ' + word + ' ') >= 0;
}
let len = word.length;
@@ -110,16 +110,16 @@ LiquidDict.prototype.test = function (word) {
let right = ~~(bucket.length / len + 0.5);
while (left < right) {
- let i = left + right >> 1;
- let needle = bucket.substr(len * i, len);
-
- if (word < needle) {
- right = i;
- } else if (word > needle) {
- left = i + 1;
- } else {
- return true;
- }
+ let i = left + right >> 1;
+ let needle = bucket.substr(len * i, len);
+
+ if (word < needle) {
+ right = i;
+ } else if (word > needle) {
+ left = i + 1;
+ } else {
+ return true;
+ }
}
return false;
@@ -128,26 +128,26 @@ LiquidDict.prototype.test = function (word) {
LiquidDict.prototype.add = function (word) {
let key = this.makeKey(word);
if (key === undefined) {
- return false;
+ return false;
}
let bucket = this.dict[key];
if (bucket === undefined) {
- this.dict[key] = bucket = {};
- ++this.bucketCount;
- bucket[word] = true;
- ++this.count;
-
- return true;
+ this.dict[key] = bucket = {};
+ ++this.bucketCount;
+ bucket[word] = true;
+ ++this.count;
+
+ return true;
} else if (typeof bucket === 'string') {
- this.dict[key] = bucket = meltBucket(this, word.len, bucket);
+ this.dict[key] = bucket = meltBucket(this, word.len, bucket);
}
if (bucket[word] === undefined) {
- bucket[word] = true;
- ++this.count;
+ bucket[word] = true;
+ ++this.count;
- return true;
+ return true;
}
++this.duplicateCount;
@@ -159,10 +159,10 @@ LiquidDict.prototype.freeze = function () {
let buckets = this.dict;
for (let key in buckets) {
- let bucket = buckets[key];
- if (typeof bucket === 'object') {
- buckets[key] = freezeBucket(this, bucket);
- }
+ let bucket = buckets[key];
+ if (typeof bucket === 'object') {
+ buckets[key] = freezeBucket(this, bucket);
+ }
}
};