2 * Copyright (C) 2017 Cisco Inc.
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.
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.
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/>.
17 // @author Changxue Deng <chadeng@cisco.com>
25 #include "mabain_consts.h"
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
42 #define MATCH_NODE_OR_EDGE 3
46 typedef struct _EdgePtrs
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
59 // temp usage for entry removing
60 size_t curr_node_offset;
61 // temp usage for entry removing
63 // temp usage for entry removing and rc
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.
74 MBData(int size, int options);
76 // Clear the data for repeated usage
79 int TransferValueTo(uint8_t* &data, int &dlen);
80 int TransferValueFrom(uint8_t* &data, int dlen);
91 uint16_t bucket_index;
96 // temp data for multiple common prefix search
97 // If true, indicate the search should be continued for common prefix search
99 // match length so far; only populated when match is found.
101 struct _EdgePtrs edge_ptrs;
102 // temp buffer to hold the node
103 uint8_t node_buff[NUM_ALPHABET+NODE_EDGE_KEY_FIRST];