byBatch(size) 在 SnappyDB 中是什么意思?

What does byBatch(size) mean in SnappyDB?

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

byBatch()方法中的'size'参数是什么意思?

如果不使用 byBatch,您将只有一个 KeyIterator,它没有实现 IteratorIterable,因此您不能在循环中使用它。

byBatch(n) 创建一个 BatchIterable,即 Iterable 和一个 Iterator。当您在其上调用 next() 时,它基本上只是在 KeyIterator 上调用 next(n)。 (Source)

KeyIterator#next(int max) 似乎总是试图从数据库中获取 max 元素。因此,我认为您很可能会在每次迭代的示例中的 batch 数组中包含 max 元素。因此,像您所做的那样传递 0 没有多大意义(不确定是否有效)。


另外,只要阅读 GitHub 存储库中的自述文件,就会发现 some documentation:

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

根据SnappyDB文档,发现here:

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

因此 size 指定了每个批次的最大键数。但是,根据文档:

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.

因此请确保在您的用例中确实需要 byBatch。