Skip to content

Commit

Permalink
Step 1: resize() should work for capacity 0.
Browse files Browse the repository at this point in the history
  • Loading branch information
tommyettinger committed Dec 29, 2023
1 parent 8fa8ffd commit 244a129
Show file tree
Hide file tree
Showing 9 changed files with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ protected void resize (int newSize) {
final int head = this.head;
final int tail = this.tail;

final boolean[] newArray = new boolean[newSize];
final boolean[] newArray = new boolean[Math.max(1, newSize)];
if (head < tail) {
// Continuous
System.arraycopy(values, head, newArray, 0, tail - head);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/github/tommyettinger/ds/ByteDeque.java
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ protected void resize (int newSize) {
final int head = this.head;
final int tail = this.tail;

final byte[] newArray = new byte[newSize];
final byte[] newArray = new byte[Math.max(1, newSize)];
if (head < tail) {
// Continuous
System.arraycopy(values, head, newArray, 0, tail - head);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/github/tommyettinger/ds/CharDeque.java
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ protected void resize (int newSize) {
final int head = this.head;
final int tail = this.tail;

final char[] newArray = new char[newSize];
final char[] newArray = new char[Math.max(1, newSize)];
if (head < tail) {
// Continuous
System.arraycopy(values, head, newArray, 0, tail - head);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/github/tommyettinger/ds/DoubleDeque.java
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ protected void resize (int newSize) {
final int head = this.head;
final int tail = this.tail;

final double[] newArray = new double[newSize];
final double[] newArray = new double[Math.max(1, newSize)];
if (head < tail) {
// Continuous
System.arraycopy(values, head, newArray, 0, tail - head);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/github/tommyettinger/ds/FloatDeque.java
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ protected void resize (int newSize) {
final int head = this.head;
final int tail = this.tail;

final float[] newArray = new float[newSize];
final float[] newArray = new float[Math.max(1, newSize)];
if (head < tail) {
// Continuous
System.arraycopy(values, head, newArray, 0, tail - head);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/github/tommyettinger/ds/IntDeque.java
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ protected void resize (int newSize) {
final int head = this.head;
final int tail = this.tail;

final int[] newArray = new int[newSize];
final int[] newArray = new int[Math.max(1, newSize)];
if (head < tail) {
// Continuous
System.arraycopy(values, head, newArray, 0, tail - head);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/github/tommyettinger/ds/LongDeque.java
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ protected void resize (int newSize) {
final int head = this.head;
final int tail = this.tail;

final long[] newArray = new long[newSize];
final long[] newArray = new long[Math.max(1, newSize)];
if (head < tail) {
// Continuous
System.arraycopy(values, head, newArray, 0, tail - head);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/github/tommyettinger/ds/ShortDeque.java
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ protected void resize (int newSize) {
final int head = this.head;
final int tail = this.tail;

final short[] newArray = new short[newSize];
final short[] newArray = new short[Math.max(1, newSize)];
if (head < tail) {
// Continuous
System.arraycopy(values, head, newArray, 0, tail - head);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ public void testObjectEmpty() {

ObjectDeque<String> deque = new ObjectDeque<>(0);
deque.add("START");
deque.remove();
deque.addAll(list);
deque.addAll(names);
Assert.assertEquals(targetLength, deque.size());

ObjectSet<String> set = new ObjectSet<>(0);
Expand Down

0 comments on commit 244a129

Please sign in to comment.