mirror of
https://github.com/MarginaliaSearch/MarginaliaSearch.git
synced 2025-02-24 05:18:58 +00:00
(array) Don't use paging arrays when mapping small files for writing
This commit is contained in:
parent
a6f1335375
commit
f74b9df0a7
@ -43,10 +43,19 @@ public interface LongArray extends LongArrayBase, LongArrayTransformations, Long
|
||||
|
||||
/** Map an existing file for writing */
|
||||
static LongArray mmapForModifying(Path path) throws IOException {
|
||||
return PagingLongArray.mapFileReadWrite(DEFAULT_PARTITIONING_SCHEME, path);
|
||||
long sizeBytes = Files.size(path);
|
||||
assert sizeBytes % WORD_SIZE == 0;
|
||||
|
||||
long size = sizeBytes / WORD_SIZE;
|
||||
|
||||
return mmapForWriting(path, size);
|
||||
}
|
||||
|
||||
static LongArray mmapForWriting(Path path, long size) throws IOException {
|
||||
if (size < MAX_CONTINUOUS_SIZE) {
|
||||
return LongArrayPage.fromMmapReadWrite(path, 0, (int) size);
|
||||
}
|
||||
|
||||
return PagingLongArray.mapFileReadWrite(DEFAULT_PARTITIONING_SCHEME, path, size);
|
||||
}
|
||||
|
||||
|
@ -62,25 +62,6 @@ public class PagingLongArray extends AbstractPagingArray<LongArrayPage, LongBuff
|
||||
return new PagingLongArray(partitioningScheme, pages, size);
|
||||
}
|
||||
|
||||
public static PagingLongArray mapFileReadWrite(ArrayPartitioningScheme partitioningScheme, Path file)
|
||||
throws IOException
|
||||
{
|
||||
long sizeBytes = Files.size(file);
|
||||
assert sizeBytes % WORD_SIZE == 0;
|
||||
|
||||
long size = sizeBytes / WORD_SIZE;
|
||||
|
||||
LongArrayPage[] pages = new LongArrayPage[partitioningScheme.getPartitions(size)];
|
||||
long offset = 0;
|
||||
for (int i = 0; i < pages.length; i++) {
|
||||
int partitionSize = partitioningScheme.getRequiredPageSize(i, size);
|
||||
pages[i] = LongArrayPage.fromMmapReadWrite(file, offset, partitionSize);
|
||||
offset += partitionSize;
|
||||
}
|
||||
|
||||
return new PagingLongArray(partitioningScheme, pages, size);
|
||||
}
|
||||
|
||||
public static PagingLongArray mapFileReadWrite(ArrayPartitioningScheme partitioningScheme, Path file, long size)
|
||||
throws IOException
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user