Class BufferWithPages<A>

java.lang.Object
org.aksw.commons.io.buffer.plain.BufferWithPages<A>
Type Parameters:
T -
All Implemented Interfaces:
ArrayReadable<A>, ArrayWritable<A>, BufferLike<A>, HasArrayOps<A>, Buffer<A>, ReadableChannelFactory<A>, ReadableChannelSource<A>, SeekableReadableChannelSource<A>

public class BufferWithPages<A> extends Object implements Buffer<A>
A buffer backed by a mapping of page indices (longs) to arrays. All arrays are the same size. The purpose of this class is to provide a tradeoff between for frequent consecutive small inserts at sparse locations. The map accounts for sparseness, whereas consecutive small inserts will usually update the same array.
Author:
raven
  • Field Details

    • arrayOps

      protected ArrayOps<A> arrayOps
    • pageSize

      protected int pageSize
    • capacity

      protected long capacity
    • map

      protected Map<Long,A> map
  • Constructor Details

    • BufferWithPages

      public BufferWithPages(ArrayOps<A> arrayOps, int pageSize)
    • BufferWithPages

      public BufferWithPages(ArrayOps<A> arrayOps, int pageSize, long capacity, Map<Long,A> map)
  • Method Details

    • getArrayOps

      public ArrayOps<A> getArrayOps()
      Specified by:
      getArrayOps in interface HasArrayOps<A>
    • getPageMap

      public Map<Long,A> getPageMap()
    • create

      public static <A> BufferWithPages<A> create(ArrayOps<A> arrayOps, int pageSize)
    • write

      public void write(long offsetInBuffer, A arrayWithItemsOfTypeT, int arrOffset, int arrLength)
      Description copied from interface: ArrayWritable
      The method that needs to be implemented; all other methods default-delegate to this one.
      Specified by:
      write in interface ArrayWritable<A>
    • readInto

      public int readInto(Object tgt, int tgtOffset, long srcOffset, int length)
      Specified by:
      readInto in interface ArrayReadable<A>
    • getCapacity

      public long getCapacity()
      Description copied from interface: BufferLike
      Buffers with 'unlimited' capacity should return Long.MAX_VALUE
      Specified by:
      getCapacity in interface BufferLike<A>
    • get

      public Object get(long index)
      Specified by:
      get in interface ArrayReadable<A>
    • put

      public void put(long index, Object item)
      Specified by:
      put in interface ArrayWritable<A>