import * as wasm from './wasm_tree_backend_bg.wasm';

const lTextDecoder = typeof TextDecoder === 'undefined' ? (0, module.require)('util').TextDecoder : TextDecoder;

let cachedTextDecoder = new lTextDecoder('utf-8', { ignoreBOM: true, fatal: true });

cachedTextDecoder.decode();

let cachegetUint8Memory0 = null;
function getUint8Memory0() {
    if (cachegetUint8Memory0 === null || cachegetUint8Memory0.buffer !== wasm.memory.buffer) {
        cachegetUint8Memory0 = new Uint8Array(wasm.memory.buffer);
    }
    return cachegetUint8Memory0;
}

function getStringFromWasm0(ptr, len) {
    return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
}

function isLikeNone(x) {
    return x === undefined || x === null;
}

let cachegetInt32Memory0 = null;
function getInt32Memory0() {
    if (cachegetInt32Memory0 === null || cachegetInt32Memory0.buffer !== wasm.memory.buffer) {
        cachegetInt32Memory0 = new Int32Array(wasm.memory.buffer);
    }
    return cachegetInt32Memory0;
}

let cachegetUint32Memory0 = null;
function getUint32Memory0() {
    if (cachegetUint32Memory0 === null || cachegetUint32Memory0.buffer !== wasm.memory.buffer) {
        cachegetUint32Memory0 = new Uint32Array(wasm.memory.buffer);
    }
    return cachegetUint32Memory0;
}

function getArrayU32FromWasm0(ptr, len) {
    return getUint32Memory0().subarray(ptr / 4, ptr / 4 + len);
}

let WASM_VECTOR_LEN = 0;

function passArray32ToWasm0(arg, malloc) {
    const ptr = malloc(arg.length * 4);
    getUint32Memory0().set(arg, ptr / 4);
    WASM_VECTOR_LEN = arg.length;
    return ptr;
}

function _assertClass(instance, klass) {
    if (!(instance instanceof klass)) {
        throw new Error(`expected instance of ${klass.name}`);
    }
    return instance.ptr;
}
/**
* wasm_bindgen annoted adapter of IndexingForest4 intended for wasm-tree-frontend
*/
export class ForestOfIdentifierQuads {

    static __wrap(ptr) {
        const obj = Object.create(ForestOfIdentifierQuads.prototype);
        obj.ptr = ptr;

        return obj;
    }

    free() {
        const ptr = this.ptr;
        this.ptr = 0;

        wasm.__wbg_forestofidentifierquads_free(ptr);
    }
    /**
    * Builds an empty Quad Forest with a OGPS tree and optionals SPOG, GPSO,
    * POGS, GSPO and OSGP trees that will be built when a match request is
    * received for them.
    */
    constructor() {
        var ret = wasm.forestofidentifierquads_new();
        return ForestOfIdentifierQuads.__wrap(ret);
    }
    /**
    * Returns the number of quads
    * @returns {number}
    */
    size() {
        var ret = wasm.forestofidentifierquads_size(this.ptr);
        return ret >>> 0;
    }
    /**
    * Adds the given quad
    * @param {number} s
    * @param {number} p
    * @param {number} o
    * @param {number} g
    */
    add(s, p, o, g) {
        wasm.forestofidentifierquads_add(this.ptr, s, p, o, g);
    }
    /**
    * Removes the given quad
    * @param {number} s
    * @param {number} p
    * @param {number} o
    * @param {number} g
    */
    remove(s, p, o, g) {
        wasm.forestofidentifierquads_remove(this.ptr, s, p, o, g);
    }
    /**
    * Returns true if the tree has the specified quad
    * @param {number} s
    * @param {number} p
    * @param {number} o
    * @param {number} g
    * @returns {boolean}
    */
    has(s, p, o, g) {
        var ret = wasm.forestofidentifierquads_has(this.ptr, s, p, o, g);
        return ret !== 0;
    }
    /**
    * Returns a slice with every quad flattened
    * @param {number | undefined} s
    * @param {number | undefined} p
    * @param {number | undefined} o
    * @param {number | undefined} g
    * @returns {Uint32Array}
    */
    get_all(s, p, o, g) {
        wasm.forestofidentifierquads_get_all(8, this.ptr, !isLikeNone(s), isLikeNone(s) ? 0 : s, !isLikeNone(p), isLikeNone(p) ? 0 : p, !isLikeNone(o), isLikeNone(o) ? 0 : o, !isLikeNone(g), isLikeNone(g) ? 0 : g);
        var r0 = getInt32Memory0()[8 / 4 + 0];
        var r1 = getInt32Memory0()[8 / 4 + 1];
        var v0 = getArrayU32FromWasm0(r0, r1).slice();
        wasm.__wbindgen_free(r0, r1 * 4);
        return v0;
    }
    /**
    * Builds a new dataset which is built by filtering with the given s, p, o and g.
    * @param {number | undefined} s
    * @param {number | undefined} p
    * @param {number | undefined} o
    * @param {number | undefined} g
    * @returns {ForestOfIdentifierQuads}
    */
    new_from(s, p, o, g) {
        var ret = wasm.forestofidentifierquads_new_from(this.ptr, !isLikeNone(s), isLikeNone(s) ? 0 : s, !isLikeNone(p), isLikeNone(p) ? 0 : p, !isLikeNone(o), isLikeNone(o) ? 0 : o, !isLikeNone(g), isLikeNone(g) ? 0 : g);
        return ForestOfIdentifierQuads.__wrap(ret);
    }
    /**
    * Insert every quads described in the passed identifier list.
    *
    * the identifier list is a multiple of 4 size array in which every
    * integer can be grouped in groups of 4 to get the identifier of
    * the subjet, the predicate, the object and the graph of each quad.
    * @param {Uint32Array} encoded_quads
    */
    insertFromIdentifierList(encoded_quads) {
        var ptr0 = passArray32ToWasm0(encoded_quads, wasm.__wbindgen_malloc);
        var len0 = WASM_VECTOR_LEN;
        wasm.forestofidentifierquads_insertFromIdentifierList(this.ptr, ptr0, len0);
    }
    /**
    * Builds a ForestOfIdentifierQuads from an identifier list of quads
    *
    * If you have previously extracted an identifier list from get_all, you
    * can easily build a new dataset with this function.
    * @param {Uint32Array} encoded_quads
    * @returns {ForestOfIdentifierQuads}
    */
    static fromIdentifierList(encoded_quads) {
        var ptr0 = passArray32ToWasm0(encoded_quads, wasm.__wbindgen_malloc);
        var len0 = WASM_VECTOR_LEN;
        var ret = wasm.forestofidentifierquads_fromIdentifierList(ptr0, len0);
        return ForestOfIdentifierQuads.__wrap(ret);
    }
    /**
    * Removes from the dataset the quads that matches the given pattern
    * @param {number | undefined} s
    * @param {number | undefined} p
    * @param {number | undefined} o
    * @param {number | undefined} g
    */
    deleteMatches(s, p, o, g) {
        wasm.forestofidentifierquads_deleteMatches(this.ptr, !isLikeNone(s), isLikeNone(s) ? 0 : s, !isLikeNone(p), isLikeNone(p) ? 0 : p, !isLikeNone(o), isLikeNone(o) ? 0 : o, !isLikeNone(g), isLikeNone(g) ? 0 : g);
    }
    /**
    * @param {ForestOfIdentifierQuads} other
    * @returns {ForestOfIdentifierQuads}
    */
    insersect(other) {
        _assertClass(other, ForestOfIdentifierQuads);
        var ret = wasm.forestofidentifierquads_insersect(this.ptr, other.ptr);
        return ForestOfIdentifierQuads.__wrap(ret);
    }
    /**
    * @param {Uint32Array} other
    * @returns {ForestOfIdentifierQuads}
    */
    intersectIdentifierList(other) {
        var ptr0 = passArray32ToWasm0(other, wasm.__wbindgen_malloc);
        var len0 = WASM_VECTOR_LEN;
        var ret = wasm.forestofidentifierquads_intersectIdentifierList(this.ptr, ptr0, len0);
        return ForestOfIdentifierQuads.__wrap(ret);
    }
    /**
    * @param {Uint32Array} other
    * @returns {ForestOfIdentifierQuads}
    */
    unionIdentifierList(other) {
        var ptr0 = passArray32ToWasm0(other, wasm.__wbindgen_malloc);
        var len0 = WASM_VECTOR_LEN;
        var ret = wasm.forestofidentifierquads_unionIdentifierList(this.ptr, ptr0, len0);
        return ForestOfIdentifierQuads.__wrap(ret);
    }
    /**
    * @param {Uint32Array} other
    * @returns {ForestOfIdentifierQuads}
    */
    differenceIdentifierList(other) {
        var ptr0 = passArray32ToWasm0(other, wasm.__wbindgen_malloc);
        var len0 = WASM_VECTOR_LEN;
        var ret = wasm.forestofidentifierquads_differenceIdentifierList(this.ptr, ptr0, len0);
        return ForestOfIdentifierQuads.__wrap(ret);
    }
    /**
    * @param {ForestOfIdentifierQuads} other
    * @returns {ForestOfIdentifierQuads}
    */
    union(other) {
        _assertClass(other, ForestOfIdentifierQuads);
        var ret = wasm.forestofidentifierquads_union(this.ptr, other.ptr);
        return ForestOfIdentifierQuads.__wrap(ret);
    }
    /**
    * @param {ForestOfIdentifierQuads} other
    * @returns {ForestOfIdentifierQuads}
    */
    difference(other) {
        _assertClass(other, ForestOfIdentifierQuads);
        var ret = wasm.forestofidentifierquads_difference(this.ptr, other.ptr);
        return ForestOfIdentifierQuads.__wrap(ret);
    }
    /**
    * @param {ForestOfIdentifierQuads} other
    * @returns {boolean}
    */
    contains(other) {
        _assertClass(other, ForestOfIdentifierQuads);
        var ret = wasm.forestofidentifierquads_contains(this.ptr, other.ptr);
        return ret !== 0;
    }
    /**
    * @param {Uint32Array} other
    * @returns {boolean}
    */
    containsIdentifierList(other) {
        var ptr0 = passArray32ToWasm0(other, wasm.__wbindgen_malloc);
        var len0 = WASM_VECTOR_LEN;
        var ret = wasm.forestofidentifierquads_containsIdentifierList(this.ptr, ptr0, len0);
        return ret !== 0;
    }
    /**
    * @param {Uint32Array} other
    * @returns {boolean}
    */
    equalsIdentifierList(other) {
        var ptr0 = passArray32ToWasm0(other, wasm.__wbindgen_malloc);
        var len0 = WASM_VECTOR_LEN;
        var ret = wasm.forestofidentifierquads_equalsIdentifierList(this.ptr, ptr0, len0);
        return ret !== 0;
    }
    /**
    * @param {ForestOfIdentifierQuads} other
    * @returns {boolean}
    */
    has_same_elements(other) {
        _assertClass(other, ForestOfIdentifierQuads);
        var ret = wasm.forestofidentifierquads_has_same_elements(this.ptr, other.ptr);
        return ret !== 0;
    }
    /**
    * Counts the number of quads that matches the given pattern
    * @param {number | undefined} s
    * @param {number | undefined} p
    * @param {number | undefined} o
    * @param {number | undefined} g
    * @returns {number}
    */
    matchCount(s, p, o, g) {
        var ret = wasm.forestofidentifierquads_matchCount(this.ptr, !isLikeNone(s), isLikeNone(s) ? 0 : s, !isLikeNone(p), isLikeNone(p) ? 0 : p, !isLikeNone(o), isLikeNone(o) ? 0 : o, !isLikeNone(g), isLikeNone(g) ? 0 : g);
        return ret >>> 0;
    }
    /**
    * Ensures the best tree to search quads matching the given pattern is built
    * @param {boolean} s
    * @param {boolean} p
    * @param {boolean} o
    * @param {boolean} g
    */
    ensureHasIndexfor(s, p, o, g) {
        wasm.forestofidentifierquads_ensureHasIndexfor(this.ptr, s, p, o, g);
    }
    /**
    * Counts the number of living trees
    * @returns {number}
    */
    getNumberOfLivingTrees() {
        var ret = wasm.forestofidentifierquads_getNumberOfLivingTrees(this.ptr);
        return ret >>> 0;
    }
}

export const __wbindgen_throw = function(arg0, arg1) {
    throw new Error(getStringFromWasm0(arg0, arg1));
};

