Search code examples
androidsnappydb

What does byBatch(size) mean in SnappyDB?


for (String[] batch : snappyDB.allKeysIterator().byBatch(0))

What does 'size' param mean in byBatch() method?


Solution

  • Without using byBatch you will only have a KeyIterator which does not implement Iterator or Iterable so you can't use it in a loop.

    byBatch(n) creates a BatchIterable which is Iterable and an Iterator. It basically just calls next(n) on the KeyIterator when you call next() on it. (Source)

    KeyIterator#next(int max) seems to always attempt to fetch max elements from the Database. So I presume you will most likely have max elements in the batch array from your example on each iteration. So it doesn't make much sense to pass 0 as you're doing (not sure if that even works).


    Also just reading the README from the GitHub repo reveals some documentation:

    Iterable<String[]> byBatch(int size); // Get an iterable of key batch, each batch of maximum [size] keys.