Reputation: 671
for (String[] batch : snappyDB.allKeysIterator().byBatch(0))
What does 'size' param mean in byBatch() method?
Upvotes: 0
Views: 47
Reputation: 803
According to SnappyDB documentation, found here:
Iterable<String[]> byBatch(int size);// Get an iterable of key batch, each batch of maximum [size] keys.
So size specifies the maximum number of keys for each batch. However, according to the documentation:
Please note that you should use the byBatch iterable to process all keys only on large collections. On reasonably small collections, using the array based APIs (findKeys and findKeysBetween) with the form for (String key : db.findKeys("android")) is a lot more efficient. Iterators should only be used to process large collections or for collection paging view / access.
So make sure that you really need byBatch in your use case.
Upvotes: 0
Reputation: 4544
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.
Upvotes: 0