remove conflict
[c11concurrency-benchmarks.git] / mabain / src / mb_data.h
1 /**
2  * Copyright (C) 2017 Cisco Inc.
3  *
4  * This program is free software: you can redistribute it and/or  modify
5  * it under the terms of the GNU General Public License, version 2,
6  * as published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
15  */
16
17 // @author Changxue Deng <chadeng@cisco.com>
18
19 #ifndef __MBDATA_H__
20 #define __MBDATA_H__
21
22 #include <stdint.h>
23 #include <stdlib.h>
24
25 #include "mabain_consts.h"
26
27 #define NUM_ALPHABET               256
28 #define NODE_EDGE_KEY_FIRST        8
29 #define DB_ITER_STATE_INIT         0x00
30 #define DB_ITER_STATE_MORE         0x01
31 #define DB_ITER_STATE_DONE         0x02
32 #define DATA_BLOCK_SIZE_DEFAULT    64LLU*1024*1024     // 64M
33 #define INDEX_BLOCK_SIZE_DEFAULT   64LLU*1024*1024     // 64M
34 #define BLOCK_SIZE_ALIGN           4*1024*1024         // 4K
35 #define BUFFER_TYPE_NONE           0
36 #define BUFFER_TYPE_EDGE_STR       0x01
37 #define BUFFER_TYPE_NODE           0x02
38 #define BUFFER_TYPE_DATA           0x04
39 #define MATCH_NONE                 0
40 #define MATCH_EDGE                 1
41 #define MATCH_NODE                 2
42 #define MATCH_NODE_OR_EDGE         3
43
44 namespace mabain {
45
46 typedef struct _EdgePtrs
47 {
48     size_t offset;
49     uint8_t *ptr;
50
51     uint8_t *len_ptr;
52     uint8_t *flag_ptr;
53     uint8_t *offset_ptr;
54
55     // temp buffer for edge, must be bigger than EDGE_SIZE.
56     uint8_t edge_buff[16];
57     // temp usage for calling UpdateNode or entry removing
58     int curr_nt;
59     // temp usage for entry removing
60     size_t curr_node_offset;
61     // temp usage for entry removing
62     int curr_edge_index;
63     // temp usage for entry removing and rc
64     size_t parent_offset;
65 } EdgePtrs;
66
67 // Data class for find and remove
68 // All memeber variable in this class should be kept public so that it can
69 // be easily accessed by the caller to get the data/value buffer and buffer len.
70 class MBData
71 {
72 public:
73     MBData();
74     MBData(int size, int options);
75     ~MBData();
76     // Clear the data for repeated usage
77     void Clear();
78     int  Resize(int size);
79     int  TransferValueTo(uint8_t* &data, int &dlen);
80     int  TransferValueFrom(uint8_t* &data, int dlen);
81
82     // data length
83     int data_len;
84     // data buffer
85     uint8_t *buff;
86     // buffer length
87     int buff_len;
88
89     // data offset
90     size_t data_offset;
91     uint16_t bucket_index;
92
93     // Search options
94     int options;
95
96     // temp data for multiple common prefix search
97     // If true, indicate the search should be continued for common prefix search
98     bool next;
99     // match length so far; only populated when match is found.
100     int match_len;
101     struct _EdgePtrs edge_ptrs;
102     // temp buffer to hold the node
103     uint8_t node_buff[NUM_ALPHABET+NODE_EDGE_KEY_FIRST];
104
105 private:
106     bool free_buffer;
107 };
108
109 }
110
111 #endif