it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap Java Examples

The following examples show how to use it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap. 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: SetSimilarity.java    From RankSys with Mozilla Public License 2.0 6 votes vote down vote up
private Int2IntMap getFasterIntersectionMap(int uidx) {
    Int2IntOpenHashMap intersectionMap = new Int2IntOpenHashMap();
    intersectionMap.defaultReturnValue(0);

    IntIterator iidxs = data.getUidxIidxs(uidx);
    while (iidxs.hasNext()) {
        IntIterator vidxs = data.getIidxUidxs(iidxs.nextInt());
        while (vidxs.hasNext()) {
            intersectionMap.addTo(vidxs.nextInt(), 1);
        }
    }

    intersectionMap.remove(uidx);

    return intersectionMap;
}
 
Example #3
Source File: LeftIndexedMultiSegmentBipartiteGraph.java    From GraphJet with Apache License 2.0 6 votes vote down vote up
/**
 * This starts the graph off with a single segment, and additional ones are allocated as needed.
 *
 * @param maxNumSegments                 is the maximum number of segments we'll add to the graph.
 *                                       At that point, the oldest segments will start getting
 *                                       dropped
 * @param maxNumEdgesPerSegment          determines when the implementation decides to fork off a
 *                                       new segment
 * @param bipartiteGraphSegmentProvider  is used to generate new segments that are added to the
 *                                       graph
 * @param statsReceiver                  tracks the internal stats
 */
public LeftIndexedMultiSegmentBipartiteGraph(
    int maxNumSegments,
    int maxNumEdgesPerSegment,
    BipartiteGraphSegmentProvider<T> bipartiteGraphSegmentProvider,
    MultiSegmentReaderAccessibleInfoProvider<T> multiSegmentReaderAccessibleInfoProvider,
    StatsReceiver statsReceiver) {
  this.maxNumSegments = maxNumSegments;
  this.maxNumEdgesPerSegment = maxNumEdgesPerSegment;
  this.bipartiteGraphSegmentProvider = bipartiteGraphSegmentProvider;
  this.statsReceiver = statsReceiver.scope("LeftIndexedMultiSegmentBipartiteGraph");
  this.numEdgesSeenInAllHistoryCounter = this.statsReceiver.counter("numEdgesSeenInAllHistory");
  this.multiSegmentReaderAccessibleInfoProvider = multiSegmentReaderAccessibleInfoProvider;
  this.numEdgesInNonLiveSegmentsMap = new Int2IntOpenHashMap(maxNumSegments);
  addNewSegment();
}
 
Example #4
Source File: SetSimilarity.java    From RankSys with Mozilla Public License 2.0 5 votes vote down vote up
private Int2IntMap getIntersectionMap(int idx1) {
    Int2IntOpenHashMap intersectionMap = new Int2IntOpenHashMap();
    intersectionMap.defaultReturnValue(0);

    data.getUidxPreferences(idx1)
            .forEach(ip -> data.getIidxPreferences(ip.v1)
                    .forEach(up -> intersectionMap.addTo(up.v1, 1)));

    intersectionMap.remove(idx1);

    return intersectionMap;
}
 
Example #5
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 #6
Source File: NoDictionarySingleColumnGroupKeyGenerator.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method to create the group-key map, depending on the data type.
 * Uses primitive maps when possible.
 *
 * @param keyType DataType for the key
 * @return Map
 */
private Map createGroupKeyMap(FieldSpec.DataType keyType) {
  Map map;
  switch (keyType) {
    case INT:
      Int2IntMap intMap = new Int2IntOpenHashMap();
      intMap.defaultReturnValue(INVALID_ID);
      map = intMap;
      break;

    case LONG:
      Long2IntOpenHashMap longMap = new Long2IntOpenHashMap();
      longMap.defaultReturnValue(INVALID_ID);
      map = longMap;
      break;

    case FLOAT:
      Float2IntOpenHashMap floatMap = new Float2IntOpenHashMap();
      floatMap.defaultReturnValue(INVALID_ID);
      map = floatMap;
      break;

    case DOUBLE:
      Double2IntOpenHashMap doubleMap = new Double2IntOpenHashMap();
      doubleMap.defaultReturnValue(INVALID_ID);
      map = doubleMap;
      break;

    case STRING:
      Object2IntOpenHashMap<String> stringMap = new Object2IntOpenHashMap<>();
      stringMap.defaultReturnValue(INVALID_ID);
      map = stringMap;
      break;

    default:
      throw new IllegalArgumentException("Illegal data type for no-dictionary key generator: " + keyType);
  }
  return map;
}
 
Example #7
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 #8
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 #9
Source File: StringFunctions.java    From presto with Apache License 2.0 5 votes vote down vote up
@Description("Translate characters from the source string based on original and translations strings")
@ScalarFunction
@LiteralParameters({"x", "y", "z"})
@SqlType(StandardTypes.VARCHAR)
public static Slice translate(@SqlType("varchar(x)") Slice source, @SqlType("varchar(y)") Slice from, @SqlType("varchar(z)") Slice to)
{
    int[] fromCodePoints = castToCodePoints(from);
    int[] toCodePoints = castToCodePoints(to);

    Int2IntOpenHashMap map = new Int2IntOpenHashMap(fromCodePoints.length);
    for (int index = 0; index < fromCodePoints.length; index++) {
        int fromCodePoint = fromCodePoints[index];
        map.putIfAbsent(fromCodePoint, index < toCodePoints.length ? toCodePoints[index] : -1);
    }

    int[] sourceCodePoints = castToCodePoints(source);
    int[] targetCodePoints = new int[sourceCodePoints.length];
    int targetPositions = 0;
    int targetBytes = 0;
    for (int index = 0; index < sourceCodePoints.length; index++) {
        int codePoint = sourceCodePoints[index];
        if (map.containsKey(codePoint)) {
            int translatedCodePoint = map.get(codePoint);
            if (translatedCodePoint == -1) {
                continue;
            }
            codePoint = translatedCodePoint;
        }
        targetCodePoints[targetPositions++] = codePoint;
        targetBytes += lengthOfCodePoint(codePoint);
    }

    Slice target = Slices.allocate(targetBytes);
    int offset = 0;
    for (int index = 0; index < targetPositions; index++) {
        offset += setCodePointAt(targetCodePoints[index], target, offset);
    }

    return target;
}
 
Example #10
Source File: MultiSegmentRandomIterator.java    From GraphJet with Apache License 2.0 5 votes vote down vote up
/**
 * This constructor mirror the one in it's super-class to reuse common code.
 *
 * @param multiSegmentBipartiteGraph  is the underlying {@link
 *                                    LeftIndexedMultiSegmentBipartiteGraph}
 * @param segmentEdgeRandomAccessor   is the accessor for the segments
 */
public MultiSegmentRandomIterator(
    LeftIndexedMultiSegmentBipartiteGraph<T> multiSegmentBipartiteGraph,
    SegmentEdgeRandomAccessor<T> segmentEdgeRandomAccessor) {
  super(multiSegmentBipartiteGraph, segmentEdgeRandomAccessor);
  this.segmentEdgeRandomAccessor = segmentEdgeRandomAccessor;
  // Allocate maximum possible memory for alias table as this is going to be reused
  this.aliasTableArray = IntArrayAliasTable.generateAliasTableArray(
      multiSegmentBipartiteGraph.getMaxNumSegments());
  this.numSamplesInSegment =
      new Int2IntOpenHashMap(multiSegmentBipartiteGraph.getMaxNumSegments());
}
 
Example #11
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 #12
Source File: AnchorIndexer.java    From tagme with Apache License 2.0 5 votes vote down vote up
public AnchorIterator(File inputFile) throws IOException
{
	anchor = null;
	links = new Int2IntOpenHashMap(1024);
	links.defaultReturnValue(0);
	originals = new HashSet<String>(32);
	in = new FastBufferedReader(new InputStreamReader(new FileInputStream(inputFile), Charset.forName("UTF-8")));
	line = new MutableString(1024);
	in.readLine(line);
	lastAnchor = Chars.split(line, TextDataset.SEP_CHAR)[0].toString();
	scroll = 1;
	end = false;
}
 
Example #13
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 #14
Source File: PositionListIndex.java    From metanome-algorithms with Apache License 2.0 5 votes vote down vote up
public PositionListIndex intersect(PositionListIndex otherPLI) {
	Int2IntOpenHashMap hashedPLI = otherPLI.asHashMap();
	Int2ObjectMap<Int2ObjectMap<IntArrayList>> intersectMap = this.buildIntersectMap(this, hashedPLI);
	
	List<IntArrayList> clusters = new ArrayList<>();
	for (Int2ObjectMap<IntArrayList> cluster1 : intersectMap.values())
		for (IntArrayList cluster2 : cluster1.values())
			if (cluster2.size() > 1)
				clusters.add(cluster2);
	
	return new PositionListIndex(-1, clusters);
}
 
Example #15
Source File: JsonUtils.java    From fastjgame with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    Int2IntMap data = new Int2IntOpenHashMap();
    data.put(1, 5);
    data.put(6, 7);

    String json = writeAsJson(data);
    System.out.println("json = " + json);

    Int2IntMap rData = readMapFromJson(json, Int2IntOpenHashMap.class, Integer.class, Integer.class);
    System.out.println("map = " + rData);

    System.out.println("equals = " + data.equals(rData));
}
 
Example #16
Source File: Int2IntBiMap.java    From ViaVersion with MIT License 4 votes vote down vote up
private Int2IntBiMap(Int2IntBiMap inverse) {
    this.map = new Int2IntOpenHashMap();
    this.inverse = inverse;
}
 
Example #17
Source File: Int2IntBiMap.java    From ViaVersion with MIT License 4 votes vote down vote up
public Int2IntBiMap() {
    this.map = new Int2IntOpenHashMap();
    this.inverse = new Int2IntBiMap(this);
}
 
Example #18
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 );
}
 
Example #19
Source File: DictionaryBasedGroupKeyGenerator.java    From incubator-pinot with Apache License 2.0 4 votes vote down vote up
public IntMapBasedHolder(int initialSize) {
  _rawKeyToGroupIdMap = new Int2IntOpenHashMap(initialSize);
  _rawKeyToGroupIdMap.defaultReturnValue(INVALID_ID);
}
 
Example #20
Source File: DictionaryBasedGroupKeyGenerator.java    From incubator-pinot with Apache License 2.0 4 votes vote down vote up
public IntMapBasedHolder(Object hashMap) {
  _rawKeyToGroupIdMap = (Int2IntOpenHashMap) hashMap;
  _rawKeyToGroupIdMap.clear();
}
 
Example #21
Source File: IntToIdMap.java    From incubator-pinot with Apache License 2.0 4 votes vote down vote up
public IntToIdMap() {
  _valueToIdMap = new Int2IntOpenHashMap();
  _valueToIdMap.defaultReturnValue(INVALID_KEY);
  _idToValueMap = new IntArrayList();
}
 
Example #22
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 #23
Source File: MovieUser.java    From jstarcraft-example with Apache License 2.0 4 votes vote down vote up
public MovieUser(int index, String name) {
    this.index = index;
    this.name = name;
    this.clickeds = new Int2IntOpenHashMap();
}
 
Example #24
Source File: BaseIndexedPriorityQueue.java    From incubator-pinot with Apache License 2.0 2 votes vote down vote up
/**
 * Constructor for the class.
 *
 * @param initialCapacity Initial capacity for the priority queue
 * @param minHeap Min order, ie smallest element on top.
 */
public BaseIndexedPriorityQueue(int initialCapacity, boolean minHeap) {
  _minHeap = minHeap;
  _keyToIndexMap = new Int2IntOpenHashMap(initialCapacity);
  _indexToKeyMap = new Int2IntOpenHashMap(initialCapacity);
}