collocatordb: class and function renames
diff --git a/c_testanalysis.c b/c_testanalysis.c
index bb40f4a..de0d227 100644
--- a/c_testanalysis.c
+++ b/c_testanalysis.c
@@ -5,7 +5,7 @@
#include "collocatordb.h"
int main() {
- COLLOCATORS *cdb = open_collocators_for_read("/vol/work/kupietz/Work2/kl/trunk/Analysemethoden/wang2vec/sample");
+ COLLOCATORDB *cdb = open_collocatordb("/vol/work/kupietz/Work2/kl/trunk/Analysemethoden/wang2vec/sample");
for(int i=100; i < 1000; i++)
get_collocators(cdb, i);
printf("%s\n", get_collocators_as_json(cdb, 500));
diff --git a/c_testcdb.c b/c_testcdb.c
index 34f05ec..5a86cc8 100644
--- a/c_testcdb.c
+++ b/c_testcdb.c
@@ -4,10 +4,10 @@
#include "collocatordb.h"
int main() {
- COLLOCATORS *cdb = open_collocators("/tmp/test2");
- inc_collocators(cdb, 2000, 2000, 4);
- inc_collocators(cdb, 2000, 2001, 4);
- inc_collocators(cdb, 2000, 2002, 4);
+ COLLOCATORDB *cdb = open_collocatordb_for_write("/tmp/test.rocksdb");
+ inc_collocator(cdb, 2000, 2000, 4);
+ inc_collocator(cdb, 2000, 2001, 4);
+ inc_collocator(cdb, 2000, 2002, 4);
dump_collocators(cdb, 2000, 0, 0);
return 0;
}
diff --git a/collocatordb.cc b/collocatordb.cc
index 2f06c63..89da1c6 100644
--- a/collocatordb.cc
+++ b/collocatordb.cc
@@ -197,7 +197,7 @@
uint64_t freq;
};
- class Collocators {
+ class CollocatorDB {
private:
WriteOptions merge_option_; // for merge
char _one[sizeof(uint64_t)];
@@ -219,10 +219,10 @@
void read_vocab(string fname);
public:
- Collocators(const char *db_name, bool read_only);
- ~Collocators();
+ CollocatorDB(const char *db_name, bool read_only);
+ ~CollocatorDB();
- // public interface of Collocators.
+ // public interface of CollocatorDB.
// All four functions return false
// if the underlying level db operation failed.
@@ -323,7 +323,7 @@
CollocatorIterator* SeekIterator(uint64_t w1, uint64_t w2, int8_t dist);
};
- rocksdb::Collocators::Collocators(const char *db_name, bool read_only = false) {
+ rocksdb::CollocatorDB::CollocatorDB(const char *db_name, bool read_only = false) {
// merge_option_.sync = true;
if(read_only)
db_ = OpenDbForRead(db_name);
@@ -339,15 +339,15 @@
std::cout << "destroying itera\n";
}
- rocksdb::Collocators::~Collocators() {
+ rocksdb::CollocatorDB::~CollocatorDB() {
std::cout << "destroying coll\n";
}
- void rocksdb::Collocators::inc(const uint32_t w1, const uint32_t w2, const uint8_t dist) {
+ void rocksdb::CollocatorDB::inc(const uint32_t w1, const uint32_t w2, const uint8_t dist) {
inc(encodeCollocation(w1, w2, dist));
}
- void rocksdb::Collocators::read_vocab(string fname) {
+ void rocksdb::CollocatorDB::read_vocab(string fname) {
char strbuf[2048];
uint64_t freq;
FILE *fin = fopen(fname.c_str(), "rb");
@@ -365,7 +365,7 @@
fclose(fin);
}
- std::shared_ptr<DB> rocksdb::Collocators::OpenDbForRead(const char *name) {
+ std::shared_ptr<DB> rocksdb::CollocatorDB::OpenDbForRead(const char *name) {
DB* db;
Options options;
ostringstream dbname, vocabname;
@@ -380,7 +380,7 @@
return std::shared_ptr<DB>(db);
}
- std::shared_ptr<DB> rocksdb::Collocators::OpenDb(const char *dbname) {
+ std::shared_ptr<DB> rocksdb::CollocatorDB::OpenDb(const char *dbname) {
DB* db;
Options options;
@@ -419,7 +419,7 @@
return std::shared_ptr<DB>(db);
}
- CollocatorIterator* rocksdb::Collocators::SeekIterator(uint64_t w1, uint64_t w2, int8_t dist) {
+ CollocatorIterator* rocksdb::CollocatorDB::SeekIterator(uint64_t w1, uint64_t w2, int8_t dist) {
ReadOptions options;
options.prefix_same_as_start = true;
char prefixc[sizeof(uint64_t)];
@@ -431,7 +431,7 @@
return cit;
}
- void rocksdb::Collocators::dump(uint32_t w1, uint32_t w2, int8_t dist) {
+ void rocksdb::CollocatorDB::dump(uint32_t w1, uint32_t w2, int8_t dist) {
auto it = std::unique_ptr<CollocatorIterator>(SeekIterator(w1, w2, dist));
for (; it->isValid(); it->Next()) {
uint64_t value = it->intValue();
@@ -486,7 +486,7 @@
bool sortByNpmi(const Collocator &lhs, const Collocator &rhs) { return lhs.npmi > rhs.npmi; }
bool sortByLfmd(const Collocator &lhs, const Collocator &rhs) { return lhs.lfmd > rhs.lfmd; }
- std::vector<Collocator> rocksdb::Collocators::get_collocators(uint32_t w1) {
+ std::vector<Collocator> rocksdb::CollocatorDB::get_collocators(uint32_t w1) {
std::vector<Collocator> collocators;
uint64_t w2, last_w2 = 0xffffffffffffffff;
uint64_t sum = 0, total_w1 = 0;
@@ -539,7 +539,7 @@
};
-string rocksdb::Collocators::collocators2json(vector<Collocator> collocators) {
+string rocksdb::CollocatorDB::collocators2json(vector<Collocator> collocators) {
ostringstream s;
s << "[";
bool first = true;
@@ -561,18 +561,18 @@
return s.str();
}
-typedef rocksdb::Collocators COLLOCATORS;
+typedef rocksdb::CollocatorDB COLLOCATORS;
extern "C" {
- COLLOCATORS *open_collocators(char *dbname) {
- return new rocksdb::Collocators(dbname);
+ COLLOCATORS *open_collocatordb_for_write(char *dbname) {
+ return new rocksdb::CollocatorDB(dbname, false);
}
- COLLOCATORS *open_collocators_for_read(char *dbname) {
- return new rocksdb::Collocators(dbname, true);
+ COLLOCATORS *open_collocatordb(char *dbname) {
+ return new rocksdb::CollocatorDB(dbname, true);
}
- void inc_collocators(COLLOCATORS *db, uint32_t w1, uint32_t w2, int8_t dist) {
+ void inc_collocator(COLLOCATORS *db, uint32_t w1, uint32_t w2, int8_t dist) {
db->inc(w1, w2, dist);
}
diff --git a/collocatordb.h b/collocatordb.h
index 406ea5d..fe76e6c 100644
--- a/collocatordb.h
+++ b/collocatordb.h
@@ -25,10 +25,10 @@
};
extern "C" {
- class Collocators {
+ class CollocatorDB {
public:
- Collocators(const char *db_name);
- ~Collocators();
+ CollocatorDB(const char *db_name);
+ ~CollocatorDB();
void inc(const uint32_t w1, const uint32_t w2, const uint8_t dist);
void dump(const uint32_t w1, const uint32_t w2, const uint8_t dist);
CollocatorIterator* SeekIterator(uint64_t w1, uint64_t w2, int8_t dist);
@@ -37,16 +37,16 @@
}
}
-typedef rocksdb::Collocators COLLOCATORS;
+typedef rocksdb::CollocatorDB COLLOCATORDB;
#else
-typedef struct COLLOCATORS COLLOCATORS;
+typedef struct COLLOCATORDB COLLOCATORDB;
#endif
-extern COLLOCATORS *open_collocators(char *s);
-extern COLLOCATORS *open_collocators_for_read(char *s);
-extern void inc_collocators(COLLOCATORS *db, uint64_t w1, uint64_t w2, int8_t dist);
-extern void dump_collocators(COLLOCATORS *db, uint32_t w1, uint32_t w2, int8_t dist);
-extern void get_collocators(COLLOCATORS *db, uint32_t w1);
-extern char *get_collocators_as_json(COLLOCATORS *db, uint32_t w1);
+extern COLLOCATORDB *open_collocatordb(char *s);
+extern COLLOCATORDB *open_collocatordb_for_write(char *s);
+extern void inc_collocator(COLLOCATORDB *db, uint64_t w1, uint64_t w2, int8_t dist);
+extern void dump_collocators(COLLOCATORDB *db, uint32_t w1, uint32_t w2, int8_t dist);
+extern void get_collocators(COLLOCATORDB *db, uint32_t w1);
+extern char *get_collocators_as_json(COLLOCATORDB *db, uint32_t w1);