bitcoinleveldb_table/
iterator.rs

1/*!
2  | An iterator yields a sequence of key/value
3  | pairs from a source.  The following class
4  | defines the interface.  Multiple
5  | implementations are provided by this library.
6  | In particular, iterators are provided to access
7  | the contents of a Table or a DB.
8  |
9  | Multiple threads can invoke const methods on an
10  | Iterator without external synchronization, but
11  | if any of the threads may call a non-const
12  | method, all threads accessing the same Iterator
13  | must use external synchronization.
14  */
15
16crate::ix!();
17
18pub trait Valid {
19
20    /**
21      | An iterator is either positioned at
22      | a key/value pair, or not valid. This
23      | method returns true iff the iterator
24      | is valid.
25      |
26      */
27    fn valid(&self) -> bool;
28}
29
30pub trait SeekToFirst {
31
32    /**
33      | Position at the first key in the source.
34      | The iterator is Valid() after this call
35      | iff the source is not empty.
36      |
37      */
38    fn seek_to_first(&mut self);
39}
40
41pub trait SeekToLast {
42
43    /**
44      | Position at the last key in the source.
45      | The iterator is Valid() after this call
46      | iff the source is not empty.
47      |
48      */
49    fn seek_to_last(&mut self);
50}
51
52pub trait Seek {
53
54    /**
55      | Position at the first key in the source that
56      | is at or past target.  The iterator is
57      | Valid() after this call iff the source
58      | contains an entry that comes at or past
59      | target.
60      */
61    fn seek(&mut self, target: &Slice);
62}
63
64pub trait Next {
65
66    /**
67      | Moves to the next entry in the source.  After
68      | this call, Valid() is true iff the iterator
69      | was not positioned at the last entry in the
70      | source.
71      |
72      | REQUIRES: Valid()
73      */
74    fn next(&mut self);
75}
76
77pub trait Prev {
78
79    /**
80      | Moves to the previous entry in the source.
81      | After this call, Valid() is true iff the
82      | iterator was not positioned at the first
83      | entry in source.
84      |
85      | REQUIRES: Valid()
86      */
87    fn prev(&mut self);
88}
89
90pub trait LevelDBIteratorStatus {
91
92    /**
93      | If an error has occurred, return it.
94      | Else return an ok status.
95      |
96      */
97    fn status(&self) -> crate::Status;
98}
99
100/**
101  | Cleanup functions are stored in
102  | a single-linked list.
103  |
104  | The list's head node is inlined in the
105  | iterator.
106  */
107pub struct LevelDBIteratorCleanupNode {
108
109    /**
110      | The head node is used if the function
111      | pointer is not null.
112      |
113      */
114    function: LevelDBIteratorCleanupFunction,
115
116    arg1:     *mut c_void,
117    arg2:     *mut c_void,
118    next:     *mut LevelDBIteratorCleanupNode,
119}
120
121impl LevelDBIteratorCleanupNode {
122
123    /**
124      | True if the node is not used. Only head
125      | nodes might be unused.
126      |
127      */
128    pub fn is_empty(&self) -> bool {
129        
130        todo!();
131        /*
132            return function == nullptr;
133        */
134    }
135
136    /**
137      | Invokes the cleanup function.
138      |
139      */
140    pub fn run(&mut self)  {
141        
142        todo!();
143        /*
144            assert(function != nullptr);
145          (*function)(arg1, arg2);
146        */
147    }
148}
149
150pub type LevelDBIteratorCleanupFunction = fn(arg1: *mut c_void, arg2: *mut c_void) -> c_void;
151
152//-------------------------------------------[.cpp/bitcoin/src/leveldb/include/leveldb/iterator.h]
153
154#[derive(Default)]
155pub struct LevelDBIteratorInner {
156    cleanup_head: Option<LevelDBIteratorCleanupNode>,
157}
158
159pub trait LevelDBIteratorInterface:
160    Valid
161    + SeekToFirst
162    + SeekToLast
163    + Seek
164    + Next
165    + Prev
166    + Key
167    + Value
168    + LevelDBIteratorStatus { }
169
170/**
171  | Return an empty iterator (yields nothing).
172  |
173  */
174pub fn new_empty_iterator() -> *mut LevelDBIteratorInner {
175    
176    todo!();
177        /*
178        
179        */
180}
181
182/**
183  | Return an empty iterator with the specified
184  | status.
185  |
186  */
187pub fn new_error_iterator(status: &Status) -> *mut LevelDBIterator {
188    
189    todo!();
190        /*
191        
192        */
193}