1 /* Copyright(C) 2004 Brazil
2 
3   This library is free software; you can redistribute it and/or
4   modify it under the terms of the GNU Lesser General Public
5   License as published by the Free Software Foundation; either
6   version 2.1 of the License, or (at your option) any later version.
7 
8   This library 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 GNU
11   Lesser General Public License for more details.
12 
13   You should have received a copy of the GNU Lesser General Public
14   License along with this library; if not, write to the Free Software
15   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16 */
17 //#include <sys/param.h>
18 
19 #ifndef SEN_SYM_H
20 #define SEN_SYM_H
21 
22 #ifndef SENNA_IN_H
23 #include "senna_in.h"
24 #endif /* SENNA_IN_H */
25 
26 #ifndef SEN_SET_H
27 #include "set.h"
28 #endif /* SEN_SET_H */
29 
30 #ifndef SEN_CTX_H
31 #include "ctx.h"
32 #endif /* SEN_CTX_H */
33 
34 #ifndef SEN_IO_H
35 #include "io.h"
36 #endif /* SEN_IO_H */
37 
38 #ifdef  __cplusplus
39 extern "C" {
40 #endif
41 
42   /* SEN_SYM_SEGMENT_SIZE * SEN_SYM_MAX_SEGMENT == 0x100000000 */
43 #define SEN_SYM_MAX_SEGMENT 0x400
44 
45   /* sizeof(pat_node) * (SEN_SYM_MAX_ID + 1) == 0x100000000 */
46 #define SEN_SYM_MAX_ID 0xfffffff
47 
48 #define SEN_SYM_MAX_KEY_LENGTH 0xffff
49   /* must be 2 ^ n */
50 #define SEN_SYM_NDELINFOS 0x100
51 #define SEN_SYM_MDELINFOS (SEN_SYM_NDELINFOS - 1)
52 
53 typedef struct {
54   /* stat : 2, ld : 30 */
55   sen_id bitfield;
56   sen_id d;
57 } sen_sym_delinfo;
58 
59 struct _sen_sym {
60   uint8_t v08p;
61   sen_io *io;
62   struct sen_sym_header *header;
63   uint32_t flags;
64   sen_encoding encoding;
65   uint32_t key_size;
66   uint32_t nref;
67   uint32_t *lock;
68   void *keyaddrs[SEN_SYM_MAX_SEGMENT];
69   void *pataddrs[SEN_SYM_MAX_SEGMENT];
70   void *sisaddrs[SEN_SYM_MAX_SEGMENT];
71 };
72 
73 struct _sen_sym_cursor_entry {
74   sen_id id;
75   uint16_t check;
76 };
77 
78 typedef struct _sen_sym_cursor_entry sen_sym_cursor_entry;
79 
80 struct _sen_sym_cursor {
81   sen_sym *sym;
82   sen_ctx *ctx;
83   unsigned int size;
84   unsigned int sp;
85   int flags;
86   sen_id limit;
87   sen_sym_cursor_entry *ss;
88 };
89 
90 const char *_sen_sym_key(sen_sym *sym, sen_id id);
91 // sen_id sen_sym_del_with_sis(sen_sym *sym, sen_id id);
92 int sen_sym_del_with_sis(sen_sym *sym, sen_id id,
93                          int(*func)(sen_id, void *), void *func_arg);
94 sen_id sen_sym_curr_id(sen_sym *sym);
95 sen_rc sen_sym_prefix_search_with_set(sen_sym *sym, const void *key, sen_set *h);
96 sen_rc sen_sym_suffix_search_with_set(sen_sym *sym, const void *key, sen_set *h);
97 
98 sen_rc sen_sym_pocket_incr(sen_sym *sym, sen_id id);
99 sen_rc sen_sym_pocket_decr(sen_sym *sym, sen_id id);
100 
101 sen_rc sen_sym_lock(sen_sym *sym, int timeout);
102 sen_rc sen_sym_unlock(sen_sym *sym);
103 sen_rc sen_sym_clear_lock(sen_sym *sym);
104 
105 sen_id sen_sym_nextid(sen_sym *sym, const void *key);
106 
107 #ifdef __cplusplus
108 }
109 #endif
110 
111 #endif /* SEN_SYM_H */
112