Package gnu.trove.set

Examples of gnu.trove.set.TIntSet


        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

    /** {@inheritDoc} */
    public boolean equals( Object other ) {
        if ( ! ( other instanceof TIntSet ) ) {
            return false;
        }
        TIntSet that = ( TIntSet ) other;
        if ( that.size() != this.size() ) {
            return false;
        }
        for ( int i = _states.length; i-- > 0; ) {
            if ( _states[i] == FULL ) {
                if ( ! that.contains( _set[i] ) ) {
                    return false;
                }
            }
        }
        return true;
View Full Code Here

        /** {@inheritDoc) */
        public boolean equals( Object other ) {
            if (! ( other instanceof TIntSet ) ) {
                return false;
            }
            final TIntSet that = ( TIntSet ) other;
            if ( that.size() != this.size() ) {
                return false;
            }
            for ( int i = _states.length; i-- > 0; ) {
                if ( _states[i] == FULL ) {
                    if ( ! that.contains( _set[i] ) ) {
                        return false;
                    }
                }
            }
            return true;
View Full Code Here

        assert VALUES.length == OCCURRENCES.length;
        if (!CLOSED) {
            return new GlobalCardinality(VARS, VALUES, OCCURRENCES);
        } else {
            TIntArrayList toAdd = new TIntArrayList();
            TIntSet givenValues = new TIntHashSet();
            for (int i : VALUES) {
                assert !givenValues.contains(i);
                givenValues.add(i);
            }
            for (IntVar var : VARS) {
                int ub = var.getUB();
                for (int k = var.getLB(); k <= ub; k = var.nextValue(k)) {
                    if (!givenValues.contains(k)) {
                        if (!toAdd.contains(k)) {
                            toAdd.add(k);
                        }
                    }
                }
View Full Code Here

            }
            address += (tuple[i] - lowerbounds[i]) * blocks[i];
        }
        int a = (int) (address % Integer.MAX_VALUE);
        int t = (int) (address / Integer.MAX_VALUE);
        TIntSet ts = tables.get(t);
        return ts != null && ts.contains(a);
    }
View Full Code Here

        for (int i = (n - 1); i >= 0; i--) {
            address += (tuple[i] - lowerbounds[i]) * blocks[i];
        }
        int a = (int) (address % Integer.MAX_VALUE);
        int t = (int) (address / Integer.MAX_VALUE);
        TIntSet ts = tables.get(t);
        if (ts == null) {
            ts = new TIntHashSet();
            tables.put(t, ts);
        }
        ts.add(a);
    }
View Full Code Here

                if (!(pn instanceof ParseTokenScalarFunction))
                    getAllIndices1(pn, set);
    }

    public static TIntSet getAllIndicesT(ParseToken node) {
        TIntSet set = new TIntHashSet();
        getAllIndicesT1(node, set);
        return set;
    }
View Full Code Here

TOP

Related Classes of gnu.trove.set.TIntSet

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.