Skip to content
Snippets Groups Projects
Select Git revision
  • 0064293e0110bb532c3148319e42696fa6cb6d5e
  • master default protected
  • rednatco-v2
  • rednatco
  • test
  • ntc-tube-uniform-color
  • ntc-tube-missing-atoms
  • restore-vertex-array-per-program
  • watlas2
  • dnatco_new
  • cleanup-old-nodejs
  • webmmb
  • fix_auth_seq_id
  • update_deps
  • ext_dev
  • ntc_balls
  • nci-2
  • plugin
  • bugfix-0.4.5
  • nci
  • servers
  • v0.5.0-dev.1
  • v0.4.5
  • v0.4.4
  • v0.4.3
  • v0.4.2
  • v0.4.1
  • v0.4.0
  • v0.3.12
  • v0.3.11
  • v0.3.10
  • v0.3.9
  • v0.3.8
  • v0.3.7
  • v0.3.6
  • v0.3.5
  • v0.3.4
  • v0.3.3
  • v0.3.2
  • v0.3.1
  • v0.3.0
41 results

CITATION.cff

Blame
  • builder.ts 2.01 KiB
    /**
     * Copyright (c) 2017 molio contributors, licensed under MIT, See LICENSE file for more info.
     *
     * @author David Sehnal <david.sehnal@gmail.com>
     */
    
    import AtomSet from '../set'
    import { OrderedSet } from '../../../../mol-base/collections/integer'
    import { sortArray } from '../../../../mol-base/collections/sort'
    
    class Builder {
        private keys: number[] = [];
        private units: number[][] = Object.create(null);
        private currentUnit: number[] = [];
    
        add(u: number, a: number) {
            const unit = this.units[u];
            if (!!unit) { unit[unit.length] = a; }
            else {
                this.units[u] = [a];
                this.keys[this.keys.length] = u;
            }
        }
    
        beginUnit() { this.currentUnit = this.currentUnit.length > 0 ? [] : this.currentUnit; }
        addToUnit(a: number) { this.currentUnit[this.currentUnit.length] = a; }
        commitUnit(u: number) {
            if (this.currentUnit.length === 0) return;
            this.keys[this.keys.length] = u;
            this.units[u] = this.currentUnit;
        }
    
        getSet(): AtomSet {
            const sets: { [key: number]: OrderedSet } = Object.create(null);
    
            let allEqual = this.keys.length === AtomSet.unitCount(this.parent);
    
            for (let i = 0, _i = this.keys.length; i < _i; i++) {
                const k = this.keys[i];
                const unit = this.units[k];
                const l = unit.length;
                if (!this.sorted && l > 1) sortArray(unit);
    
                const set = l === 1 ? OrderedSet.ofSingleton(unit[0]) : OrderedSet.ofSortedArray(unit);
                const parentSet = AtomSet.unitGetById(this.parent, k);
                if (OrderedSet.areEqual(set, parentSet)) {
                    sets[k] = parentSet;
                } else {
                    sets[k] = set;
                    allEqual = false;
                }
            }
            return allEqual ? this.parent : AtomSet.create(sets);
        }
    
        constructor(private parent: AtomSet, private sorted: boolean) { }
    }
    
    export default function createBuilder(parent: AtomSet, sorted: boolean) {
        return new Builder(parent, sorted);
    }