Package io.karatelabs.match
Class DiskBackedList
java.lang.Object
io.karatelabs.match.DiskBackedList
- All Implemented Interfaces:
LargeValueStore,Closeable,AutoCloseable
A disk-backed list implementation for handling large collections without
exhausting memory. Items are serialized as JSON lines to a temporary file.
-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes this store and releases any associated resources (e.g., temp files).static DiskBackedListCreates a DiskBackedList from an iterable source.static longestimateCollectionSize(List<?> list) Estimates the total memory size of a list using random sampling.static longestimateSize(Object obj) Estimates the memory size of an object in bytes.get(int index) Returns the element at the specified index.iterator()Returns an iterator over the elements in this store.intsize()Returns the number of elements in this store.
-
Method Details
-
create
Creates a DiskBackedList from an iterable source.- Parameters:
source- the source iterable to store- Returns:
- a new DiskBackedList containing all items from the source
- Throws:
IOException- if an I/O error occurs
-
estimateSize
Estimates the memory size of an object in bytes. This is a rough estimate for determining whether to use disk storage.- Parameters:
obj- the object to estimate- Returns:
- estimated size in bytes
-
estimateCollectionSize
Estimates the total memory size of a list using random sampling. For lists with more than SAMPLE_SIZE items, samples 5 random items and extrapolates.- Parameters:
list- the list to estimate- Returns:
- estimated size in bytes
-
size
public int size()Description copied from interface:LargeValueStoreReturns the number of elements in this store.- Specified by:
sizein interfaceLargeValueStore
-
get
Description copied from interface:LargeValueStoreReturns the element at the specified index.- Specified by:
getin interfaceLargeValueStore- Parameters:
index- the index of the element to return- Returns:
- the element at the specified position
-
iterator
Description copied from interface:LargeValueStoreReturns an iterator over the elements in this store.- Specified by:
iteratorin interfaceLargeValueStore
-
close
public void close()Description copied from interface:LargeValueStoreCloses this store and releases any associated resources (e.g., temp files).- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceLargeValueStore
-