Package gnu.trove.map.hash

Examples of gnu.trove.map.hash.TIntIntHashMap


        }
        if (isContiguous)
            return g;       

        // Map the vertices to a contiguous range
        TIntIntMap vMap = new TIntIntHashMap(g.order());
        int j = 0;
        for (int i : g.vertices())
            vMap.put(i, j++);
       
        Graph<E> copy = g.copy(Collections.<Integer>emptySet());
        for (int i = 0; i < order; ++i)
            copy.add(i);
        for (E e : g.edges())
            copy.add(e.<E>clone(vMap.get(e.from()), vMap.get(e.to())));
       
        return copy;
    }   
View Full Code Here


     *
     * @param length the length of this vector
     */
    public SparseHashIntegerVector(int length) {
        this.length = length;
        map = new TIntIntHashMap();
        magnitude = -1;
    }
View Full Code Here

    public SparseHashIntegerVector(IntegerVector values) {
        length = values.length();
        magnitude = -1;
        if (values instanceof SparseHashIntegerVector) {
            SparseHashIntegerVector v = (SparseHashIntegerVector)values;
            map = new TIntIntHashMap(v.map);
        }
        else if (values instanceof SparseVector) {
            int[] nonZeros = ((SparseVector) values).getNonZeroIndices();
            map = new TIntIntHashMap(nonZeros.length);
            for (int index : nonZeros)
                map.put(index, values.get(index));
        } else {
            map = new TIntIntHashMap();
            for (int index = 0; index < values.length(); ++index) {
                int value = values.get(index);
                if (value != 0)
                    map.put(index, value);
            }
View Full Code Here

    public Map<Integer,Integer> findIsomorphism(Graph<? extends Edge> g1,
                                                Graph<? extends Edge> g2) {
        // Since the user has asked to find the mapping itself, we'll need to
        // keep track of how the vertices are remapped.  Note that if the graphs
        // are already in canonical order, then these maps will be empty.
        TIntIntHashMap g1vMap = new TIntIntHashMap(g1.order());
        TIntIntHashMap g2vMap = new TIntIntHashMap(g2.order());

        // Remap the graphs so that the vertices are contiguous, filling in a
        // backwards mapping so we can recover the isomorphism later.
        Graph<? extends Edge> g1mapped = remap(g1, g1vMap);
        Graph<? extends Edge> g2mapped = remap(g2, g2vMap);
        State state = makeInitialState(g1mapped, g2mapped);

        Map<Integer,Integer> isoMapping = new HashMap<Integer,Integer>();
        // If we mapped the vertices, we have to unmap the vertices in order
        // to identify the isometric pairs.
        if (match(state, isoMapping)) {
            // Create a new isometric map that will contain the unmapped
            // mappings
            TIntIntMap fixedIsoMapping = new TIntIntHashMap(isoMapping.size());
            for (Map.Entry<Integer,Integer> e : isoMapping.entrySet()) {
                int v1 = e.getKey();
                v1 = (g1vMap.isEmpty()) ? v1 : g1vMap.get(v1);
                int v2 = e.getValue();
                v2 = (g2vMap.isEmpty()) ? v2 : g2vMap.get(v2);
                fixedIsoMapping.put(v1, v2);
            }
            return TDecorators.wrap(fixedIsoMapping);
        }
        else
            return Collections.<Integer,Integer>emptyMap();
View Full Code Here

        }
        if (isContiguous)
            return g;       

        // Map the vertices to a contiguous range
        TIntIntMap vMap = new TIntIntHashMap(g.order());
        int j = 0;
        for (int i : g.vertices()) {
            vMap.put(i, j++);
        }
       
        if (rvMap != null) {
            // Assumes a stable iteration ordering of the vertices, which is
            // potentially unsafe... However, this avoids putting a redundant
            // null check in the prior loop.
            int k = 0;
            for (int i : g.vertices()) {
                rvMap.put(k++, i);
            }
        }
       
        Graph<E> copy = g.copy(Collections.<Integer>emptySet());
        for (int i = 0; i < order; ++i)
            copy.add(i);
        for (E e : g.edges())
            copy.add(e.<E>clone(vMap.get(e.from()), vMap.get(e.to())));
       
        return copy;
    }   
View Full Code Here

     *        added to {@code objectIndices}
     */
    public IndexedCounter(Indexer<T> objectIndices, boolean allowNewIndices) {
        this.objectIndices = objectIndices;
        this.allowNewIndices = allowNewIndices;
        indexToCount = new TIntIntHashMap();
        sum = 0;
    }
View Full Code Here

        // If the state of this set's type is inconsistent with the current type
        // mapping, then update the mapping with any missing types and then
        // reset all of its BitSet contents with the correct indices
        if (needToRemapIndices) {
            TIntIntMap typeRemapping = new TIntIntHashMap();
            for (Map.Entry<Object,Integer> e : typeIndices.entrySet()) {
                Object o = e.getKey();
                int oldIndex = e.getValue();
                // NOTE: the else {} case above may have added several of our
                // types that weren't inconsistent, so this may be an identity
                // mapping for some types, which is nice.
                typeRemapping.put(oldIndex, index(o));
            }
            // Remap all the in-edges vertices' types...
            for (TIntObjectIterator<BitSet> it = edges.iterator(); it.hasNext(); ) {
                it.advance();
                int v = it.key();
                BitSet oldIndices = it.value();
                BitSet newIndices = new BitSet();
                for (int i = oldIndices.nextSetBit(0); i >= 0;
                         i = oldIndices.nextSetBit(i+1)) {
                    newIndices.set(typeRemapping.get(i));
                }
                it.setValue(newIndices);
            }
        }
    }
View Full Code Here

        // If the state of this set's type is inconsistent with the current type
        // mapping, then update the mapping with any missing types and then
        // reset all of its BitSet contents with the correct indices
        if (needToRemapIndices) {
            TIntIntMap typeRemapping = new TIntIntHashMap();
            for (Map.Entry<Object,Integer> e : typeIndices.entrySet()) {
                Object o = e.getKey();
                int oldIndex = e.getValue();
                // NOTE: the else {} case above may have added several of our
                // types that weren't inconsistent, so this may be an identity
                // mapping for some types, which is nice.
                typeRemapping.put(oldIndex, index(o));
            }
            // Remap all the in-edges vertices' types...
            for (TIntObjectIterator<BitSet> it = inEdges.iterator(); it.hasNext(); ) {
                it.advance();
                int v = it.key();
                BitSet oldIndices = it.value();
                BitSet newIndices = new BitSet();
                for (int i = oldIndices.nextSetBit(0); i >= 0;
                         i = oldIndices.nextSetBit(i+1)) {
                    newIndices.set(typeRemapping.get(i));
                }
                it.setValue(newIndices);
            }
            // Remap all the in-edges vertices' types...
            for (TIntObjectIterator<BitSet> it = outEdges.iterator(); it.hasNext(); ) {
                it.advance();
                int v = it.key();
                BitSet oldIndices = it.value();
                BitSet newIndices = new BitSet();
                for (int i = oldIndices.nextSetBit(0); i >= 0;
                         i = oldIndices.nextSetBit(i+1)) {
                    newIndices.set(typeRemapping.get(i));
                }
                it.setValue(newIndices);
            }
        }
    }
View Full Code Here

        n = vars.length;
        matching = new int[n];
        for (int i = 0; i < n; i++) {
            matching[i] = -1;
        }
        map = new TIntIntHashMap();
        IntVar v;
        int ub;
        int idx = n;
        for (int i = 0; i < n; i++) {
            v = vars[i];
View Full Code Here

        super("GCC", createProp(vars, values, cards));
    }

  private static Propagator createProp(IntVar[] vars, int[] values, IntVar[] cards) {
    assert values.length == cards.length;
    TIntIntHashMap map = new TIntIntHashMap();
    int idx = 0;
    for (int v : values) {
      if (!map.containsKey(v)) {
        map.put(v, idx);
        idx++;
      } else {
        throw new UnsupportedOperationException("ERROR: multiple occurrences of value: " + v);
      }
    }
View Full Code Here

TOP

Related Classes of gnu.trove.map.hash.TIntIntHashMap

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.