-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathIndexIterator.java
More file actions
113 lines (96 loc) · 3.24 KB
/
IndexIterator.java
File metadata and controls
113 lines (96 loc) · 3.24 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
101
102
103
104
105
106
107
108
109
110
111
112
113
/*************************************************************************************************
* Index iterator interface
*
* Copyright 2020 Google LLC
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of the License at
* https://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software distributed under the
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*************************************************************************************************/
package tkrzw;
import java.nio.charset.StandardCharsets;
/**
* Iterator for each record of the secondary index.
* @note An iterator is made by the "makeIterator" method of Index. Every unused iterator object
* should be destructed explicitly by the "destruct" method to free resources.
*/
public class IndexIterator {
static {
Utility.loadLibrary();
}
/**
* Constructor.
* @param index The index to scan.
*/
IndexIterator(Index index) {
initialize(index);
}
/**
* Initialize the object.
* @param index The index to scan.
*/
private native void initialize(Index index);
/**
* Destructs the object and releases resources.
*/
public native void destruct();
/**
* Initializes the iterator to indicate the first record.
*/
public native void first();
/**
* Initializes the iterator to indicate the last record.
*/
public native void last();
/**
* Initializes the iterator to indicate a specific range.
* @param key The key of the lower bound.
* @param value The value of the lower bound.
*/
public native void jump(byte[] key, byte[] value);
/**
* Initializes the iterator to indicate a specific range, with string data.
* @param key The key of the lower bound.
* @param value The value of the lower bound.
*/
public void jump(String key, String value) {
jump(key.getBytes(StandardCharsets.UTF_8), value.getBytes(StandardCharsets.UTF_8));
}
/**
* Moves the iterator to the next record.
*/
public native void next();
/**
* Moves the iterator to the previous record.
*/
public native void previous();
/**
* Gets the key and the value of the current record of the iterator.
* @return A pair of the key and the value of the current record, or null on failure.
*/
public native byte[][] get();
/**
* Gets the key and the value of the current record of the iterator.
* @return A pair of the key and the value of the current record, or null on failure.
*/
public String[] getString() {
byte[][] record = get();
if (record == null) {
return null;
}
String[] str_record = new String[2];
str_record[0] = new String(record[0], StandardCharsets.UTF_8);
str_record[1] = new String(record[1], StandardCharsets.UTF_8);
return str_record;
}
/**
* Gets a string representation of the iterator.
*/
public native String toString();
/** The pointer to the native object */
private long ptr_ = 0;
}
// END OF FILE