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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
hicc::cpp! {
#include <queue>
}
hicc::import_class! {
#[cpp(class = "template<class T, class Container> std::queue<T, Container>")]
pub class queue<T> {
/// ```
/// use hicc_std::QueueInt;
/// let mut queue = QueueInt::new();
/// assert!(queue.is_empty());
/// queue.push(&1);
/// assert!(!queue.is_empty());
/// ```
#[cpp(method = "bool empty() const")]
pub fn is_empty(&self) -> bool;
/// ```
/// use hicc_std::QueueInt;
/// let mut queue = QueueInt::new();
/// assert_eq!(queue.size(), 0);
/// queue.push(&1);
/// assert_eq!(queue.size(), 1);
/// ```
#[cpp(method = "size_t size() const")]
pub fn size(&self) -> usize;
/// 如果为空不做任何改变.
/// ```
/// use hicc_std::QueueInt;
/// let mut queue = QueueInt::new();
/// queue.pop();
/// queue.push(&1);
/// assert_eq!(queue.size(), 1);
/// queue.pop();
/// assert_eq!(queue.size(), 0);
/// ```
pub fn pop(&mut self) {
if !self.is_empty() {
unsafe { self._pop() };
}
}
#[cpp(method = "void pop()")]
unsafe fn _pop(&mut self);
/// ```
/// use hicc_std::QueueInt;
/// let mut queue = QueueInt::new();
/// queue.push(&1);
/// queue.push(&2);
/// assert_eq!(queue.front(), Some(&1));
/// ```
#[cpp(method = "void push(const T&)")]
pub fn push(&mut self, val: &T);
/// ```
/// use hicc_std::QueueInt;
/// let mut queue = QueueInt::new();
/// assert_eq!(queue.front(), None);
/// queue.push(&1);
/// assert_eq!(queue.front(), Some(&1));
/// ```
pub fn front(&self) -> Option<T::OutputRef<'_>> {
if !self.is_empty() {
return unsafe { Some(self._front()) };
}
None
}
#[cpp(method = "const T& front() const")]
unsafe fn _front(&self) -> &T;
/// ```
/// use hicc_std::QueueInt;
/// let mut queue = QueueInt::new();
/// assert_eq!(queue.front_mut(), None);
/// queue.push(&1);
/// queue.push(&3);
/// *queue.front_mut().unwrap() += 1;
/// assert_eq!(queue.front(), Some(&2));
///
/// use hicc_std::{string, QueueString};
/// use hicc::AbiClass;
/// let mut queue = QueueString::new();
/// queue.push(&string::from(hicc::cstr!("hello")));
/// queue.push(&string::new());
/// assert_eq!(queue.front(), Some(string::from(hicc::cstr!("hello")).into_ref()));
/// queue.front_mut().unwrap().write(string::from(hicc::cstr!("world")));
/// assert_eq!(queue.front(), Some(string::from(hicc::cstr!("world")).into_ref()));
/// ```
pub fn front_mut(&mut self) -> Option<T::OutputRefMut<'_>> {
if !self.is_empty() {
return unsafe { Some(self._front_mut()) };
}
None
}
#[cpp(method = "T& front()")]
unsafe fn _front_mut(&mut self) -> &mut T;
/// ```
/// use hicc_std::QueueInt;
/// let mut queue = QueueInt::new();
/// assert_eq!(queue.back(), None);
/// queue.push(&2);
/// queue.push(&1);
/// assert_eq!(queue.back(), Some(&1));
/// ```
pub fn back(&self) -> Option<T::OutputRef<'_>> {
if !self.is_empty() {
return unsafe { Some(self._back()) };
}
None
}
#[cpp(method = "const T& back() const")]
unsafe fn _back(&self) -> &T;
/// ```
/// use hicc_std::QueueInt;
/// let mut queue = QueueInt::new();
/// assert_eq!(queue.back(), None);
/// queue.push(&3);
/// queue.push(&1);
/// *queue.back_mut().unwrap() += 1;
/// assert_eq!(queue.back(), Some(&2));
///
/// use hicc_std::{string, QueueString};
/// use hicc::AbiClass;
/// let mut queue = QueueString::new();
/// queue.push(&string::new());
/// queue.push(&string::from(hicc::cstr!("hello")));
/// assert_eq!(queue.back(), Some(string::from(hicc::cstr!("hello")).into_ref()));
/// queue.back_mut().unwrap().write(string::from(hicc::cstr!("world")));
/// assert_eq!(queue.back(), Some(string::from(hicc::cstr!("world")).into_ref()));
/// ```
pub fn back_mut(&mut self) -> Option<T::OutputRefMut<'_>> {
if !self.is_empty() {
return unsafe { Some(self._back_mut()) };
}
None
}
#[cpp(method = "T& back()")]
unsafe fn _back_mut(&mut self) -> &mut T;
/// ```
/// use hicc_std::QueueInt;
/// let mut queue = QueueInt::new();
/// queue.push(&1);
/// let mut other = QueueInt::new();
/// other.push(&2);
/// assert_eq!(queue.front(), Some(&1));
/// assert_eq!(other.front(), Some(&2));
/// queue.swap(&mut other);
/// assert_eq!(queue.front(), Some(&2));
/// assert_eq!(other.front(), Some(&1));
/// ```
#[cpp(method = "void swap(Self&)")]
pub fn swap(&mut self, other: &mut Self);
}
unsafe impl<T: hicc::AbiType + Sync> Send for queue<T> {}
unsafe impl<T: hicc::AbiType + Sync> Sync for queue<T> {}
#[cpp(class = "template<class T, class Container, class Compare> std::priority_queue<T, Container, Compare>")]
pub class priority_queue<T> {
/// ```
/// use hicc_std::PriorityQueueInt;
/// let mut priority_queue = PriorityQueueInt::new();
/// assert!(priority_queue.is_empty());
/// priority_queue.push(&1);
/// assert!(!priority_queue.is_empty());
/// ```
#[cpp(method = "bool empty() const")]
pub fn is_empty(&self) -> bool;
/// ```
/// use hicc_std::PriorityQueueInt;
/// let mut priority_queue = PriorityQueueInt::new();
/// assert_eq!(priority_queue.size(), 0);
/// priority_queue.push(&1);
/// assert_eq!(priority_queue.size(), 1);
/// ```
#[cpp(method = "size_t size() const")]
pub fn size(&self) -> usize;
/// 如果为空不做任何改变.
/// ```
/// use hicc_std::PriorityQueueInt;
/// let mut priority_queue = PriorityQueueInt::new();
/// priority_queue.pop();
/// priority_queue.push(&1);
/// assert_eq!(priority_queue.size(), 1);
/// priority_queue.pop();
/// assert_eq!(priority_queue.size(), 0);
/// ```
pub fn pop(&mut self) {
if !self.is_empty() {
unsafe { self._pop(); }
}
}
#[cpp(method = "void pop()")]
unsafe fn _pop(&mut self);
/// ```
/// use hicc_std::PriorityQueueInt;
/// let mut priority_queue = PriorityQueueInt::new();
/// priority_queue.push(&1);
/// assert_eq!(priority_queue.top(), Some(&1));
/// ```
#[cpp(method = "void push(const T&)")]
pub fn push(&mut self, val: &T);
/// ```
/// use hicc_std::PriorityQueueInt;
/// let mut priority_queue = PriorityQueueInt::new();
/// assert_eq!(priority_queue.top(), None);
/// priority_queue.push(&1);
/// priority_queue.push(&3);
/// priority_queue.push(&2);
/// assert_eq!(priority_queue.top(), Some(&3));
/// ```
pub fn top(&self) -> Option<T::OutputRef<'_>> {
if !self.is_empty() {
return unsafe { Some(self._top()) };
}
None
}
#[cpp(method = "const T& top() const")]
unsafe fn _top(&self) -> &T;
/// ```
/// use hicc_std::PriorityQueueInt;
/// let mut priority_queue = PriorityQueueInt::new();
/// priority_queue.push(&1);
/// let mut other = PriorityQueueInt::new();
/// other.push(&2);
/// assert_eq!(priority_queue.top(), Some(&1));
/// assert_eq!(other.top(), Some(&2));
/// priority_queue.swap(&mut other);
/// assert_eq!(priority_queue.top(), Some(&2));
/// assert_eq!(other.top(), Some(&1));
/// ```
#[cpp(method = "void swap(Self&)")]
pub fn swap(&mut self, other: &mut Self);
}
unsafe impl<T: hicc::AbiType + Sync> Send for priority_queue<T> {}
unsafe impl<T: hicc::AbiType + Sync> Sync for priority_queue<T> {}
}