function intersect_union(arrays, mandatory, resolve) {
    const check = create_object(),
          result = [];
    /** @type {SearchResults|IntermediateSearchResults} */

    for (let x = 0, ids; x < mandatory.length; x++) {
        ids = mandatory[x];
        for (let i = 0; i < ids.length; i++) {
            check[ids[i]] = 1;
        }
    }

    if (resolve) {
        for (let i = 0, id; i < arrays.length; i++) {
            id = arrays[i];
            if (check[id]) {
                result.push(id);
                check[id] = 0;
            }
        }
    } else {
        for (let i = 0, ids, id; i < arrays.result.length; i++) {
            ids = arrays.result[i];
            for (let j = 0; j < ids.length; j++) {
                id = ids[j];
                if (check[id]) {
                    const arr = result[i] || (result[i] = []);
                    arr.push(id);
                    check[id] = 0;
                }
            }
        }
    }

    return result;
}
@param {SearchResults|IntermediateSearchResults|Resolver} arrays
@param {Array<SearchResults>} mandatory
@param {boolean=} resolve
@returns {SearchResults}