Comments (4)
@ohenepee as far as i understand you need to move iterator to the next at the end of the loop. What's happening now:
x x x
^
iterator.valid? # => true
iterator.next # => moves to the second value
iterator.key # => second key
x x x
^
iterator.valid? # => true
iterator.next # => moves to the third value
iterator.key # => third key
x x x
^
iterator.valid? # => true
iterator.next # => moves to the invalid pointer
iterator.key # => Invalid memory access
from leveldb.
Yes! You're right, I just needed to move the iterator.next
below the puts
. Thanks also for your awesome elaboration on the subject.
while iterator.valid?
puts "#{iterator.key} - #{iterator.value}"
iterator.next
end
iterator.destroy
It works now without giving the INVALID ACCESS TO MEMORY error, however it still reads the whole database even though I explicitly asked the iterator to seek for a particular key prefix... unless perhaps I don't know how the iterator is supposed to work in this case, then I suppose its a bug.
In the example I gave in the first comment, if I ask the iterator ro seek for "messages"
, should it also print entries keyed with "locations"
and "something"
?
from leveldb.
That's how leveldb works. Using a seek you find a start point for the iterator and it will iterate till the end (having the lexicographic order).
To filter only needed entries, you can stop when the first key with a wrong prefix occurs and break the loop:
iterator = LevelDB::Iterator.new(db)
iterator.seek("messages")
while iterator.valid?
break unless iterator.key.starts_with?("messages")
puts "#{iterator.key} - #{iterator.value}"
iterator.next
end
iterator.seek("something")
...
iterator.destroy
Related reading: https://groups.google.com/forum/#!topic/leveldb/DRj0-t1hJ08
from leveldb.
You couldn't be more helpful... thanks a lot and stay blessed!
from leveldb.
Related Issues (3)
- Can't resolve 0.2.0 HOT 1
- Is This Project Dead? HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from leveldb.