Move set functions into core.js
This commit is contained in:
parent
2c4983da46
commit
a339bf69d3
@ -87,6 +87,8 @@
|
|||||||
"stringReverse": "readonly",
|
"stringReverse": "readonly",
|
||||||
"promiseTimeout": "readonly",
|
"promiseTimeout": "readonly",
|
||||||
"parseUrl": "readonly",
|
"parseUrl": "readonly",
|
||||||
|
"areSetsEqual": "readonly",
|
||||||
|
"getSetIntersection": "readonly",
|
||||||
"EventDispatcher": "readonly",
|
"EventDispatcher": "readonly",
|
||||||
"EventListenerCollection": "readonly",
|
"EventListenerCollection": "readonly",
|
||||||
"EXTENSION_IS_BROWSER_EDGE": "readonly"
|
"EXTENSION_IS_BROWSER_EDGE": "readonly"
|
||||||
|
@ -137,30 +137,6 @@ function dictTermsGroup(definitions, dictionaries) {
|
|||||||
return dictTermsSort(results);
|
return dictTermsSort(results);
|
||||||
}
|
}
|
||||||
|
|
||||||
function dictAreSetsEqual(set1, set2) {
|
|
||||||
if (set1.size !== set2.size) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const value of set1) {
|
|
||||||
if (!set2.has(value)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
function dictGetSetIntersection(set1, set2) {
|
|
||||||
const result = [];
|
|
||||||
for (const value of set1) {
|
|
||||||
if (set2.has(value)) {
|
|
||||||
result.push(value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
function dictTermsMergeBySequence(definitions, mainDictionary) {
|
function dictTermsMergeBySequence(definitions, mainDictionary) {
|
||||||
const sequencedDefinitions = new Map();
|
const sequencedDefinitions = new Map();
|
||||||
const nonSequencedDefinitions = [];
|
const nonSequencedDefinitions = [];
|
||||||
@ -281,11 +257,11 @@ function dictTermsMergeByGloss(result, definitions, appendTo=null, mergedIndices
|
|||||||
const only = [];
|
const only = [];
|
||||||
const expressionSet = definition.expression;
|
const expressionSet = definition.expression;
|
||||||
const readingSet = definition.reading;
|
const readingSet = definition.reading;
|
||||||
if (!dictAreSetsEqual(expressionSet, resultExpressionSet)) {
|
if (!areSetsEqual(expressionSet, resultExpressionSet)) {
|
||||||
only.push(...dictGetSetIntersection(expressionSet, resultExpressionSet));
|
only.push(...getSetIntersection(expressionSet, resultExpressionSet));
|
||||||
}
|
}
|
||||||
if (!dictAreSetsEqual(readingSet, resultReadingSet)) {
|
if (!areSetsEqual(readingSet, resultReadingSet)) {
|
||||||
only.push(...dictGetSetIntersection(readingSet, resultReadingSet));
|
only.push(...getSetIntersection(readingSet, resultReadingSet));
|
||||||
}
|
}
|
||||||
definition.only = only;
|
definition.only = only;
|
||||||
}
|
}
|
||||||
|
@ -132,6 +132,30 @@ function parseUrl(url) {
|
|||||||
return {baseUrl, queryParams};
|
return {baseUrl, queryParams};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function areSetsEqual(set1, set2) {
|
||||||
|
if (set1.size !== set2.size) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const value of set1) {
|
||||||
|
if (!set2.has(value)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getSetIntersection(set1, set2) {
|
||||||
|
const result = [];
|
||||||
|
for (const value of set1) {
|
||||||
|
if (set2.has(value)) {
|
||||||
|
result.push(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Async utilities
|
* Async utilities
|
||||||
|
Loading…
Reference in New Issue
Block a user