pmem / pmemkv

Key/Value Datastore for Persistent Memory
https://pmem.io
Other
398 stars 119 forks source link

Why does pmemkv's iterator not support valid? #1050

Closed yunxiao3 closed 2 years ago

yunxiao3 commented 2 years ago

QUESTION:

Details

Why does pmemkv's iterator not support valid? Is there a good way to implement this function, except do while. I think it is very troublesome for the upper layer to call the iterator without the valid API

igchor commented 2 years ago

We felt that having next/seek_* methods return status would be sufficient. There's nothing preventing us from implementing valid() method.

It's true that there's a bit of boilerplate code when using iterators with do/while loop but you can use for loop instead, for example: for (auto s = it.seek_to_first(); s == status::OK; s = it.next())

If you have some other use case where using valid() would be preferred please let us know. Also, if would like to provide a patch with the implementation of a valid() method that would be very much welcomed :)

lukaszstolarczuk commented 2 years ago

Hi @yunxiao3, it's been some time since you opened this question, did you have any thoughts or follow-up comments/questions?

yunxiao3 commented 2 years ago

thx