This repository has been archived by the owner on Oct 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: new wrapper class for leveldb iterator
- Loading branch information
1 parent
d9eb52d
commit 402b5ce
Showing
6 changed files
with
204 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#ifndef Header_h | ||
#define Header_h | ||
|
||
@interface LvDBIterator : NSObject | ||
|
||
- (id)initFromIterator:(void *)dbIterator; | ||
- (void)destroy; | ||
|
||
- (void)seekToFirst; | ||
- (void)seekToLast; | ||
- (void)seek:(NSData *)key; | ||
- (void)next; | ||
- (void)prev; | ||
- (BOOL)valid; | ||
- (NSData *)key; | ||
- (NSData *)value; | ||
|
||
@end | ||
|
||
#endif /* Header_h */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#import "LvDB.h" | ||
#import "LvDBIterator.h" | ||
|
||
#import <iostream> | ||
#import <memory> | ||
#import "leveldb/db.h" | ||
|
||
@implementation LvDBIterator | ||
|
||
std::unique_ptr<leveldb::Iterator> iterator; | ||
|
||
- (id)initFromIterator:(void *)dbIterator { | ||
if (self = [super init]) { | ||
std::cout << "[LvDBWrapper] Iterator generated." << std::endl; | ||
leveldb::Iterator* it = static_cast<leveldb::Iterator*>(dbIterator); | ||
iterator.reset(it); | ||
} | ||
return self; | ||
} | ||
|
||
- (void)dealloc { | ||
std::cout << "[LvDBWrapper] Iterator deallocated." << std::endl; | ||
} | ||
|
||
- (void)destroy { | ||
std::cout << "[LvDBWrapper] Iterator destroyed." << std::endl; | ||
iterator.reset(); | ||
} | ||
|
||
- (void)seekToFirst { | ||
iterator->SeekToFirst(); | ||
} | ||
|
||
- (void)seekToLast { | ||
iterator->SeekToLast(); | ||
} | ||
|
||
- (void)seek:(NSData *)key { | ||
leveldb::Slice dbKey = leveldb::Slice((const char *)[key bytes], [key length]); | ||
iterator->Seek(dbKey); | ||
} | ||
|
||
- (void)next { | ||
iterator->Next(); | ||
} | ||
|
||
- (void)prev { | ||
iterator->Prev(); | ||
} | ||
|
||
- (BOOL)valid { | ||
return iterator->Valid(); | ||
} | ||
|
||
- (NSData *)key { | ||
leveldb::Slice key = iterator->key(); | ||
return [[NSData alloc] initWithBytes:key.data() length:key.size()]; | ||
} | ||
|
||
- (NSData *)value { | ||
leveldb::Slice value = iterator->value(); | ||
return [[NSData alloc] initWithBytes:value.data() length:value.size()]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,6 @@ | |
#define ExposedHeader_h | ||
|
||
#include "../LvDB.h" | ||
#include "../LvDBIterator.h" | ||
|
||
#endif /* ExposedHeader_h */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters