Lines 55-62
public class MemoryMappedArraySupport<T> {
Link Here
|
55 |
createBufferIfNull(i); |
55 |
createBufferIfNull(i); |
56 |
} |
56 |
} |
57 |
|
57 |
|
58 |
ensureExists(initialCapacity - 1); |
|
|
59 |
if (initialCapacity > 0) { |
58 |
if (initialCapacity > 0) { |
|
|
59 |
ensureExists(initialCapacity - 1); |
60 |
// backfill any buffers |
60 |
// backfill any buffers |
61 |
for(int i = 0; i < bufferNumber(initialCapacity - 1); i++) { |
61 |
for(int i = 0; i < bufferNumber(initialCapacity - 1); i++) { |
62 |
createBufferIfNull(i); |
62 |
createBufferIfNull(i); |
Lines 69-75
public class MemoryMappedArraySupport<T> {
Link Here
|
69 |
} |
69 |
} |
70 |
|
70 |
|
71 |
int bufferNumber(int index) { |
71 |
int bufferNumber(int index) { |
72 |
return (int) (((long)index) / (BUFFER_SIZE/sizeOfElement)); |
72 |
int result = (int) (((long)index) / (BUFFER_SIZE/sizeOfElement)); |
|
|
73 |
if (result < 0) { |
74 |
System.out.println("index = " + index + ", buffer_size = " + BUFFER_SIZE + ", sizeOfElement = " + sizeOfElement); |
75 |
} |
76 |
return result; |
73 |
} |
77 |
} |
74 |
|
78 |
|
75 |
public int size() { |
79 |
public int size() { |
Lines 122-131
public class MemoryMappedArraySupport<T> {
Link Here
|
122 |
} |
126 |
} |
123 |
|
127 |
|
124 |
void ensureExists(int index) { |
128 |
void ensureExists(int index) { |
125 |
if (index > maxCapacity) { |
129 |
if (index > maxCapacity || index < 0) { |
126 |
throw new IndexOutOfBoundsException("too many elements for array. index = " + index + ", maxCapacity = " + maxCapacity); |
130 |
throw new IndexOutOfBoundsException("too many elements for array. index = " + index + ", maxCapacity = " + maxCapacity); |
127 |
} |
131 |
} |
128 |
|
132 |
|
|
|
133 |
|
129 |
long requiredLength = (index + 1) * sizeOfElement; |
134 |
long requiredLength = (index + 1) * sizeOfElement; |
130 |
while (requiredLength > fileLength()) { |
135 |
while (requiredLength > fileLength()) { |
131 |
fileSetLength(fileLength() + FILE_EXTEND_LENGTH); |
136 |
fileSetLength(fileLength() + FILE_EXTEND_LENGTH); |
132 |
- |
|
|