agsamantha/node_modules/langchain/dist/util/set.js

36 lines
814 B
JavaScript
Raw Normal View History

2024-10-02 15:15:21 -05:00
/**
* Source: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set#implementing_basic_set_operations
*/
/**
* returns intersection of two sets
*/
export function intersection(setA, setB) {
const _intersection = new Set();
for (const elem of setB) {
if (setA.has(elem)) {
_intersection.add(elem);
}
}
return _intersection;
}
/**
* returns union of two sets
*/
export function union(setA, setB) {
const _union = new Set(setA);
for (const elem of setB) {
_union.add(elem);
}
return _union;
}
/**
* returns difference of two sets
*/
export function difference(setA, setB) {
const _difference = new Set(setA);
for (const elem of setB) {
_difference.delete(elem);
}
return _difference;
}