Skip to content

Commit

Permalink
Prepare user comparator
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor Shcherb committed Aug 5, 2011
1 parent f748e27 commit d027393
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ What is to be verified and implemented
-------------------- --------------------
There are some operations not linked with C++ [API](http://code.google.com/p/leveldb/source/browse/#svn%2Ftrunk%2Finclude%2Fleveldb) : There are some operations not linked with C++ [API](http://code.google.com/p/leveldb/source/browse/#svn%2Ftrunk%2Finclude%2Fleveldb) :


* [Comparator](http://code.google.com/p/leveldb/source/browse/trunk/include/leveldb/comparator.h) - important enough (callback) * [Comparator](http://code.google.com/p/leveldb/source/browse/trunk/include/leveldb/comparator.h) - important enough. But require callback from C to Java which is difficult to do in SWIG.
* [TableBuilder](http://code.google.com/p/leveldb/source/browse/trunk/include/leveldb/table_builder.h) and [Table](http://code.google.com/p/leveldb/source/browse/trunk/include/leveldb/table.h) - should be properly tested. There is no default API to read Table from middle of file but it can be implemented. * [TableBuilder](http://code.google.com/p/leveldb/source/browse/trunk/include/leveldb/table_builder.h) and [Table](http://code.google.com/p/leveldb/source/browse/trunk/include/leveldb/table.h) - should be properly tested. There is no default API to read Table from middle of file but it can be implemented.




Expand Down
44 changes: 42 additions & 2 deletions db.i
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -5,13 +5,49 @@
#include "leveldb/write_batch.h" #include "leveldb/write_batch.h"
#include "leveldb/db.h" #include "leveldb/db.h"
#include "leveldb/env.h" #include "leveldb/env.h"
#include "leveldb/comparator.h"
#include "leveldb/table_builder.h" #include "leveldb/table_builder.h"
#include "leveldb/table.h" #include "leveldb/table.h"
#include "leveldb/options.h" #include "leveldb/options.h"
%} %}



%{
namespace leveldb {
class UserComparator : private Comparator {
private :
std::string comparatorName;
int (*comparatorFunc)(const std::string& a, const std::string& b);
public :
UserComparator(std::string name, int (*c)(const std::string& a, const std::string& b)) : comparatorName(name){
this-> comparatorFunc = c;
}

// If *start < limit, changes *start to a short string in [start,limit).
void FindShortestSeparator(std::string* start, const Slice& limit) {
// Does nothing that's correct to allow optimization
}

// Changes *key to a short string >= *key.
void FindShortSuccessor(std::string* key) {
// Does nothing that's correct to allow optimization
}
int Compare(const leveldb::Slice& a, const leveldb::Slice& b) const {
return 0;
}


const char* Name() const {
return comparatorName.c_str();
}
};
}
%}


namespace leveldb { namespace leveldb {


%nodefaultctor;
%nodefaultdtor Snapshot; %nodefaultdtor Snapshot;
class Snapshot { class Snapshot {
}; };
Expand All @@ -30,7 +66,6 @@ namespace leveldb {
// DB::ReleaseSnapshot(*post_write_snapshotsnapshot) when the // DB::ReleaseSnapshot(*post_write_snapshotsnapshot) when the
// snapshot is no longer needed. // snapshot is no longer needed.
// Default: NULL // Default: NULL

%rename(postWriteSnapshot) post_write_snapshot; %rename(postWriteSnapshot) post_write_snapshot;
const Snapshot** post_write_snapshot; const Snapshot** post_write_snapshot;


Expand Down Expand Up @@ -90,6 +125,9 @@ namespace leveldb {
int block_restart_interval; int block_restart_interval;


CompressionType compression; CompressionType compression;

// const Comparator* comparator;

}; };




Expand All @@ -115,7 +153,8 @@ namespace leveldb {


%inline %{ %inline %{
namespace leveldb { namespace leveldb {



class DBWriteBatch { class DBWriteBatch {
friend class DBAccessor; friend class DBAccessor;
private : private :
Expand Down Expand Up @@ -208,6 +247,7 @@ namespace leveldb {
long long approximateOffsetOf(const std::string& key) { table -> ApproximateOffsetOf(Slice(key)); } long long approximateOffsetOf(const std::string& key) { table -> ApproximateOffsetOf(Slice(key)); }
}; };



class DBTableBuilder { class DBTableBuilder {
TableBuilder* tableBuilder; TableBuilder* tableBuilder;
WritableFile* wf; WritableFile* wf;
Expand Down
1 change: 0 additions & 1 deletion src/com/anvisics/jleveldb/ext/LeveldbJNI.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
package com.anvisics.jleveldb.ext; package com.anvisics.jleveldb.ext;


class LeveldbJNI { class LeveldbJNI {
public final static native long new_Snapshot();
public final static native long new_WriteOptions(); public final static native long new_WriteOptions();
public final static native void WriteOptions_sync_set(long jarg1, WriteOptions jarg1_, boolean jarg2); public final static native void WriteOptions_sync_set(long jarg1, WriteOptions jarg1_, boolean jarg2);
public final static native boolean WriteOptions_sync_get(long jarg1, WriteOptions jarg1_); public final static native boolean WriteOptions_sync_get(long jarg1, WriteOptions jarg1_);
Expand Down
4 changes: 0 additions & 4 deletions src/com/anvisics/jleveldb/ext/Snapshot.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -31,8 +31,4 @@ public synchronized void delete() {
} }
} }


public Snapshot() {
this(LeveldbJNI.new_Snapshot(), true);
}

} }

0 comments on commit d027393

Please sign in to comment.