Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache enumeration #1

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions LevelBits/LBDB.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,7 @@ extern NSString *LBLevelErrorDomain;
- (id <NSCoding>)objectForKey:(NSString *)key error:(NSError **)error;
- (BOOL)setObject:(id <NSCoding>)value forKey:(NSString *)key error:(NSError **)error;
- (BOOL)removeObjectForKey:(NSString *)key error:(NSError **)error;
- (void)enumerateKeysAndValuesUsingBlock:(void (^)(id key, id<NSCoding> value, BOOL *stop))block;
- (void)compact;

@end
26 changes: 26 additions & 0 deletions LevelBits/LBDB.mm
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,32 @@ - (void)dealloc
[super dealloc];
}

- (void)enumerateKeysAndValuesUsingBlock:(void (^)(id, id<NSCoding>, BOOL *))block;
{
leveldb::ReadOptions options;
leveldb::Iterator *iter = db_->NewIterator(options);
iter->SeekToFirst();

while (iter->Valid())
{
leveldb::Slice k = iter->key();
leveldb::Slice v = iter->value();
BOOL stop = NO;

block(lb_string_for_slice(k), lb_object_for_slice(v), &stop);
if (stop) break;

iter->Next();
}

delete iter;
}

- (void)compact;
{
db_->CompactRange(NULL, NULL);
}

- (BOOL)setObject:(id <NSCoding>)value forKey:(NSString *)key error:(NSError **)error;
{
return [self store:lb_slice_for_object(value) forKey:lb_slice_for_string(key) error:error];
Expand Down
Binary file modified Library/libleveldb.a
Binary file not shown.
2 changes: 1 addition & 1 deletion Vendor/leveldb
Submodule leveldb updated from 239ac9 to dd0d56