blob: fe76e6cc1c8c457f506db78bc3283bbee4adcb2b [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 Kupietz06c9a9f2018-01-02 16:56:43 +010013#ifdef __cplusplus
Marc Kupietz4b799e92018-01-02 11:04:56 +010014namespace rocksdb {
15 class CollocatorIterator : public Iterator {
16 public:
17 CollocatorIterator(const Iterator& it);
18 void SeekToFirst();
19 void SeekToLast();
20 void Seek(const rocksdb::Slice&);
21 void Prev();
22 bool isValid();
23 uint64_t intValue();
24 uint64_t intKey();
25 };
26
Marc Kupietz06c9a9f2018-01-02 16:56:43 +010027 extern "C" {
Marc Kupietz6aec7682018-01-10 09:47:48 +010028 class CollocatorDB {
Marc Kupietz06c9a9f2018-01-02 16:56:43 +010029 public:
Marc Kupietz6aec7682018-01-10 09:47:48 +010030 CollocatorDB(const char *db_name);
31 ~CollocatorDB();
Marc Kupietz4b799e92018-01-02 11:04:56 +010032 void inc(const uint32_t w1, const uint32_t w2, const uint8_t dist);
Marc Kupietz06c9a9f2018-01-02 16:56:43 +010033 void dump(const uint32_t w1, const uint32_t w2, const uint8_t dist);
Marc Kupietz4b799e92018-01-02 11:04:56 +010034 CollocatorIterator* SeekIterator(uint64_t w1, uint64_t w2, int8_t dist);
Marc Kupietz06c9a9f2018-01-02 16:56:43 +010035 };
36
37 }
Marc Kupietz4b799e92018-01-02 11:04:56 +010038}
Marc Kupietz06c9a9f2018-01-02 16:56:43 +010039
Marc Kupietz6aec7682018-01-10 09:47:48 +010040typedef rocksdb::CollocatorDB COLLOCATORDB;
Marc Kupietz06c9a9f2018-01-02 16:56:43 +010041
42#else
Marc Kupietz6aec7682018-01-10 09:47:48 +010043typedef struct COLLOCATORDB COLLOCATORDB;
Marc Kupietz06c9a9f2018-01-02 16:56:43 +010044#endif
45
Marc Kupietz6aec7682018-01-10 09:47:48 +010046extern COLLOCATORDB *open_collocatordb(char *s);
47extern COLLOCATORDB *open_collocatordb_for_write(char *s);
48extern void inc_collocator(COLLOCATORDB *db, uint64_t w1, uint64_t w2, int8_t dist);
49extern void dump_collocators(COLLOCATORDB *db, uint32_t w1, uint32_t w2, int8_t dist);
50extern void get_collocators(COLLOCATORDB *db, uint32_t w1);
51extern char *get_collocators_as_json(COLLOCATORDB *db, uint32_t w1);
Marc Kupietzc8ddf452018-01-07 21:33:12 +010052