@Override public int countUnique() { ByteSet count = new ByteOpenHashSet(3); for (byte next : data) { count.add(next); } return count.size(); }
@Override public Selection selectIsIn(String... strings) { ByteOpenHashSet keys = new ByteOpenHashSet(); for (String string : strings) { byte key = getKeyForValue(string); if (key != DEFAULT_RETURN_VALUE) { keys.add(key); } } Selection results = new BitmapBackedSelection(); for (int i = 0; i < values.size(); i++) { if (keys.contains(values.getByte(i))) { results.add(i); } } return results; }
@Override public boolean addAll(Collection<? extends Byte> c) { // The resulting collection will be at least c.size() big if (f <= .5) ensureCapacity(c.size()); // The resulting collection will be sized for c.size() elements else tryCapacity(size() + c.size()); // The resulting collection will be tentatively sized for size() + c.size() // elements return super.addAll(c); } @Override
/** * Creates a new hash set and fills it with the elements of a given array. * * @param a * an array whose elements will be used to fill the set. * @param offset * the first element to use. * @param length * the number of elements to use. * @param f * the load factor. */ public ByteOpenHashSet(final byte[] a, final int offset, final int length, final float f) { this(length < 0 ? 0 : length, f); ByteArrays.ensureOffsetLength(a, offset, length); for (int i = 0; i < length; i++) add(a[offset + i]); } /**
/** * Creates a new hash set copying a given collection. * * @param c * a {@link Collection} to be copied into the new hash set. * @param f * the load factor. */ public ByteOpenHashSet(final Collection<? extends Byte> c, final float f) { this(c.size(), f); addAll(c); } /**
/** * Returns a hash code for this set. * * This method overrides the generic method provided by the superclass. Since * {@code equals()} is not overriden, it is important that the value returned by * this method is the same value as the one returned by the overriden method. * * @return a hash code for this set. */ @Override public int hashCode() { int h = 0; for (int j = realSize(), i = 0; j-- != 0;) { while (((key[i]) == ((byte) 0))) i++; h += (key[i]); i++; } // Zero / null have hash zero. return h; } private void writeObject(java.io.ObjectOutputStream s) throws java.io.IOException {
private void writeObject(java.io.ObjectOutputStream s) throws java.io.IOException { final ByteIterator i = iterator(); s.defaultWriteObject(); for (int j = size; j-- != 0;) s.writeByte(i.nextByte()); }
@Override public boolean addAll(ByteCollection c) { if (f <= .5) ensureCapacity(c.size()); // The resulting collection will be sized for c.size() elements else tryCapacity(size() + c.size()); // The resulting collection will be tentatively sized for size() + c.size() // elements return super.addAll(c); } @Override
/** * Creates a new hash set using elements provided by a type-specific iterator. * * @param i * a type-specific iterator whose elements will fill the set. * @param f * the load factor. */ public ByteOpenHashSet(final ByteIterator i, final float f) { this(DEFAULT_INITIAL_SIZE, f); while (i.hasNext()) add(i.nextByte()); } /**
/** * Creates a new hash set copying a given type-specific collection. * * @param c * a type-specific collection to be copied into the new hash set. * @param f * the load factor. */ public ByteOpenHashSet(final ByteCollection c, final float f) { this(c.size(), f); addAll(c); } /**
/** * Rehashes the set. * * <p> * This method implements the basic rehashing strategy, and may be overriden by * subclasses implementing different rehashing strategies (e.g., disk-based * rehashing). However, you should not override this method unless you * understand the internal workings of this class. * * @param newN * the new size */ protected void rehash(final int newN) { final byte key[] = this.key; final int mask = newN - 1; // Note that this is used by the hashing macro final byte newKey[] = new byte[newN + 1]; int i = n, pos; for (int j = realSize(); j-- != 0;) { while (((key[--i]) == ((byte) 0))); if (!((newKey[pos = (it.unimi.dsi.fastutil.HashCommon.mix((key[i]))) & mask]) == ((byte) 0))) while (!((newKey[pos = (pos + 1) & mask]) == ((byte) 0))); newKey[pos] = key[i]; } n = newN; this.mask = mask; maxFill = maxFill(n, f); this.key = newKey; } /**
@Override public BooleanColumn unique() { ByteSet count = new ByteOpenHashSet(3); for (byte next : data) { count.add(next); } ByteArrayList list = new ByteArrayList(count); return new BooleanColumn(name() + " Unique values", list); }
@Override public Selection selectIsIn(Collection<String> strings) { ByteOpenHashSet keys = new ByteOpenHashSet(); for (String string : strings) { byte key = getKeyForValue(string); if (key != DEFAULT_RETURN_VALUE) { keys.add(key); } } Selection results = new BitmapBackedSelection(); for (int i = 0; i < values.size(); i++) { if (keys.contains(values.getByte(i))) { results.add(i); } } return results; }
@Override public int countUnique() { ByteSet count = new ByteOpenHashSet(3); for (byte next : data) { count.add(next); } return count.size(); }
@Override public Selection selectIsIn(Collection<String> strings) { ByteOpenHashSet keys = new ByteOpenHashSet(); for (String string : strings) { byte key = getKeyForValue(string); if (key != DEFAULT_RETURN_VALUE) { keys.add(key); } } Selection results = new BitmapBackedSelection(); for (int i = 0; i < values.size(); i++) { if (keys.contains(values.getByte(i))) { results.add(i); } } return results; }
@Override public int countUnique() { ByteSet count = new ByteOpenHashSet(3); for (byte next : data) { count.add(next); } return count.size(); }
@Override public Selection selectIsIn(String... strings) { ByteOpenHashSet keys = new ByteOpenHashSet(); for (String string : strings) { byte key = getKeyForValue(string); if (key != DEFAULT_RETURN_VALUE) { keys.add(key); } } Selection results = new BitmapBackedSelection(); for (int i = 0; i < values.size(); i++) { if (keys.contains(values.getByte(i))) { results.add(i); } } return results; }
return new ShortOpenHashSet(set); } else if (oCls.equals(Byte.class)) { return new ByteOpenHashSet(set); } else if (oCls.equals(Long.class)) { return new LongOpenHashSet(set);
@Override public BooleanColumn unique() { ByteSet count = new ByteOpenHashSet(3); for (byte next : data) { count.add(next); } ByteArrayList list = new ByteArrayList(count); return new BooleanColumn(name() + " Unique values", list); }
@Override public BooleanColumn unique() { ByteSet count = new ByteOpenHashSet(3); for (byte next : data) { count.add(next); } ByteArrayList list = new ByteArrayList(count); return new BooleanColumn(name() + " Unique values", list); }