gnu.trove.map.TIntObjectMap Java Examples

The following examples show how to use gnu.trove.map.TIntObjectMap. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ToJdbcPragmaTransform.java    From CQL with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public void execute() {
	try {
		Connection conn = DriverManager.getConnection(jdbcString);
		deleteThenCreate(conn);
		int s1 = (int) options1.getOrDefault(AqlOption.start_ids_at);
		int s2 = (int) options2.getOrDefault(AqlOption.start_ids_at);
		Pair<TObjectIntMap<X1>, TIntObjectMap<X1>> I = h.src().algebra().intifyX(s1);
		Pair<TObjectIntMap<X2>, TIntObjectMap<X2>> J = h.dst().algebra().intifyX(s2);
		for (En en : h.src().schema().ens) {
			for (X1 x : h.src().algebra().en(en)) {
				storeMyRecord(I, J, conn, x, prefix + enToString(en), en);
			}
		}
		conn.close();
	} catch (Exception e) {
		e.printStackTrace();
		throw new RuntimeException(e);
	}
}
 
Example #2
Source File: DataWatcherTransformer.java    From Carbon-2 with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static byte[] transform(WatchedEntity entity, byte[] data) throws IOException {
    if (entity == null) {
        return data;
    }
    TIntObjectMap<DataWatcherObject> objects = DataWatcherSerializer.decodeData(data);
    TIntObjectMap<DataWatcherObject> newobjects = new TIntObjectHashMap<DataWatcherObject>();
    //copy entity
    moveDWData(objects, newobjects, 0, 0); //flags
    moveDWData(objects, newobjects, 1, 1); //air
    moveDWData(objects, newobjects, 2, 2); //nametag
    moveDWData(objects, newobjects, 3, 3); //nametagvisible
    //copy specific types
    for (RemappingEntry entry : entity.getType().getRemaps()) {
        moveDWData(objects, newobjects, entry.getFrom(), entry.getTo());
    }
    return DataWatcherSerializer.encodeData(newobjects);
}
 
Example #3
Source File: PoolTest.java    From htm.java with GNU Affero General Public License v3.0 6 votes vote down vote up
@Test
public void testTroveMapPreservesSynapseOrdering() {
    Synapse s = new Synapse();
    TIntObjectMap<Synapse> t = new TIntObjectHashMap<>();
    t.put(2, s);
    t.put(4, s);
    t.put(6, s);
    t.put(8, s);
    t.put(10, s);
    t.put(12, s);
    
    int[] expectedKeys = { 12, 10, 8, 6, 4, 2 };
    assertTrue(Arrays.equals(expectedKeys, t.keys()));
    
    // Insert a cell index in the middle, check that order is still
    // preserved following inserts
    t.put(3, s);
    expectedKeys = new int[] { 12, 10, 8, 6, 4, 3, 2 };
    assertTrue(Arrays.equals(expectedKeys, t.keys()));
    
    // Check reversing produces ascending ordered Synapses
    expectedKeys = new int[] { 2, 3, 4, 6, 8, 10, 12 };
    assertTrue(Arrays.equals(expectedKeys, ArrayUtils.reverse(t.keys())));
}
 
Example #4
Source File: DataWatcherTransformer.java    From Carbon-2 with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static byte[] transform(WatchedEntity entity, byte[] data) throws IOException {
    if (entity == null) {
        return data;
    }
    TIntObjectMap<DataWatcherObject> objects = DataWatcherSerializer.decodeData(data);
    TIntObjectMap<DataWatcherObject> newobjects = new TIntObjectHashMap<DataWatcherObject>();
    //copy entity
    moveDWData(objects, newobjects, 0, 0); //flags
    moveDWData(objects, newobjects, 1, 1); //air
    moveDWData(objects, newobjects, 2, 2); //nametag
    moveDWData(objects, newobjects, 3, 3); //nametagvisible
    //copy specific types
    for (RemappingEntry entry : entity.getType().getRemaps()) {
        moveDWData(objects, newobjects, entry.getFrom(), entry.getTo());
    }
    return DataWatcherSerializer.encodeData(newobjects);
}
 
Example #5
Source File: MetricTable.java    From monsoon with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private static mt_other encodeOther(TIntObjectMap<metric_value> t_other, int timestampsSize) {
    LOG.log(Level.FINEST, "encoding {0}", TDecorators.wrap(t_other));
    metric_value[] values = new metric_value[timestampsSize];
    int values_len = 0;
    for (int i = 0; i < values.length; ++i) {
        metric_value mv = t_other.get(i);
        if (mv != null)
            values[values_len++] = mv;
    }

    mt_other result = new mt_other();
    result.presence = createPresenceBitset(t_other.keySet(), timestampsSize);
    result.values = Arrays.copyOf(values, values_len);

    return result;
}
 
Example #6
Source File: StaticRoutingConverter.java    From scheduler with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public StaticRouting fromJSON(Model mo, JSONObject o) throws JSONConverterException {
    Network v = Network.get(mo);
    TIntObjectMap<Link> idToLink = new TIntObjectHashMap<>();
    for (Link l : v.getLinks()) {
        idToLink.put(l.id(), l);
    }
    StaticRouting r = new StaticRouting();
    checkKeys(o, ROUTES_LABEL);
    JSONArray a = (JSONArray) o.get(ROUTES_LABEL);
    for (Object ao : a) {
        StaticRouting.NodesMap nm = nodesMapFromJSON(mo, (JSONObject) ((JSONObject) ao).get("nodes_map"));
        Map<Link, Boolean> links = new LinkedHashMap<>();
        JSONArray aoa = (JSONArray) ((JSONObject) ao).get("links");
        for (Object aoao : aoa) {
            links.put(idToLink.get(requiredInt((JSONObject)aoao, "link")),
                    Boolean.valueOf(requiredString((JSONObject) aoao, "direction")));
        }
        r.setStaticRoute(nm, links);
    }
    return r;
}
 
Example #7
Source File: FuzzySetSimJoin.java    From JedAIToolkit with Apache License 2.0 6 votes vote down vote up
/**
 * Find matches for a given set
 */
private TIntFloatHashMap search(int[][] querySet, int[][][] collection, float simThreshold,
        TIntObjectMap<TIntList>[] idx) {

    /* SIGNATURE GENERATION */
    TIntSet[] unflattenedSignature = computeUnflattenedSignature(querySet, simThreshold, idx);

    /* CANDIDATE SELECTION AND CHECK FILTER */
    TIntObjectMap<TIntFloatMap> checkFilterCandidates = applyCheckFilter(querySet, collection,
            unflattenedSignature, idx, simThreshold);

    /* NEAREST NEIGHBOR FILTER */
    TIntSet nnFilterCandidates = applyNNFilter(querySet, collection, checkFilterCandidates, simThreshold);

    /* VERIFICATION */
    TIntFloatHashMap matches = verifyCandidates(querySet, collection, nnFilterCandidates, simThreshold);

    return matches;
}
 
Example #8
Source File: FuzzySetSimJoin.java    From JedAIToolkit with Apache License 2.0 6 votes vote down vote up
/**
 * Computes the join between two already transformed and indexed collections
 *
 * @param collection1
 * @param collection2
 * @param simThreshold
 * @return
 */
HashMap<String, Float> join(int[][][] collection1, int[][][] collection2, float simThreshold) {
    final HashMap<String, Float> matchingPairs = new HashMap<>();

    /* CREATE INDEX */
    TIntObjectMap<TIntList>[] idx = buildSetInvertedIndex(collection2, tokenDict.size());

    /* EXECUTE THE JOIN ALGORITHM */
    for (int i = 0; i < collection1.length; i++) {
        TIntFloatHashMap matches = search(collection1[i], collection2, simThreshold, idx);
        for (int j : matches.keys()) {
            matchingPairs.put(i + "_" + j, matches.get(j));
        }
    }

    return matchingPairs;
}
 
Example #9
Source File: ToJdbcPragmaTransform.java    From CQL with GNU Affero General Public License v3.0 6 votes vote down vote up
private void storeMyRecord(Pair<TObjectIntMap<X1>, TIntObjectMap<X1>> i,
		Pair<TObjectIntMap<X2>, TIntObjectMap<X2>> j, Connection conn, X1 x, String table, En en) throws Exception {
	List<String> hdrQ = new LinkedList<>();
	List<String> hdr = new LinkedList<>();
	hdr.add("src" + idCol);
	hdr.add("dst" + idCol);
	hdrQ.add("?");
	hdrQ.add("?");

	String insertSQL = "INSERT INTO " + table + "(" + Util.sep(hdr, ",") + ") values (" + Util.sep(hdrQ, ",") + ")";
	PreparedStatement ps = conn.prepareStatement(insertSQL);

	ps.setObject(1, i.first.get(x), colTy0);
	ps.setObject(2, j.first.get(h.repr(en, x)), colTy0);

	ps.executeUpdate();
	ps.close();
}
 
Example #10
Source File: ChrPosMap.java    From systemsgenetics with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 
 * @param chr
 * @param pos
 * @return null if not found
 */
public E get(String chr, int pos){
	TIntObjectMap<E> chrElements = data.get(chr);
	if(chrElements == null){
		return null;
	} else {
		return chrElements.get(pos);
	}
}
 
Example #11
Source File: ChrPosMap.java    From systemsgenetics with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("RedundantStringConstructorCall")
public void put(String chr, int pos, E element){
	TIntObjectMap<E> chrElements = data.get(chr);
	if(chrElements == null){
		chrElements = new TIntObjectHashMap<E>();
		data.put(new String(chr), chrElements);
	}
	chrElements.put(pos, element);
}
 
Example #12
Source File: ChrPosMap.java    From systemsgenetics with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 
 * @param chr
 * @param pos
 * @return the removed element or null
 */
public E remove(String chr, int pos){
	
	TIntObjectMap<E> chrElements = data.get(chr);
	if(chrElements == null){
		return null;
	} else {
		return chrElements.remove(pos);
	}
	
}
 
Example #13
Source File: ChrPosMap.java    From systemsgenetics with GNU General Public License v3.0 5 votes vote down vote up
public Iterator<E> chrIterator(String chr) {
	
	TIntObjectMap<E> chrElements = data.get(chr);
	if(chrElements == null){
		return null;
	} else {
		return chrElements.valueCollection().iterator();
	}
	
}
 
Example #14
Source File: ChrPosMap.java    From systemsgenetics with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Iterator<E> iterator() {
	
	Iterator[] chrIterators = new Iterator[data.size()];
	
	int i = 0;
	for(TIntObjectMap<E> chrData : data.values()){
		chrIterators[i] = chrData.valueCollection().iterator();
		++i;
	}
	return Iterators.concat(chrIterators);
	
}
 
Example #15
Source File: ChrPosMap.java    From systemsgenetics with GNU General Public License v3.0 5 votes vote down vote up
public int size(){
	int count = 0;

	for(TIntObjectMap<E> chrResults : data.values()){
		count += chrResults.size();
	}
	return count;
}
 
Example #16
Source File: TroveIntObjectMapTest.java    From hashmapTest with The Unlicense 5 votes vote down vote up
@Override
public int test() {
    final TIntObjectMap<Integer> m_map = new TIntObjectHashMap<>( m_keys.length / 2 + 1, m_fillFactor );
    final Integer value = 1;
    int add = 0, remove = 0;
    while ( add < m_keys.length )
    {
        m_map.put( m_keys[ add ], value );
        ++add;
        m_map.put( m_keys[ add ], value );
        ++add;
        m_map.remove( m_keys[ remove++ ] );
    }
    return m_map.size();
}
 
Example #17
Source File: TroveIntObjectMapTest.java    From hashmapTest with The Unlicense 5 votes vote down vote up
@Override
public int test() {
    final TIntObjectMap<Integer> m_map = new TIntObjectHashMap<>( m_keys.length, m_fillFactor );
    for ( int i = 0; i < m_keys.length; ++i )
        m_map.put( m_keys[ i ], null );
    for ( int i = 0; i < m_keys.length; ++i )
        m_map.put( m_keys[ i ], null );
    return m_map.size();
}
 
Example #18
Source File: MetricTable.java    From monsoon with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static mt_hist encodeHist(TIntObjectMap<histogram> t_hist, int timestampsSize) {
    LOG.log(Level.FINEST, "encoding {0}", TDecorators.wrap(t_hist));
    histogram values[] = new histogram[timestampsSize];
    int values_len = 0;
    for (int i = 0; i < values.length; ++i) {
        if (t_hist.containsKey(i))
            values[values_len++] = t_hist.get(i);
    }

    mt_hist result = new mt_hist();
    result.presence = createPresenceBitset(t_hist.keySet(), timestampsSize);
    result.values = Arrays.copyOf(values, values_len);

    return result;
}
 
Example #19
Source File: PipeGridElementWidget.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static TIntObjectMap<TextureHolder> initializeIcons(Map<TextureSprite, TextureArea> sprite2TextureMap) {
    TIntObjectMap<TextureHolder> resultMap = new TIntObjectHashMap<>();
    for (int i = 0; i < 4; i++) {
        resultMap.put(pack(i, i + 1), new TextureHolder(sprite2TextureMap.get(TextureSprite.EDGE), i));
        resultMap.put(pack(i, i + 1, i + 2), new TextureHolder(sprite2TextureMap.get(TextureSprite.T_JOINT), i));
    }
    for (int i = 0; i < 2; i++) {
        resultMap.put(pack(i, i + 2), new TextureHolder(sprite2TextureMap.get(TextureSprite.STRAIGHT), i));
        resultMap.put(pack(i), new TextureHolder(sprite2TextureMap.get(TextureSprite.STRAIGHT), i));
        resultMap.put(pack(i + 2), new TextureHolder(sprite2TextureMap.get(TextureSprite.STRAIGHT), i));
    }
    resultMap.put(pack(0, 1, 2, 3), new TextureHolder(sprite2TextureMap.get(TextureSprite.CROSS), 0));
    return resultMap;
}
 
Example #20
Source File: BlockPattern.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
public BlockPattern(Predicate<BlockWorldState>[][][] predicatesIn,
                    List<Pair<Predicate<BlockWorldState>, IntRange>> countMatches,
                    TIntObjectMap<Predicate<PatternMatchContext>> layerMatchers,
                    List<Predicate<PatternMatchContext>> validators,
                    RelativeDirection[] structureDir,
                    int[][] aisleRepetitions) {
    this.blockMatches = predicatesIn;
    this.countMatches = countMatches.toArray(new Pair[0]);
    this.layerMatchers.putAll(layerMatchers);
    this.validators = validators.toArray(new Predicate[0]);
    this.fingerLength = predicatesIn.length;

    if (this.fingerLength > 0) {
        this.thumbLength = predicatesIn[0].length;

        if (this.thumbLength > 0) {
            this.palmLength = predicatesIn[0][0].length;
        } else {
            this.palmLength = 0;
        }
    } else {
        this.thumbLength = 0;
        this.palmLength = 0;
    }
    this.structureDir = structureDir;
    this.aisleRepetitions = aisleRepetitions;

    initializeCenterOffsets();
}
 
Example #21
Source File: Algebra.java    From CQL with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * DO NOT close this connection
 */
// client should not remove
public synchronized Connection addIndices(Pair<TObjectIntMap<X>, TIntObjectMap<X>> j, Map<En, List<String>> indices,
		int vlen) {
	if (conn == null) {
		conn = createAndLoad(indices, j, vlen);
		this.indicesLoaded = new LinkedList<>();
		for (List<String> l : indices.values()) {
			this.indicesLoaded.addAll(l);
		}
		return conn;
	}
	try (Statement stmt = conn.createStatement()) {
		for (List<String> ss : indices.values()) {
			for (String s : ss) {
				if (!indicesLoaded.contains(s)) {
					stmt.execute(s);
					indicesLoaded.add(s);
				}
			}
		}
		stmt.close();
		return conn;
	} catch (Exception ex) {
		ex.printStackTrace();
		throw new RuntimeException(ex);
	}
}
 
Example #22
Source File: ToCsvPragmaTransform.java    From CQL with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void execute() {
	try {
		StringBuffer sb = new StringBuffer();
		CSVPrinter printer = new CSVPrinter(sb, ToCsvPragmaInstance.getFormat(options1));
		int srcId = (int) options1.getOrDefault(AqlOption.start_ids_at);
		int dstId = (int) options2.getOrDefault(AqlOption.start_ids_at);

		Pair<TObjectIntMap<X1>, TIntObjectMap<X1>> a = h.src().algebra().intifyX(srcId);
		Pair<TObjectIntMap<X2>, TIntObjectMap<X2>> b = h.dst().algebra().intifyX(dstId);

		for (En en : h.src().schema().ens) {
			for (X1 x1 : h.src().algebra().en(en)) {
				List<String> row = new LinkedList<>();
				row.add(Integer.toString(a.first.get(x1)));
				X2 x2 = h.repr(en, x1);
				row.add(Integer.toString(b.first.get(x2)));
				printer.printRecord(row);
			}
		}

		printer.close();
		delete();
		if (!file.createNewFile()) {
			throw new RuntimeException("Could not create new file: " + file);
		}
		FileWriter out = new FileWriter(file);
		out.write(sb.toString());
		out.close();
	} catch (IOException e) {
		throw new RuntimeException(e);
	}
}
 
Example #23
Source File: TIntObjectHashMapTest.java    From baleen with Apache License 2.0 4 votes vote down vote up
@Test
public void testPutAllTIntObjectMap() {
  TIntObjectMap<String> map = new gnu.trove.map.hash.TIntObjectHashMap<>();
  tIntObjectHashMap.putAll(map);
  verify(delegate).putAll(map);
}
 
Example #24
Source File: TIntObjectHashMap.java    From baleen with Apache License 2.0 4 votes vote down vote up
/** See {@link gnu.trove.map.hash.TIntObjectHashMap#putAll(TIntObjectMap)} */
public void putAll(TIntObjectMap<? extends V> map) {
  delegate.putAll(map);
}
 
Example #25
Source File: ShardCacheViewImpl.java    From JDA with Apache License 2.0 4 votes vote down vote up
public TIntObjectMap<JDA> getMap()
{
    if (!lock.writeLock().isHeldByCurrentThread())
        throw new IllegalStateException("Cannot access map without holding write lock!");
    return elements;
}
 
Example #26
Source File: DataWatcherSerializer.java    From Carbon-2 with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static byte[] encodeData(TIntObjectMap<DataWatcherObject> objects) {
	PacketDataSerializer serializer = new PacketDataSerializer(Unpooled.buffer());
	TIntObjectIterator<DataWatcherObject> iterator = objects.iterator();
	while (iterator.hasNext()) {
		iterator.advance();
		DataWatcherObject object = iterator.value();
		final int tk = ((object.type.getId() << 5) | (iterator.key() & 0x1F)) & 0xFF;
		serializer.writeByte(tk);
		switch (object.type) {
			case BYTE: {
				serializer.writeByte((byte) object.value);
				break;
			}
			case SHORT: {
				serializer.writeShort((short) object.value);
				break;
			}
			case INT: {
				serializer.writeInt((int) object.value);
				break;
			}
			case FLOAT: {
				serializer.writeFloat((float) object.value);
				break;
			}
			case STRING: {
			    PacketDataSerializerHelper.writeString(serializer, (String) object.value);
				break;
			}
			case ITEMSTACK: {
			    PacketDataSerializerHelper.writeItemStack(serializer, (ItemStack) object.value);
				break;
			}
			case VECTOR3I: {
				BlockPosition blockPos = (BlockPosition) object.value;
				serializer.writeInt(blockPos.getX());
				serializer.writeInt(blockPos.getY());
				serializer.writeInt(blockPos.getZ());
				break;
			}
			case VECTOR3F: {
				Vector3f vector = (Vector3f) object.value;
				serializer.writeFloat(vector.getX());
				serializer.writeFloat(vector.getY());
				serializer.writeFloat(vector.getZ());
				break;
			}
		}
	}
	serializer.writeByte(127);
	return Utils.toArray(serializer);
}
 
Example #27
Source File: DataWatcherTransformer.java    From Carbon-2 with GNU Lesser General Public License v3.0 4 votes vote down vote up
private static void moveDWData(TIntObjectMap<DataWatcherObject> from, TIntObjectMap<DataWatcherObject> to, int oldId, int newId) {
    DataWatcherObject dwobject = from.remove(oldId);
    if (dwobject != null) {
        to.put(newId, dwobject);
    }
}
 
Example #28
Source File: DataWatcherSerializer.java    From Carbon-2 with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static byte[] encodeData(TIntObjectMap<DataWatcherObject> objects) {
	PacketDataSerializer serializer = new PacketDataSerializer(Unpooled.buffer());
	TIntObjectIterator<DataWatcherObject> iterator = objects.iterator();
	while (iterator.hasNext()) {
		iterator.advance();
		DataWatcherObject object = iterator.value();
		final int tk = ((object.type.getId() << 5) | (iterator.key() & 0x1F)) & 0xFF;
		serializer.writeByte(tk);
		switch (object.type) {
			case BYTE: {
				serializer.writeByte((byte) object.value);
				break;
			}
			case SHORT: {
				serializer.writeShort((short) object.value);
				break;
			}
			case INT: {
				serializer.writeInt((int) object.value);
				break;
			}
			case FLOAT: {
				serializer.writeFloat((float) object.value);
				break;
			}
			case STRING: {
			    PacketDataSerializerHelper.writeString(serializer, (String) object.value);
				break;
			}
			case ITEMSTACK: {
			    PacketDataSerializerHelper.writeItemStack(serializer, (ItemStack) object.value);
				break;
			}
			case VECTOR3I: {
				BlockPosition blockPos = (BlockPosition) object.value;
				serializer.writeInt(blockPos.getX());
				serializer.writeInt(blockPos.getY());
				serializer.writeInt(blockPos.getZ());
				break;
			}
			case VECTOR3F: {
				Vector3f vector = (Vector3f) object.value;
				serializer.writeFloat(vector.getX());
				serializer.writeFloat(vector.getY());
				serializer.writeFloat(vector.getZ());
				break;
			}
		}
	}
	serializer.writeByte(127);
	return Utils.toArray(serializer);
}
 
Example #29
Source File: DataWatcherTransformer.java    From Carbon-2 with GNU Lesser General Public License v3.0 4 votes vote down vote up
private static void moveDWData(TIntObjectMap<DataWatcherObject> from, TIntObjectMap<DataWatcherObject> to, int oldId, int newId) {
    DataWatcherObject dwobject = from.remove(oldId);
    if (dwobject != null) {
        to.put(newId, dwobject);
    }
}
 
Example #30
Source File: ChrPosMap.java    From systemsgenetics with GNU General Public License v3.0 4 votes vote down vote up
public ChrPosMap() {
	data = new HashMap<String, TIntObjectMap<E>>();
}