private void setupLinks() {
        //
        // now acquire links.
        //
        final int rawlinksnum = this.links.size();
        int[] rawlinks = new int[rawlinksnum * Link.LINK_SIZE];
        int idx  = 0;
        //
        for (int i = 0; i < rawlinksnum; i++) {
            final int[] link = this.links.get(i);
            //
            final int src  = link[0];
            final int dst  = link[1];
            final int widx = link[2];
            //
            rawlinks[idx] = src;  idx++;
            rawlinks[idx] = dst;  idx++;
            rawlinks[idx] = widx; idx++;
        }
        //
        // sort raw links and eliminate redundant links.
        //
        Link.sortDstMaj(rawlinks, Link.ORDER_ASC);
        int[] links = Link.eliminateRedundantLinks(rawlinks);
        //
        if (links.length % Link.LINK_SIZE != 0) {
            throw new LinkArrayCorrupt();
        }
        //
        this.structure.links = links;
        final int linksnum = links.length / Link.LINK_SIZE;
        this.structure.linksnum = linksnum;
        //
        // count weights and assign weight indices. the
        // first weights is always 1.0.
        //
        int woff = 1;
        idx = 0;
        for (int i = 0; i < linksnum; i++) {
            final int src  = links[idx + Link.IDX_SRC];
            final int dst  = links[idx + Link.IDX_DST];
            final int widx = links[idx + Link.IDX_WEIGHT];
            //
            this.indeg[dst]++;
            this.outdeg[src]++;
            //
            // recurrence check.
            //
            final int lsrc = this.layermap[src];
            final int ldst = this.layermap[dst];
            if (lsrc >= ldst) {
                this.structure.recurrent = true;
            }
            //
            if (widx == WEIGHT_NEEDED) {
                links[idx + Link.IDX_WEIGHT] = woff; woff++; 
            } else if (widx == Link.NOWEIGHT) {
                links[idx + Link.IDX_WEIGHT] = 0;
            }
            //
            idx += Link.LINK_SIZE;
        }
        //
        // dont count the first weight, which is constant 1.
        //
        this.structure.weightsnum = (woff - 1);
        //
        // create reverted links. the weight indices are
        // now in linksrev too. the reverted are sorted in
        // source major order.
        //
        int[] linksrev = links.clone();
        Link.sortSrcMaj(linksrev, Link.ORDER_ASC);
        //
        // swap src and dst in linksrev.
        //
        idx = 0;
        for (int i = 0; i < linksnum; i++) {
            final int src  = linksrev[idx + Link.IDX_SRC];
            final int dst  = linksrev[idx + Link.IDX_DST];
            //
            linksrev[idx + Link.IDX_DST] = src;
            linksrev[idx + Link.IDX_SRC] = dst;
            //
            idx += Link.LINK_SIZE;
        }
        this.structure.linksrev = linksrev;
    }