@Test public void resizeOnlyIfNecessary() { char[] keys = new char[1]; int size = 0; Container[] values = new Container[1]; RoaringArray array = new RoaringArray(keys, values, size); array.extendArray(1); assertSame(keys, array.keys, "Keys were not reallocated"); }
void extendArray(int k) { if (this.size + k > this.keys.length) { int newCapacity; if (this.keys.length < 1024) { newCapacity = 2 * (this.size + k); } else { newCapacity = 5 * (this.size + k) / 4; } this.keys = Arrays.copyOf(this.keys, newCapacity); this.values = Arrays.copyOf(this.values, newCapacity); } }
RoaringArray implements Cloneable, Externalizable, AppendableStorage<Container> { void extendArray(int k) { if (this.size + k > this.keys.length) { int newCapacity; if (this.keys.length < 1024) { newCapacity = 2 * (this.size + k); } else { newCapacity = 5 * (this.size + k) / 4; } this.keys = Arrays.copyOf(this.keys, newCapacity); this.values = Arrays.copyOf(this.values, newCapacity); } } }
RoaringArray implements Cloneable, Externalizable, AppendableStorage<Container> { void extendArray(int k) { if (this.size + k > this.keys.length) { int newCapacity; if (this.keys.length < 1024) { newCapacity = 2 * (this.size + k); } else { newCapacity = 5 * (this.size + k) / 4; } this.keys = Arrays.copyOf(this.keys, newCapacity); this.values = Arrays.copyOf(this.values, newCapacity); } } protected  RoaringArray();   RoaringArray(int initialCapacity);   RoaringArray(char[] keys, Container[] values, int size); }
RoaringArray implements Cloneable, Externalizable, AppendableStorage<Container> { void extendArray(int k) { if (this.size + k > this.keys.length) { int newCapacity; if (this.keys.length < 1024) { newCapacity = 2 * (this.size + k); } else { newCapacity = 5 * (this.size + k) / 4; } this.keys = Arrays.copyOf(this.keys, newCapacity); this.values = Arrays.copyOf(this.values, newCapacity); } } protected  RoaringArray();   RoaringArray(int initialCapacity);   RoaringArray(char[] keys, Container[] values, int size); @Override void append(char key, Container value); void trim(); @Override RoaringArray clone(); void deserialize(DataInput in); void deserialize(DataInput in, byte[] buffer); void deserialize(ByteBuffer bbf); @Override boolean equals(Object o); ContainerPointer getContainerPointer(); ContainerPointer getContainerPointer(final int startIndex); @Override int hashCode(); @Override void readExternal(ObjectInput in); void serialize(DataOutput out); void serialize(ByteBuffer buffer); int serializedSizeInBytes(); @Override void writeExternal(ObjectOutput out); int first(); int last(); }
RoaringArray implements Cloneable, Externalizable, AppendableStorage<Container> { void extendArray(int k) { if (this.size + k > this.keys.length) { int newCapacity; if (this.keys.length < 1024) { newCapacity = 2 * (this.size + k); } else { newCapacity = 5 * (this.size + k) / 4; } this.keys = Arrays.copyOf(this.keys, newCapacity); this.values = Arrays.copyOf(this.values, newCapacity); } } protected  RoaringArray();   RoaringArray(int initialCapacity);   RoaringArray(char[] keys, Container[] values, int size); @Override void append(char key, Container value); void trim(); @Override RoaringArray clone(); void deserialize(DataInput in); void deserialize(DataInput in, byte[] buffer); void deserialize(ByteBuffer bbf); @Override boolean equals(Object o); ContainerPointer getContainerPointer(); ContainerPointer getContainerPointer(final int startIndex); @Override int hashCode(); @Override void readExternal(ObjectInput in); void serialize(DataOutput out); void serialize(ByteBuffer buffer); int serializedSizeInBytes(); @Override void writeExternal(ObjectOutput out); int first(); int last();  }