b59f3e52b28c199d8040e09e6c4b67049b44a069
[c11concurrency-benchmarks.git] / silo / masstree / query_masstree.hh
1 /* Masstree
2  * Eddie Kohler, Yandong Mao, Robert Morris
3  * Copyright (c) 2012-2014 President and Fellows of Harvard College
4  * Copyright (c) 2012-2014 Massachusetts Institute of Technology
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, subject to the conditions
9  * listed in the Masstree LICENSE file. These conditions include: you must
10  * preserve this copyright notice, and you cannot mention the copyright
11  * holders in advertising related to the Software without their permission.
12  * The Software is provided WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED. This
13  * notice is a summary of the Masstree LICENSE file; the license in that file
14  * is legally binding.
15  */
16 #ifndef QUERY_MASSTREE_HH
17 #define QUERY_MASSTREE_HH 1
18 #include "masstree.hh"
19 #include "kvrow.hh"
20 class threadinfo;
21 namespace lcdf { class Json; }
22
23 namespace Masstree {
24
25 template <typename P>
26 class query_table {
27   public:
28     typedef P param_type;
29     typedef node_base<P> node_type;
30     typedef typename P::threadinfo_type threadinfo;
31     typedef unlocked_tcursor<P> unlocked_cursor_type;
32     typedef tcursor<P> cursor_type;
33
34     query_table() {
35     }
36
37     const basic_table<P>& table() const {
38         return table_;
39     }
40     basic_table<P>& table() {
41         return table_;
42     }
43
44     void initialize(threadinfo& ti) {
45         table_.initialize(ti);
46     }
47     void destroy(threadinfo& ti) {
48         table_.destroy(ti);
49     }
50
51     void findpivots(Str* pv, int npv) const;
52
53     void stats(FILE* f);
54     void json_stats(lcdf::Json& j, threadinfo& ti);
55     inline lcdf::Json json_stats(threadinfo& ti) {
56         lcdf::Json j;
57         json_stats(j, ti);
58         return j;
59     }
60
61     void print(FILE* f, int indent) const;
62
63     static void test(threadinfo& ti);
64
65     static const char* name() {
66         return "mb";
67     }
68
69   private:
70     basic_table<P> table_;
71 };
72
73 struct default_query_table_params : public nodeparams<15, 15> {
74     typedef row_type* value_type;
75     typedef value_print<value_type> value_print_type;
76     typedef ::threadinfo threadinfo_type;
77 };
78
79 typedef query_table<default_query_table_params> default_table;
80
81 } // namespace Masstree
82 #endif