1 | /* -*- c-basic-offset: 2 -*- */ |
2 | /* |
3 | Copyright(C) 2011-2016 Brazil |
4 | |
5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Lesser General Public |
7 | License version 2.1 as published by the Free Software Foundation. |
8 | |
9 | This library is distributed in the hope that it will be useful, |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | Lesser General Public License for more details. |
13 | |
14 | You should have received a copy of the GNU Lesser General Public |
15 | License along with this library; if not, write to the Free Software |
16 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
17 | */ |
18 | |
19 | #pragma once |
20 | |
21 | #include "cursor.hpp" |
22 | #include "vector.hpp" |
23 | |
24 | namespace grn { |
25 | namespace dat { |
26 | |
27 | class Trie; |
28 | |
29 | class GRN_DAT_API KeyCursor : public Cursor { |
30 | public: |
31 | KeyCursor(); |
32 | ~KeyCursor(); |
33 | |
34 | void open(const Trie &trie, |
35 | const String &min_str, |
36 | const String &max_str, |
37 | UInt32 offset = 0, |
38 | UInt32 limit = MAX_UINT32, |
39 | UInt32 flags = 0); |
40 | |
41 | void close(); |
42 | |
43 | const Key &next(); |
44 | |
45 | UInt32 offset() const { |
46 | return offset_; |
47 | } |
48 | UInt32 limit() const { |
49 | return limit_; |
50 | } |
51 | UInt32 flags() const { |
52 | return flags_; |
53 | } |
54 | |
55 | private: |
56 | const Trie *trie_; |
57 | UInt32 offset_; |
58 | UInt32 limit_; |
59 | UInt32 flags_; |
60 | |
61 | Vector<UInt32> buf_; |
62 | UInt32 count_; |
63 | UInt32 max_count_; |
64 | bool finished_; |
65 | UInt8 *end_buf_; |
66 | String end_str_; |
67 | |
68 | KeyCursor(const Trie &trie, |
69 | UInt32 offset, UInt32 limit, UInt32 flags); |
70 | |
71 | UInt32 fix_flags(UInt32 flags) const; |
72 | void init(const String &min_str, const String &max_str); |
73 | void ascending_init(const String &min_str, const String &max_str); |
74 | void descending_init(const String &min_str, const String &max_str); |
75 | void swap(KeyCursor *cursor); |
76 | |
77 | const Key &ascending_next(); |
78 | const Key &descending_next(); |
79 | |
80 | static const UInt32 POST_ORDER_FLAG = 0x80000000U; |
81 | |
82 | // Disallows copy and assignment. |
83 | KeyCursor(const KeyCursor &); |
84 | KeyCursor &operator=(const KeyCursor &); |
85 | }; |
86 | |
87 | } // namespace dat |
88 | } // namespace grn |
89 | |