Java Code Examples for it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap#put()

The following examples show how to use it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap#put() . 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: QueryStringParserCallbackBuilder.java    From util with Apache License 2.0 6 votes vote down vote up
public CompositeCallback(Collection<KeyCallbackPair<T>> keyCallbackPairs) {
    slotMap = new Int2IntOpenHashMap(keyCallbackPairs.size());
    nextSlot = new int[keyCallbackPairs.size()];
    keys = new String[keyCallbackPairs.size()];
    callbacks = new Object[keyCallbackPairs.size()];

    int i = 0;
    for (KeyCallbackPair<T> keyCallbackPair : keyCallbackPairs) {
        String key = keyCallbackPair.getKey();
        int hash = hash(key, 0, key.length());
        if (slotMap.containsKey(hash))  {
            nextSlot[i] = slotMap.get(hash);
        } else {
            nextSlot[i] = -1;
        }
        slotMap.put(hash, i);
        keys[i] = key;
        callbacks[i] = keyCallbackPair.getCallback();
        i++;
    }
}
 
Example 2
Source File: PositionListIndex.java    From metanome-algorithms with Apache License 2.0 5 votes vote down vote up
public Int2IntOpenHashMap asHashMap() {
	Int2IntOpenHashMap hashedPLI = new Int2IntOpenHashMap(this.clusters.size());		
	int clusterId = 0;
	for (IntArrayList cluster : this.clusters) {
		for (int recordId : cluster)
			hashedPLI.put(recordId, clusterId);
		
		clusterId++;
	}
	return hashedPLI;
}
 
Example 3
Source File: RedirectMap.java    From tagme with Apache License 2.0 5 votes vote down vote up
@Override
protected Int2IntMap parseSet() throws IOException
{
	final Object2IntMap<String> titles = new TitlesToWIDMap(lang).getDataset();
	final Int2IntOpenHashMap map = new Int2IntOpenHashMap(3000000);
	SQLWikiParser parser = new SQLWikiParser(log, "Titles NF") {
		@Override
		public boolean compute(ArrayList<String> values) throws IOException
		{
			int ns = Integer.parseInt(values.get(SQLWikiParser.REDIRECT_NS));
			if (ns == SQLWikiParser.NS_ARTICLE)
			{
				int idFrom = Integer.parseInt(values.get(SQLWikiParser.REDIRECT_ID_FROM));
				int idTo = titles.getInt(cleanPageName(values.get(SQLWikiParser.REDIRECT_TITLE_TO)));
				if (idTo >= 0)
					map.put(idFrom, idTo);
				else this.updateItem(0);
				
				return true;
			} else return false;
		}
	};

	File input = WikipediaFiles.REDIRECTS.getSourceFile(lang);
	InputStreamReader in = new InputStreamReader(new FileInputStream(input), Charset.forName("UTF-8"));
	parser.compute(in);
	in.close();
	
	map.defaultReturnValue(-1);
	map.trim();
	
	return map;

}
 
Example 4
Source File: FastUtilMapTest.java    From hashmapTest with The Unlicense 5 votes vote down vote up
@Override
public int test() {
    final Int2IntOpenHashMap m_map = new Int2IntOpenHashMap( m_keys.length, m_fillFactor );
    for ( int i = 0; i < m_keys.length; ++i )
        m_map.put( m_keys[ i ],m_keys[ i ] );
    for ( int i = 0; i < m_keys.length; ++i )
        m_map.put( m_keys[ i ],m_keys[ i ] );
    return m_map.size();
}
 
Example 5
Source File: FastUtilMapTest.java    From hashmapTest with The Unlicense 5 votes vote down vote up
@Override
public int test() {
    final Int2IntOpenHashMap m_map = new Int2IntOpenHashMap( m_keys.length / 2 + 1, m_fillFactor );
    int add = 0, remove = 0;
    while ( add < m_keys.length )
    {
        m_map.put( m_keys[ add ], m_keys[ add ] );
        ++add;
        m_map.put( m_keys[ add ], m_keys[ add ] );
        ++add;
        m_map.remove( m_keys[ remove++ ] );
    }
    return m_map.size();
}
 
Example 6
Source File: OnHeapIntDictionary.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor for the class.
 * Populates the value <-> mappings.
 *
 * @param dataBuffer Pinot data buffer
 * @param length Length of the dictionary
 */
public OnHeapIntDictionary(PinotDataBuffer dataBuffer, int length) {
  super(dataBuffer, length, Integer.BYTES, (byte) 0);

  _valToDictId = new Int2IntOpenHashMap(length);
  _valToDictId.defaultReturnValue(NULL_VALUE_INDEX);
  _dictIdToVal = new int[length];

  for (int dictId = 0; dictId < length; dictId++) {
    int value = getInt(dictId);
    _dictIdToVal[dictId] = value;
    _valToDictId.put(value, dictId);
  }
}
 
Example 7
Source File: PdfExtractFile.java    From inception with Apache License 2.0 4 votes vote down vote up
private void initializeStringContent(String aPdftxt)
{
    stringToExtract = new Int2IntOpenHashMap();
    extractToString = new Int2IntOpenHashMap();
    extractLines = new HashMap<>();
    pageOffsetMap = new HashMap<>();
    pdftxt = aPdftxt;

    StringBuilder sb = new StringBuilder();
    String[] lines = pdftxt.split("\n");

    int extractLineIndex = 1;
    int strContentIndex = 0;
    int lastPage = 1;
    int pageBeginIndex = 1;

    for (String line : lines)
    {
        PdfExtractLine extractLine = new PdfExtractLine();
        String[] columns = line.split("\t");
        int page = Integer.parseInt(columns[0].trim());
        extractLine.setPage(page);
        extractLine.setPosition(extractLineIndex);
        extractLine.setValue(columns[1].trim());
        extractLine.setDisplayPositions(columns.length > 2 ? columns[2].trim() : "");
        extractLines.put(extractLineIndex, extractLine);

        stringToExtract.put(strContentIndex, extractLineIndex);
        extractToString.put(extractLineIndex, strContentIndex);

        if (page > lastPage) {
            pageOffsetMap.put(lastPage, new Offset(pageBeginIndex, extractLineIndex - 1));
            lastPage = page;
            pageBeginIndex = extractLineIndex;
        }

        // if value of PdfExtractLine is in brackets it is a draw operation and is ignored
        // if value is "NO_UNICODE" also skip, unicode mapping is unavailable for this character
        if (!extractLine.getValue().matches("^\\[.*\\]$")
            && !extractLine.getValue().equals("NO_UNICODE"))
        {
            sb.append(extractLine.getValue());
            strContentIndex++;
        }
        extractLineIndex++;
    }

    extractToString.put(extractLineIndex, strContentIndex);
    stringToExtract.put(strContentIndex, extractLineIndex);
    extractLines.put(extractLineIndex, new PdfExtractLine(lastPage, extractLineIndex, "", ""));

    // add last page
    pageOffsetMap.put(lastPage, new Offset(pageBeginIndex, extractLineIndex - 1));
    maxPageNumber = lastPage;
    stringContent = sb.toString();
}
 
Example 8
Source File: FastUtilMapTest.java    From hashmapTest with The Unlicense 4 votes vote down vote up
@Override
public void setup(final int[] keys, final float fillFactor, final int oneFailOutOf) {
    super.setup(keys, fillFactor, oneFailOutOf);
    m_map = new Int2IntOpenHashMap( keys.length, fillFactor );
    for (int key : keys) m_map.put( key + (key % oneFailOutOf == 0 ? 1 : 0), key );
}