Repository navigation
Expand file tree
/
Copy patharray.h
More file actions
100 lines (89 loc) · 2.84 KB
/
Copy patharray.h
File metadata and controls
100 lines (89 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
* Copyright (C) 2008 Hiroyuki Yamada
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef LUX_IO_ARRAY_H
#define LUX_IO_ARRAY_H
#include "dbm.h"
namespace Lux {
namespace IO {
class Data;
static const char *ARYMAGIC = "LUXAR001";
const int DEFAULT_PAGESIZE = getpagesize();
static const uint32_t ARY_ALLOCATE_UNIT = 100;
// global header
typedef struct {
char magic[8];
uint32_t num_keys;
uint32_t num_pages;
uint16_t page_size;
uint8_t index_type;
uint8_t data_size; // for fixed length value in cluster index
uint32_t num_resized;
} array_header_t;
/*
* Class Array
*/
class Array {
public:
Array(db_index_t index_type = CLUSTER,
uint8_t data_size = sizeof(uint32_t));
~Array(void);
bool open(std::string db_name, db_flags_t oflags);
bool close(void);
data_t *get(uint32_t index);
bool get(uint32_t index, data_t **data, alloc_type_t atype = USER);
bool put(uint32_t index,
const void *val, uint32_t val_size,
insert_mode_t flags = OVERWRITE);
bool put(uint32_t index, data_t *data, insert_mode_t flags = OVERWRITE);
bool del(uint32_t index);
void set_index_type(db_index_t index_type, uint8_t data_size);
void set_lock_type(lock_type_t lock_type);
void set_noncluster_params(store_mode_t smode,
padding_mode_t pmode = RATIO,
uint32_t padding = 20);
void clean_data(data_t *d);
void show_db_header(void);
private:
int fd_;
db_flags_t oflags_;
char *map_;
array_header_t *dh_;
db_index_t index_type_;
uint8_t data_size_;
uint64_t allocated_size_;
Data *dt_;
store_mode_t smode_;
padding_mode_t pmode_;
uint32_t padding_;
#ifdef LUXIO_HAVE_LIBPTHREAD
pthread_rwlock_t rwlock_;
#endif
uint32_t num_pages_;
uint16_t page_size_;
uint32_t num_resized_;
lock_type_t lock_type_;
bool open_(std::string db_name, db_flags_t oflags);
bool alloc_pages(uint32_t num_pages, uint16_t page_size);
bool realloc_pages(uint32_t num_pages, uint16_t page_size);
bool remap(void);
bool unlock_db(void);
bool rlock_db(void);
bool wlock_db(void);
};
}
}
#endif