Package gnu.trove.set.hash

Examples of gnu.trove.set.hash.TIntHashSet


    /**
     * Creates a new empty {@code TroveIntSet} with the specified capacity.
     */
    public TroveIntSet(int capacity) {
        set = new TIntHashSet(capacity);
    }
View Full Code Here


        while (iter.hasNext()) {
            int n = iter.nextInt();
            classes.count(vertexAssignments[n]);
        }

        TIntSet ties = new TIntHashSet();
        int max = 0;
        for (Map.Entry<Integer,Integer> e : classes) {
            int clazz = e.getKey();
            int count = e.getValue();
            if (count > max) {
                ties.clear();
                max = count;
            }
            if (count == max)
                ties.add(clazz);
        }

        int[] options = ties.toArray(new int[ties.size()]);
        return (options.length == 1)
            ? options[0]
            : options[RANDOM.nextInt(options.length)];
    }
View Full Code Here

                classSums.put(nClass, weight);
            }
        }

        double maxSum = -1d;
        TIntSet ties = new TIntHashSet();
        TIntDoubleIterator iter = classSums.iterator();
        while (iter.hasNext()) {
            iter.advance();
            double weight = iter.value();
            if (weight > maxSum) {
                maxSum = weight;
                ties.clear();
            }
            if (weight == maxSum)
                ties.add(iter.key());
           
        }
       
        // If there wasn't a tie after all
        int[] options = ties.toArray();
        return (options.length == 1)
            ? options[0]
            : options[RANDOM.nextInt(options.length)];
    }
View Full Code Here

        if (left.length() != right.length())
            throw new IllegalArgumentException(
                    "Vectors of different sizes cannot be multiplied");

        if (left instanceof SparseVector && right instanceof SparseVector) {
            TIntSet lnz = new TIntHashSet(((SparseVector)left).getNonZeroIndices());
            for (int nz : ((SparseVector)right).getNonZeroIndices()) {
                if (lnz.contains(nz)) {
                    left.set(nz, left.get(nz) * right.get(nz));
                    lnz.remove(nz);
                }
            }

            // The remaining non-zero values in left should be zero'd out
            // because they were effectively multiplied by zero by the right
            // vector.
            TIntIterator iter = lnz.iterator();
            while (iter.hasNext())
                left.set(iter.next(), 0);
        }
        else {
            int length = left.length();
View Full Code Here

            SparseVector svA = (SparseVector)a;
            SparseVector svB = (SparseVector)b;

            int[] aNonZero = svA.getNonZeroIndices();
            int[] bNonZero = svB.getNonZeroIndices();
            TIntSet union = new TIntHashSet(aNonZero);
            union.addAll(bNonZero);
           
            double sum = 0;
            int[] nzIndices = union.toArray();
            for (int nz : nzIndices) {
                double x = a.get(nz);
                double y = b.get(nz);
                double diff = x - y;
                sum += diff * diff;
 
View Full Code Here

     */
    public SparseDirectedTypedEdgeSet(int rootVertex) {
        this.rootVertex = rootVertex;
        inEdges = new TIntObjectHashMap<BitSet>();
        outEdges = new TIntObjectHashMap<BitSet>();
        connected = new TIntHashSet();
        size = 0;
    }
View Full Code Here

            this.v = v;
            vertsInSubgraph = new ArrayDeque<Integer>();
            extensionStack = new ArrayDeque<TIntHashSet>();

            IntSet neighbors = g.getNeighbors(v);
            TIntHashSet extension = new TIntHashSet();
            IntIterator iter = neighbors.iterator();
            while (iter.hasNext()) {
                int u = iter.nextInt();
                if (u > v)
                    extension.add(u);
            }

            vertsInSubgraph.push(v);
            extensionStack.push(extension);
        }
View Full Code Here

         * Returns the next graph in enumeration or {@code null} if no further
         * graphs can be generated from this {@code Extension}'s seed vertex.
         */
        public G next() {
            // Load the next set of extensions to the current subgraph
            TIntHashSet curExtension = extensionStack.peek();
            if (curExtension == null)
                return null;
            else {
                while (extensionStack.size() < subgraphSize - 1
                       && !extensionStack.isEmpty()) {
                    loadNextExtension();

                    curExtension = extensionStack.peek();
                    if (curExtension.isEmpty())
                        extensionStack.pop();
                }
            }

            // Some checking here
            curExtension = extensionStack.peek();
            if (curExtension == null)
                return null;

            TIntIterator iter = curExtension.iterator();
            int w = iter.next();
            iter.remove();
           
            vertsInSubgraph.push(w);
            // The return type of copy() isn't parameterized on the type of the
            // graph itself.  However, we know that all the current interfaces
            // confirm to the convention that the type is refined (narrowed,
            // really), so we perform the cast here to give the user back the
            // more specific type.

            @SuppressWarnings("unchecked")
                G next = (G)g.copy(new HashSet<Integer>(vertsInSubgraph));

            // Remove the most recently added vertex from the set of vertices so
            // that the next call to next() can add its vertex
            vertsInSubgraph.pop();

            // If that was the last vertex in the current extension, then pop it
            // off the stack to signify the next extension shouldbe loaded.
            if (curExtension.isEmpty()) {
                extensionStack.pop();
                vertsInSubgraph.pop();
            }
           
            return next;           
View Full Code Here

         * extensionStack} will be empty upon this method's return.
         */
        private void loadNextExtension() {
            // Get the set of vertices that are on the top of the stack
            // currently
            TIntHashSet extension = extensionStack.peek();
            if (extension == null)
                throw new IllegalStateException();

            if (extension.isEmpty())
                return;

            // Choose and remove an aribitrary vertex from the extension           
            TIntIterator iter = extension.iterator();
            Integer w = iter.next();
            iter.remove();

            // The next extension is formed from all edges to vertices whose
            // indices are greater than the currently selected vertex, w,
            // and that point to a vertex in the exclusive neighborhood of
            // w.  The exclusive neighborhood is defined relative to a set
            // of vertices N: all vertices that are adjacent to w but are
            // not in N or the neighbors of N.  In this case, N is the
            // current subgraph's vertices
            TIntHashSet nextExtension = new TIntHashSet(extension);
            next_vertex:
            for (Integer n : g.getNeighbors(w)) {
                // Perform the fast vertex value test and check for whether
                // the vertex is currently in the subgraph
                if (n > v && !vertsInSubgraph.contains(n)) {
                    // Then perform the most expensive
                    // exclusive-neighborhood test that looks at the
                    // neighbors of the vertices in the current subgraph
                    Iterator<Integer> subIter = vertsInSubgraph.iterator();
                    while (subIter.hasNext()) {
                        int inCur = subIter.next();
                        // If we find n within the neighbors of a vertex in
                        // the current subgraph, then skip the remaining
                        // checks and examine another vertex adjacent to w.
                        if (g.contains(inCur, n))
                            continue next_vertex;
                    }
                    // Otherwise, n is in the exclusive neighborhood of w,
                    // so add it to the future extension.
                    nextExtension.add(n);
                }
            }
            vertsInSubgraph.push(w);
            extensionStack.push(nextExtension);
        }
View Full Code Here

     */
    private final TIntSet edges;
   
    public SparseUndirectedEdgeSet(int rootVertex) {
        this.rootVertex = rootVertex;
        edges = new TIntHashSet();
    }
View Full Code Here

TOP

Related Classes of gnu.trove.set.hash.TIntHashSet

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.