/** {@inheritDoc} */ public void putAll( Map<? extends Integer, ? extends Long> map ) { ensureCapacity( map.size() ); // could optimize this for cases when map instanceof THashMap for ( Map.Entry<? extends Integer, ? extends Long> entry : map.entrySet() ) { this.put( entry.getKey().intValue(), entry.getValue().longValue() ); } }
/** {@inheritDoc} */ @Override public boolean equals( Object other ) { if ( ! ( other instanceof TIntLongMap ) ) { return false; } TIntLongMap that = ( TIntLongMap ) other; if ( that.size() != this.size() ) { return false; } long[] values = _values; byte[] states = _states; long this_no_entry_value = getNoEntryValue(); long that_no_entry_value = that.getNoEntryValue(); for ( int i = values.length; i-- > 0; ) { if ( states[i] == FULL ) { int key = _set[i]; long that_value = that.get( key ); long this_value = values[i]; if ( ( this_value != that_value ) && ( this_value != this_no_entry_value ) && ( that_value != that_no_entry_value ) ) { return false; } } } return true; }
protected void searchPoiByName(PoiRegion region, SearchRequest<Amenity> req) throws IOException { TIntLongHashMap offsets = new TIntLongHashMap(); String query = normalizeSearchPoiByNameQuery(req.nameQuery); CollatorStringMatcher matcher = new CollatorStringMatcher(query, case OsmandOdb.OsmAndPoiIndex.POIDATA_FIELD_NUMBER: Integer[] offKeys = new Integer[offsets.size()]; if (offsets.size() > 0) { int[] keys = offsets.keys(); for (int i = 0; i < keys.length; i++) { offKeys[i] = keys[i];
/** {@inheritDoc} */ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { // VERSION in.readByte(); // SUPER super.readExternal( in ); // NUMBER OF ENTRIES int size = in.readInt(); setUp( size ); // ENTRIES while (size-- > 0) { int key = in.readInt(); long val = in.readLong(); put(key, val); } } } // TIntLongHashMap
/** {@inheritDoc} */ public int[] keys() { int[] keys = new int[size()]; int[] k = _set; byte[] states = _states; for ( int i = k.length, j = 0; i-- > 0; ) { if ( states[i] == FULL ) { keys[j++] = k[i]; } } return keys; }
private void startQueryFor(int k) { final double width = 1d / (5d*64d); final double dev = width/2d; final double mass = k * width + dev; final Set<MolecularFormula> formulas = query.findMolecularFormulasByMass(mass, dev + 1e-5); LoggerFactory.getLogger(this.getClass()).error("START QUERY FROM " + (mass-dev) + " TO " + (mass+dev)); shortLock.startWriting(); covered.put(k/64, covered.get(k/64) | (1l<<(k%64))); ++changes; try { for (MolecularFormula f : formulas) { known.add(f); } } finally { shortLock.finishWriting(); } }
@Override public SparseLongArray reverse() { //TODO: this could be more efficient and avoid the copy TIntLongHashMap tmp = new TIntLongHashMap(data.size()); for (Entry e : entries()) tmp.put(length - e.index, e.value); this.data = tmp; return this; } }
TIntLongHashMap mp = new TIntLongHashMap(); for (int j = 0; j < list.size(); j++) { mp.put(list.get(j), listContainer.get(j)); int contOffset = (int) mp.get(offset); codedIS.seek(contOffset); int len = codedIS.readRawVarint32();
List<Resource> result = new ArrayList<Resource>(rootCheckTimeMap.size()); long now = System.currentTimeMillis(); Long lastCheckTime = rootCheckTimeMap.get(r.getId()); if (null == lastCheckTime || lastCheckTime <= now - (checkPeriod * 1000)) { result.add(r); ((null != lastCheckTime) ? lastCheckTime : Long.valueOf(0L))); rootCheckTimeMap.clear(); rootCheckTimeMap.putAll(tempRootCheckTimeMap);
TIntLongHashMap offsetsMap = new TIntLongHashMap(); while (true) { if (req.isCancelled()) { break; case OsmandOdb.OsmAndPoiIndex.POIDATA_FIELD_NUMBER: int[] offsets = offsetsMap.keys(); + offsets.length + " subtrees"); for (int j = 0; j < offsets.length; j++) { long skipVal = offsetsMap.get(offsets[j]); if (skipTiles != null && skipVal != -1) { int dzoom = ZOOM_TO_SKIP_FILTER_READ - ZOOM_TO_SKIP_FILTER;
private TIntLongHashMap readPoiNameIndex(Collator instance, String query, SearchRequest<Amenity> req) throws IOException { TIntLongHashMap offsets = new TIntLongHashMap(); TIntArrayList dataOffsets = null; int offset = 0;
public void finish() throws IOException { body.close(); info("wrote " + bodyOffset + " bytes in body of matrix"); // write offset file info("generating header"); int sizeHeader = 16 + rowOffsets.size() * (4 + 8); body = new BufferedOutputStream(new FileOutputStream(path)); body.write(intToBytes(SparseMatrix.FILE_HEADER)); body.write(floatToBytes(vconf.minScore)); body.write(floatToBytes(vconf.maxScore)); body.write(intToBytes(rowOffsets.size())); // Next write row indexes in sorted order (4 bytes per row) int sortedIndexes[] = rowIndexes.toArray(); Arrays.sort(sortedIndexes); for (int rowIndex : sortedIndexes) { body.write(intToBytes(rowIndex)); } // Next write offsets for sorted indexes. (8 bytes per row) for (int rowIndex : sortedIndexes) { long rowOffset = rowOffsets.get(rowIndex); body.write(longToBytes(rowOffset + sizeHeader)); } InputStream r = new FileInputStream(bodyPath); // append other file IOUtils.copyLarge(r, body); r.close(); body.flush(); body.close(); info("wrote " + FileUtils.sizeOf(path) + " bytes to " + path); }
@Override public AdjustedRandomIndexAnalysis analyse(int[][] correct, int[][] estimated) { TIntLongHashMap nij = new TIntLongHashMap(); TIntLongHashMap ni = new TIntLongHashMap(); TIntLongHashMap nj = new TIntLongHashMap(); int i = invCor.get(index); int j = invEst.get(index); nij.adjustOrPutValue(i * correct.length + j, 1, 1); ni.adjustOrPutValue(i, 1, 1); nj.adjustOrPutValue(j, 1, 1); final long[] sumn = new long[1]; nj.forEachEntry(new TIntLongProcedure() { ni.forEachEntry(new TIntLongProcedure() { nij.forEachEntry(new TIntLongProcedure() {
/** * Creates a new <code>TIntLongHashMap</code> instance containing * all of the entries in the map passed in. * * @param keys a <tt>int</tt> array containing the keys for the matching values. * @param values a <tt>long</tt> array containing the values. */ public TIntLongHashMap( int[] keys, long[] values ) { super( Math.max( keys.length, values.length ) ); int size = Math.min( keys.length, values.length ); for ( int i = 0; i < size; i++ ) { this.put( keys[i], values[i] ); } }
/** {@inheritDoc} */ public int[] toArray() { return TIntLongHashMap.this.keys(); }
/** {@inheritDoc} */ public boolean containsAll( int[] array ) { for ( int element : array ) { if ( ! TIntLongHashMap.this.contains( element ) ) { return false; } } return true; }
/** {@inheritDoc} */ public boolean containsAll( Collection<?> collection ) { for ( Object element : collection ) { if ( element instanceof Integer ) { int ele = ( ( Integer ) element ).intValue(); if ( ! TIntLongHashMap.this.containsKey( ele ) ) { return false; } } else { return false; } } return true; }
/** {@inheritDoc} */ public void clear() { TIntLongHashMap.this.clear(); }
public void store(final OutputStream stream) throws IOException { final BufferedOutputStream buffered = (stream instanceof BufferedOutputStream) ? (BufferedOutputStream)stream : new BufferedOutputStream(stream); final DataOutputStream outstream = new DataOutputStream(buffered); outstream.writeUTF(database.name()); outstream.writeInt(covered.size()); try { covered.forEachEntry(new TIntLongProcedure() { @Override public boolean execute(int a, long b) { try { outstream.writeInt(a); outstream.writeLong(b); } catch (IOException e) { throw new RuntimeException(); } return true; } }); } catch (RuntimeException e) { final Throwable t = e.getCause(); if (t != null && t instanceof IOException) throw (IOException)t; else throw e; } outstream.flush(); known.store(buffered); }
/** {@inheritDoc} */ @Override public String toString() { final StringBuilder buf = new StringBuilder( "{" ); forEachEntry( new TIntLongProcedure() { private boolean first = true; public boolean execute( int key, long value ) { if ( first ) first = false; else buf.append( ", " ); buf.append(key); buf.append("="); buf.append(value); return true; } }); buf.append( "}" ); return buf.toString(); }