question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

improve CursorIterator

See original GitHub issue

Consider making CursorIterator more extensible. It would be reasonable to be able to subclass to provide a range iterator (i.e. a forward iterator that checks an upper bound key, or a reverse iterator checking a lower bound). Since the class is final and tryToComputeNext is private, this is not currently feasible.

Another minor point is that the state machine should probably include a CLOSED state (in which hasNext returns false, and repeated calls to close are idempotent).

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:14 (14 by maintainers)

github_iconTop GitHub Comments

1reaction
benalexaucommented, Jul 15, 2017

I just pushed the final commits. LmdbJava now supports every range type offered by Guava (in both forward and backward cursor directions) and method names now reflect its terminology. There is also an example of using a Guava comparator, plus I added Guava to the ComparatorTest to further validate the project’s comparators against third-party references. Are we happy to close this ticket?

1reaction
benalexaucommented, Jul 14, 2017

The only thing that feels a bit unclear is whether keys are inclusive or exclusive. Ideally we should let users choose for themselves.

I too found the names unclear, which is why I put examples in the KeyRangeType JavaDocs. I intend to add some more KeyRangeType values to cover the exclusive cases.

I suppose that we intend to let users provide their own comparator by overriding the BufferProxy.compare method, right? I think this is good since there are quite a few comparators out there that users might want to use for performance reasons.

Users can provide their own Comparator by invoking CursorIterator<T> Dbi.iterate(Txn<T>, KeyRange<T>, Comparator<T>). Is that sufficient?

Maybe we could add a test using (for example) the lexicographical comparators in UnsignedBytes and SignedBytes?

Good idea. I’ll tackle that tomorrow.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Iterators vs. Cursors: A Case Study in Objects vs. Values
The improvement requires recoding but is incremental in cost, because the code for cursors and iterators is very similar. To benefit from cursors,...
Read more >
design patterns - How to implement a cursor iterator?
The correct approach for the cursor is option 2. The answer is already in your quote, which describes option 2:.
Read more >
Cursor vs Iterator pattern - c++ - Stack Overflow
The Cursor pattern you described is the combination of two patterns: Proxy and Iterator. The reason the standard library is different is to...
Read more >
Iterate over Query Result Sets Using a Cursor - Navicat
Like WHILE loops, cursors allow programmers to process each row of a SELECT result set individually by iterating over them. While many SQL ......
Read more >
Iterators in Java - GeeksforGeeks
A Java Cursor is an Iterator, which is used to iterate or traverse or retrieve a Collection or Stream object's elements one by...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found