blob: 95848a3ad5ac6438db346e982f7e7c09819f68e2 [file] [log] [blame]
Marc Kupietz06c9a9f2018-01-02 16:56:43 +01001#ifdef __cplusplus
Marc Kupietz4b799e92018-01-02 11:04:56 +01002#include <typeinfo>
Marc Kupietz4b799e92018-01-02 11:04:56 +01003#include "rocksdb/db.h"
Marc Kupietz06c9a9f2018-01-02 16:56:43 +01004#endif
5#include <stdint.h>
Marc Kupietz4b799e92018-01-02 11:04:56 +01006
7#define IS_BIG_ENDIAN (*(uint16_t *)"\0\xff" < 0x100)
8#define encodeCollocation(w1, w2, dist) (((uint64_t)dist << 56) | ((uint64_t)w2 << 24) | w1)
9#define W1(key) (uint64_t)(key & 0xffffff)
10#define W2(key) (uint64_t)((key >> 24) & 0xffffff)
11#define DIST(key) (int8_t)((uint64_t)((key >> 56) & 0xff))
12
Marc Kupietzc8ddf452018-01-07 21:33:12 +010013
14typedef struct {
15 uint64_t freq;
16 char *word;
17} vocab_entry;
18
Marc Kupietz06c9a9f2018-01-02 16:56:43 +010019#ifdef __cplusplus
Marc Kupietz4b799e92018-01-02 11:04:56 +010020namespace rocksdb {
21 class CollocatorIterator : public Iterator {
22 public:
23 CollocatorIterator(const Iterator& it);
24 void SeekToFirst();
25 void SeekToLast();
26 void Seek(const rocksdb::Slice&);
27 void Prev();
28 bool isValid();
29 uint64_t intValue();
30 uint64_t intKey();
31 };
32
Marc Kupietz06c9a9f2018-01-02 16:56:43 +010033 extern "C" {
34 class Collocators {
35 public:
Marc Kupietz4b799e92018-01-02 11:04:56 +010036 Collocators(const char *db_name);
37 ~Collocators();
38 void inc(const uint32_t w1, const uint32_t w2, const uint8_t dist);
Marc Kupietz06c9a9f2018-01-02 16:56:43 +010039 void dump(const uint32_t w1, const uint32_t w2, const uint8_t dist);
Marc Kupietz4b799e92018-01-02 11:04:56 +010040 CollocatorIterator* SeekIterator(uint64_t w1, uint64_t w2, int8_t dist);
Marc Kupietz06c9a9f2018-01-02 16:56:43 +010041 };
42
43 }
Marc Kupietz4b799e92018-01-02 11:04:56 +010044}
Marc Kupietz06c9a9f2018-01-02 16:56:43 +010045
46typedef rocksdb::Collocators COLLOCATORS;
47
48#else
49typedef struct COLLOCATORS COLLOCATORS;
50#endif
51
52extern COLLOCATORS *open_collocators(char *s);
53extern void inc_collocators(COLLOCATORS *db, uint64_t w1, uint64_t w2, int8_t dist);
54extern void dump_collocators(COLLOCATORS *db, uint32_t w1, uint32_t w2, int8_t dist);
Marc Kupietzc8ddf452018-01-07 21:33:12 +010055extern void get_collocators(COLLOCATORS *db, uint32_t w1, vocab_entry *vocab, uint64_t total);
56extern char *get_collocators_as_json(COLLOCATORS *db, uint32_t w1, vocab_entry *vocab, uint64_t total);
57