constructor()

in src/js/other-websites/fathom.js [849:881]


        constructor(elements, distance) {
            // A sparse adjacency matrix:
            // {A => {},
            //  B => {A => 4},
            //  C => {A => 4, B => 4},
            //  D => {A => 4, B => 4, C => 4}
            //  E => {A => 4, B => 4, C => 4, D => 4}}
            //
            // A, B, etc. are arrays of [arrays of arrays of...] nodes, each
            // array being a cluster. In this way, they not only accumulate a
            // cluster but retain the steps along the way.
            //
            // This is an efficient data structure in terms of CPU and memory, in
            // that we don't have to slide a lot of memory around when we delete a
            // row or column from the middle of the matrix while merging. Of
            // course, we lose some practical efficiency by using hash tables, and
            // maps in particular are slow in their early implementations.
            this._matrix = new Map();

            // Convert elements to clusters:
            const clusters = elements.map(el => [el]);

            // Init matrix:
            for (let outerCluster of clusters) {
                const innerMap = new Map();
                for (let innerCluster of this._matrix.keys()) {
                    innerMap.set(innerCluster, distance(outerCluster[0],
                                                        innerCluster[0]));
                }
                this._matrix.set(outerCluster, innerMap);
            }
            this._numClusters = clusters.length;
        }