Class DiskBackedList

java.lang.Object
io.karatelabs.match.DiskBackedList
All Implemented Interfaces:
LargeValueStore, Closeable, AutoCloseable

public class DiskBackedList extends Object implements LargeValueStore
A disk-backed list implementation for handling large collections without exhausting memory. Items are serialized as JSON lines to a temporary file.
  • Method Details

    • create

      public static DiskBackedList create(Iterable<?> source) throws IOException
      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

      public static long estimateSize(Object obj)
      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

      public static long estimateCollectionSize(List<?> list)
      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: LargeValueStore
      Returns the number of elements in this store.
      Specified by:
      size in interface LargeValueStore
    • get

      public Object get(int index)
      Description copied from interface: LargeValueStore
      Returns the element at the specified index.
      Specified by:
      get in interface LargeValueStore
      Parameters:
      index - the index of the element to return
      Returns:
      the element at the specified position
    • iterator

      public Iterator<Object> iterator()
      Description copied from interface: LargeValueStore
      Returns an iterator over the elements in this store.
      Specified by:
      iterator in interface LargeValueStore
    • close

      public void close()
      Description copied from interface: LargeValueStore
      Closes this store and releases any associated resources (e.g., temp files).
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface LargeValueStore