finalizeGraph() {
        let offset = 0;
        // delete all nodes that are not being executed
        for (let i = 0; i < this._nodes.length; i++) {
            if (!this._nodes[i].executeNode) {
                // delete this node and shift all subsequent nodes up
                offset++;
                // delete all output values
                this._nodes[i].outputs.forEach(ind => {
                    this._allData[ind]._from = -2;
                });
                this._nodes.splice(i, 1);
                i--;
                continue;
            }
            if (offset > 0) {
                // update the value table
                this._nodes[i].inputs.forEach(value => {
                    const ind = this._allData[value]._to.indexOf(i + offset);
                    if (ind !== -1) {
                        this._allData[value]._to[ind] = i;
                    }
                });
                this._nodes[i].outputs.forEach(value => {
                    if (this._allData[value]._from && this._allData[value]._from === i + offset) {
                        this._allData[value]._from = i;
                    }
                });
            }
        }
        offset = 0;
        // delete all values that are not being referenced
        for (let i = 0; i < this._allData.length; i++) {
            // if current value is neither linked to next node, nor an output value, remove it.
            if (this._allData[i].from === -2 && this._allOutputIndices.indexOf(i + offset) === -1) {
                offset++;
                this._allData.splice(i, 1);
                i--;
                continue;
            }
            if (offset > 0) {
                let ind = -1;
                // if current value is neither an input value nor an initializer, find the node it's
                // coming from and update the corresponding node output
                if (this._allData[i].from !== undefined && this._allData[i].from !== -1) {
                    ind = this._nodes[this._allData[i].from].outputs.indexOf(i + offset);
                    if (ind !== -1) {
                        this._nodes[this._allData[i].from].outputs[ind] = i;
                    }
                }
                else {
                    // if current value is an input value, update its reference in inputIndices
                    ind = this._allInputIndices.indexOf(i + offset);
                    if (ind !== -1) {
                        this._allInputIndices[ind] = i;
                    }
                }
                // find the node that the current value is linking to and update its input reference
                this._allData[i].to.forEach(node => {
                    ind = this._nodes[node].inputs.indexOf(i + offset);
                    if (ind !== -1) {
                        this._nodes[node].inputs[ind] = i;
                    }
                });
                if (this._allData[i].to.length === 0) {
                    // if current value is a graph output, update its reference in outputIndices
                    ind = this._allOutputIndices.indexOf(i + offset);
                    if (ind !== -1) {
                        this._allOutputIndices[ind] = i;
                    }
                }
            }
        }
    }
/**
     * finalize the graph.
     *
     * this function should be called after all the transformation completed.
     * this function removes all unnecessary nodes and values from the graph
     */
finalize the graph.
this function should be called after all the transformation completed.
this function removes all unnecessary nodes and values from the graph
finalize the graph . this function should be called after all the transformation completed . this function removes all unnecessary nodes and values from the graph
finalizeGraph() {
        let offset = 0;
        for (let i = 0; i < this._nodes.length; i++) {
            if (!this._nodes[i].executeNode) {
                offset++;
                this._nodes[i].outputs.forEach(ind => {
                    this._allData[ind]._from = -2;
                });
                this._nodes.splice(i, 1);
                i--;
                continue;
            }
            if (offset > 0) {
                this._nodes[i].inputs.forEach(value => {
                    const ind = this._allData[value]._to.indexOf(i + offset);
                    if (ind !== -1) {
                        this._allData[value]._to[ind] = i;
                    }
                });
                this._nodes[i].outputs.forEach(value => {
                    if (this._allData[value]._from && this._allData[value]._from === i + offset) {
                        this._allData[value]._from = i;
                    }
                });
            }
        }
        offset = 0;
        for (let i = 0; i < this._allData.length; i++) {
            if (this._allData[i].from === -2 && this._allOutputIndices.indexOf(i + offset) === -1) {
                offset++;
                this._allData.splice(i, 1);
                i--;
                continue;
            }
            if (offset > 0) {
                let ind = -1;
                if (this._allData[i].from !== undefined && this._allData[i].from !== -1) {
                    ind = this._nodes[this._allData[i].from].outputs.indexOf(i + offset);
                    if (ind !== -1) {
                        this._nodes[this._allData[i].from].outputs[ind] = i;
                    }
                }
                else {
                    ind = this._allInputIndices.indexOf(i + offset);
                    if (ind !== -1) {
                        this._allInputIndices[ind] = i;
                    }
                }
                this._allData[i].to.forEach(node => {
                    ind = this._nodes[node].inputs.indexOf(i + offset);
                    if (ind !== -1) {
                        this._nodes[node].inputs[ind] = i;
                    }
                });
                if (this._allData[i].to.length === 0) {
                    ind = this._allOutputIndices.indexOf(i + offset);
                    if (ind !== -1) {
                        this._allOutputIndices[ind] = i;
                    }
                }
            }
        }
    }
finalizeGraph ( ) { let offset = 0 ; for ( let i = 0 ; i < this . _nodes . length ; i ++ ) { if ( ! this . _nodes [ i ] . executeNode ) { offset ++ ; this . _nodes [ i ] . outputs . forEach ( ind => { this . _allData [ ind ] . _from = - 2 ; } ) ; this . _nodes . splice ( i , 1 ) ; i -- ; continue ; } if ( offset > 0 ) { this . _nodes [ i ] . inputs . forEach ( value => { const ind = this . _allData [ value ] . _to . indexOf ( i + offset ) ; if ( ind !== - 1 ) { this . _allData [ value ] . _to [ ind ] = i ; } } ) ; this . _nodes [ i ] . outputs . forEach ( value => { if ( this . _allData [ value ] . _from && this . _allData [ value ] . _from === i + offset ) { this . _allData [ value ] . _from = i ; } } ) ; } } offset = 0 ; for ( let i = 0 ; i < this . _allData . length ; i ++ ) { if ( this . _allData [ i ] . from === - 2 && this . _allOutputIndices . indexOf ( i + offset ) === - 1 ) { offset ++ ; this . _allData . splice ( i , 1 ) ; i -- ; continue ; } if ( offset > 0 ) { let ind = - 1 ; if ( this . _allData [ i ] . from !== undefined && this . _allData [ i ] . from !== - 1 ) { ind = this . _nodes [ this . _allData [ i ] . from ] . outputs . indexOf ( i + offset ) ; if ( ind !== - 1 ) { this . _nodes [ this . _allData [ i ] . from ] . outputs [ ind ] = i ; } } else { ind = this . _allInputIndices . indexOf ( i + offset ) ; if ( ind !== - 1 ) { this . _allInputIndices [ ind ] = i ; } } this . _allData [ i ] . to . forEach ( node => { ind = this . _nodes [ node ] . inputs . indexOf ( i + offset ) ; if ( ind !== - 1 ) { this . _nodes [ node ] . inputs [ ind ] = i ; } } ) ; if ( this . _allData [ i ] . to . length === 0 ) { ind = this . _allOutputIndices . indexOf ( i + offset ) ; if ( ind !== - 1 ) { this . _allOutputIndices [ ind ] = i ; } } } } }
finalize the graph.
finalize the graph .
// delete all nodes that are not being executed // delete this node and shift all subsequent nodes up // delete all output values // update the value table // delete all values that are not being referenced // if current value is neither linked to next node, nor an output value, remove it. // if current value is neither an input value nor an initializer, find the node it's // coming from and update the corresponding node output // if current value is an input value, update its reference in inputIndices // find the node that the current value is linking to and update its input reference // if current value is a graph output, update its reference in outputIndices