@Override public int computeHashCode(SparseIntArray array) { double dp = 0; for (Entry e : array.entries()) dp += r[e.index] * e.value; return dp >= 0 ? 1 : 0; } }
mMaxTextSize = getTextSize(); mAvailableSpaceRect = new RectF(); mTextCachedSizes = new SparseIntArray(); if (mMaxLines == 0) { public void setTextSize(float size) { mMaxTextSize = size; mTextCachedSizes.clear(); adjustTextSize(getText().toString()); mMaxTextSize = TypedValue.applyDimension(unit, size, r.getDisplayMetrics()); mTextCachedSizes.clear(); adjustTextSize(getText().toString()); mTextCachedSizes.clear(); adjustTextSize(getText().toString()); int size = mTextCachedSizes.get(key); if (size != 0) { return size; mTextCachedSizes.put(key, size); return size; protected void onSizeChanged(int width, int height, int oldwidth, int oldheight) { mTextCachedSizes.clear(); super.onSizeChanged(width, height, oldwidth, oldheight);
@Override public SparseIntArray concatenate(SparseIntArray... ins) { final SparseIntArray result = copy(); for (int i=0; i<ins.length; i++) { final int oldLength = result.length; result.setLength(oldLength + ins[i].length); for (Entry e : ins[i].entries()) { result.set(e.index + oldLength, e.value); } } return result; }
/** * Compute the dot product with another vector * @param vector the other vector * @return the dot product */ public double dotProduct(SparseIntArray vector) { double sum = 0; int tused = this.used(); int vused = vector.used(); SparseIntArray smaller = (tused < vused ? this : vector); SparseIntArray larger = (tused < vused ? vector : this); for (Entry e : smaller.entries()) { sum += e.value * larger.get(e.index); } return sum; }
SparseIntArray spa = new SparseIntArray(); public int getColor(int position) { if(spa.get(position) == 0) { spa.put(position, colors[random.nextInt(colors.length)]; return spa.get(position);
if (mapOfButtons.indexOfKey(id) < 0) if (mapOfFilledTextViews.size() == 0) int numberToClear = mapOfFilledTextViews.get(indexToClear); clearButton(numberToClear); clearTextView(indexToClear); if (mapOfFilledTextViews.size() == textView.length) int number = mapOfButtons.get(id); setText(number); int i = mapOfFilledTextViews.indexOfValue(number); int key = mapOfFilledTextViews.keyAt(i); clearButton(number); clearTextView(key); mapOfFilledTextViews = new SparseIntArray(4); mapOfButtons = new SparseIntArray(10); mapOfButtons.put(R.id.button_0, 0); mapOfButtons.put(R.id.button_1, 1); mapOfButtons.put(R.id.button_2, 2); mapOfButtons.put(R.id.button_3, 3); mapOfButtons.put(R.id.button_4, 4); mapOfButtons.put(R.id.button_5, 5); mapOfButtons.put(R.id.button_6, 6); mapOfButtons.put(R.id.button_7, 7);
@Override public int computeHashCode(SparseIntArray array) { return (array.get(dimension) - shift) >= 0 ? 1 : 0; } }
sections = new SparseIntArray(); int m=0; int t = 'A'; int temp = alphabetIndexer.getPositionForSection(i + 1); if (temp != position){ sections.put(position + m, t+i); m++; int temp = alphabetIndexer.getPositionForSection(i-1); if (position != temp){ sections.put(position + m, t+i); cursorPositions = new SparseIntArray(); for (int i=0; i<cursor.getCount() + sections.size(); i++){ if (sections.get(i, -1) != -1){ temp ++; cursorPositions.put(i, -1); } else { cursorPositions.put(i, i - temp); getCursor().moveToPosition(cursorPositions.get(position)); bindView(view, mContext, getCursor(), position); } else if (getItemViewType(position) == SECTION_LIST_VIEW) { bindSectionView(view, mContext, (char)sections.get(position)); } else { if (view == null){
private static SparseIntArray ORIENTATIONS = new SparseIntArray(); static{ ORIENTATIONS.append(Surface.ROTATION_0, 0); ORIENTATIONS.append(Surface.ROTATION_90, 90); ORIENTATIONS.append(Surface.ROTATION_180, 180); ORIENTATIONS.append(Surface.ROTATION_270, 270); } private int sensorToDeviceRotation(CameraCharacteristics cameraCharacteristics, int deviceOrientation){ int sensorOrientation = cameraCharacteristics.get(CameraCharacteristics.SENSOR_ORIENTATION); deviceOrientation = ORIENTATIONS.get(deviceOrientation); return (sensorOrientation + deviceOrientation + 360) % 360; }
@Override public double compare(final SparseIntArray h1, final SparseIntArray h2) { if (h1.length != h2.length) throw new IllegalArgumentException("Vectors have differing lengths"); double d = 0; for (SparseIntArray.DualEntry e : h1.unionEntries(h2)) { d += (e.value * e.otherValue); } return d; } }
@Override public boolean execute(int word, int count) { d.values.set(word, count); return true; } });
/** * Utility method to quickly convert a collection of quantised local * features to a histogram of their corresponding visual word identifiers. * * @param qfeatures * the quantised features. * @param nfeatures * the number of visual words. * @return a histogram of the occurrences of the visual words */ public static <L extends Location> SparseIntFV extractFeatureFromQuantised(Collection<? extends QuantisedLocalFeature<L>> qfeatures, final int nfeatures) { final SparseIntFV fv = new SparseIntFV(nfeatures); for (final QuantisedLocalFeature<L> qf : qfeatures) { fv.values.increment(qf.id, 1); } return fv; }
/** * @return the density of the array (number of used elements divided * by array length) */ public float density() { return (float)used() / (float)length; }
private static final SparseIntArray tagMatcher2 = new SparseIntArray(); private static void put(String key, int value) { tagMatcher2.put(key.hashCode(), value); } private static int get(String key) { return tagMatcher2.get(key.hashCode()); } static { put("tag1", 1); put("tag2", 2); put("tag23", 23); } private void parse2 (String node) { switch (get(node)) { case 1: // etc break; case 0: // no match break; } }
@Override public double getAsDouble(int i) { return values.get(i); }