Created
February 26, 2019 16:09
-
-
Save kostja/9934d96b4d7ce10d093d69fdf792c9d8 to your computer and use it in GitHub Desktop.
Template for memtx tree
This file contains hidden or 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
struct index {}; | |
struct index_vtab { | |
void (*build_index)(struct index *); | |
}; | |
#define bps_declaration \ | |
struct bps_tree { \ | |
bps_tree_node node; \ | |
}; | |
template <typename T> | |
struct memtx_index: public index { | |
#define bps_tree_node T | |
bps_declaration | |
#undef bps_tree_node | |
struct bps_tree index; | |
static void | |
build_index(struct index *p) | |
{ | |
struct memtx_index<T> *index = (struct memtx_index<T> *) p; | |
}; | |
static struct index_vtab vtab; | |
}; | |
template <typename T> | |
struct index_vtab memtx_index<T>::vtab = { | |
.build_index = memtx_index<T>::build_index | |
}; | |
struct multikey {}; | |
struct hint {}; | |
enum memtx_index_type { HINT, MULTIKEY }; | |
static struct index * | |
create_index(enum memtx_index_type type) | |
{ | |
switch (type) { | |
case HINT: | |
return new memtx_index<hint>; | |
case MULTIKEY: | |
return new memtx_index<multikey>; | |
} | |
} | |
int main() | |
{ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment