hicc_std/
std_queue.rs

1hicc::cpp! {
2    #include <queue>
3}
4
5hicc::import_class! {
6    #[cpp(class = "template<class T, class Container> std::queue<T, Container>")]
7    pub class queue<T> {
8        /// ```
9        /// use hicc_std::QueueInt;
10        /// let mut queue = QueueInt::new();
11        /// assert!(queue.is_empty());
12        /// queue.push(&1);
13        /// assert!(!queue.is_empty());
14        /// ```
15        #[cpp(method = "bool empty() const")]
16        pub fn is_empty(&self) -> bool;
17
18        /// ```
19        /// use hicc_std::QueueInt;
20        /// let mut queue = QueueInt::new();
21        /// assert_eq!(queue.size(), 0);
22        /// queue.push(&1);
23        /// assert_eq!(queue.size(), 1);
24        /// ```
25        #[cpp(method = "size_t size() const")]
26        pub fn size(&self) -> usize;
27
28        /// 如果为空不做任何改变.
29        /// ```
30        /// use hicc_std::QueueInt;
31        /// let mut queue = QueueInt::new();
32        /// queue.pop();
33        /// queue.push(&1);
34        /// assert_eq!(queue.size(), 1);
35        /// queue.pop();
36        /// assert_eq!(queue.size(), 0);
37        /// ```
38        pub fn pop(&mut self) {
39            if !self.is_empty() {
40                unsafe { self._pop() };
41            }
42        }
43        #[cpp(method = "void pop()")]
44        unsafe fn _pop(&mut self);
45
46        /// ```
47        /// use hicc_std::QueueInt;
48        /// let mut queue = QueueInt::new();
49        /// queue.push(&1);
50        /// queue.push(&2);
51        /// assert_eq!(queue.front(), Some(&1));
52        /// ```
53        #[cpp(method = "void push(const T&)")]
54        pub fn push(&mut self, val: &T);
55
56        /// ```
57        /// use hicc_std::QueueInt;
58        /// let mut queue = QueueInt::new();
59        /// assert_eq!(queue.front(), None);
60        /// queue.push(&1);
61        /// assert_eq!(queue.front(), Some(&1));
62        /// ```
63        pub fn front(&self) -> Option<T::OutputRef<'_>> {
64            if !self.is_empty() {
65                return unsafe { Some(self._front()) };
66            }
67            None
68        }
69        #[cpp(method = "const T& front() const")]
70        unsafe fn _front(&self) -> &T;
71
72        /// ```
73        /// use hicc_std::QueueInt;
74        /// let mut queue = QueueInt::new();
75        /// assert_eq!(queue.front_mut(), None);
76        /// queue.push(&1);
77        /// queue.push(&3);
78        /// *queue.front_mut().unwrap() += 1;
79        /// assert_eq!(queue.front(), Some(&2));
80        ///
81        /// use hicc_std::{string, QueueString};
82        /// use hicc::AbiClass;
83        /// let mut queue = QueueString::new();
84        /// queue.push(&string::from(c"hello"));
85        /// queue.push(&string::new());
86        /// assert_eq!(queue.front(), Some(string::from(c"hello").into_ref()));
87        /// queue.front_mut().unwrap().write(string::from(c"world"));
88        /// assert_eq!(queue.front(), Some(string::from(c"world").into_ref()));
89        /// ```
90        pub fn front_mut(&mut self) -> Option<T::OutputRefMut<'_>> {
91            if !self.is_empty() {
92                return unsafe { Some(self._front_mut()) };
93            }
94            None
95        }
96        #[cpp(method = "T& front()")]
97        unsafe fn _front_mut(&mut self) -> &mut T;
98
99        /// ```
100        /// use hicc_std::QueueInt;
101        /// let mut queue = QueueInt::new();
102        /// assert_eq!(queue.back(), None);
103        /// queue.push(&2);
104        /// queue.push(&1);
105        /// assert_eq!(queue.back(), Some(&1));
106        /// ```
107        pub fn back(&self) -> Option<T::OutputRef<'_>> {
108            if !self.is_empty() {
109                return unsafe { Some(self._back()) };
110            }
111            None
112        }
113        #[cpp(method = "const T& back() const")]
114        unsafe fn _back(&self) -> &T;
115
116        /// ```
117        /// use hicc_std::QueueInt;
118        /// let mut queue = QueueInt::new();
119        /// assert_eq!(queue.back(), None);
120        /// queue.push(&3);
121        /// queue.push(&1);
122        /// *queue.back_mut().unwrap() += 1;
123        /// assert_eq!(queue.back(), Some(&2));
124        ///
125        /// use hicc_std::{string, QueueString};
126        /// use hicc::AbiClass;
127        /// let mut queue = QueueString::new();
128        /// queue.push(&string::new());
129        /// queue.push(&string::from(c"hello"));
130        /// assert_eq!(queue.back(), Some(string::from(c"hello").into_ref()));
131        /// queue.back_mut().unwrap().write(string::from(c"world"));
132        /// assert_eq!(queue.back(), Some(string::from(c"world").into_ref()));
133        /// ```
134        pub fn back_mut(&mut self) -> Option<T::OutputRefMut<'_>> {
135            if !self.is_empty() {
136                return unsafe { Some(self._back_mut()) };
137            }
138            None
139        }
140        #[cpp(method = "T& back()")]
141        unsafe fn _back_mut(&mut self) -> &mut T;
142
143        /// ```
144        /// use hicc_std::QueueInt;
145        /// let mut queue = QueueInt::new();
146        /// queue.push(&1);
147        /// let mut other = QueueInt::new();
148        /// other.push(&2);
149        /// assert_eq!(queue.front(), Some(&1));
150        /// assert_eq!(other.front(), Some(&2));
151        /// queue.swap(&mut other);
152        /// assert_eq!(queue.front(), Some(&2));
153        /// assert_eq!(other.front(), Some(&1));
154        /// ```
155        #[cpp(method = "void swap(Self&)")]
156        pub fn swap(&mut self, other: &mut Self);
157    }
158
159
160    unsafe impl<T: hicc::AbiType + Sync> Send for queue<T> {}
161    unsafe impl<T: hicc::AbiType + Sync> Sync for queue<T> {}
162
163    #[cpp(class = "template<class T, class Container, class Compare> std::priority_queue<T, Container, Compare>")]
164    pub class priority_queue<T> {
165        /// ```
166        /// use hicc_std::PriorityQueueInt;
167        /// let mut priority_queue = PriorityQueueInt::new();
168        /// assert!(priority_queue.is_empty());
169        /// priority_queue.push(&1);
170        /// assert!(!priority_queue.is_empty());
171        /// ```
172        #[cpp(method = "bool empty() const")]
173        pub fn is_empty(&self) -> bool;
174
175        /// ```
176        /// use hicc_std::PriorityQueueInt;
177        /// let mut priority_queue = PriorityQueueInt::new();
178        /// assert_eq!(priority_queue.size(), 0);
179        /// priority_queue.push(&1);
180        /// assert_eq!(priority_queue.size(), 1);
181        /// ```
182        #[cpp(method = "size_t size() const")]
183        pub fn size(&self) -> usize;
184
185        /// 如果为空不做任何改变.
186        /// ```
187        /// use hicc_std::PriorityQueueInt;
188        /// let mut priority_queue = PriorityQueueInt::new();
189        /// priority_queue.pop();
190        /// priority_queue.push(&1);
191        /// assert_eq!(priority_queue.size(), 1);
192        /// priority_queue.pop();
193        /// assert_eq!(priority_queue.size(), 0);
194        /// ```
195        pub fn pop(&mut self) {
196            if !self.is_empty() {
197                unsafe { self._pop(); }
198            }
199        }
200        #[cpp(method = "void pop()")]
201        unsafe fn _pop(&mut self);
202
203        /// ```
204        /// use hicc_std::PriorityQueueInt;
205        /// let mut priority_queue = PriorityQueueInt::new();
206        /// priority_queue.push(&1);
207        /// assert_eq!(priority_queue.top(), Some(&1));
208        /// ```
209        #[cpp(method = "void push(const T&)")]
210        pub fn push(&mut self, val: &T);
211
212        /// ```
213        /// use hicc_std::PriorityQueueInt;
214        /// let mut priority_queue = PriorityQueueInt::new();
215        /// assert_eq!(priority_queue.top(), None);
216        /// priority_queue.push(&1);
217        /// priority_queue.push(&3);
218        /// priority_queue.push(&2);
219        /// assert_eq!(priority_queue.top(), Some(&3));
220        /// ```
221        pub fn top(&self) -> Option<T::OutputRef<'_>> {
222            if !self.is_empty() {
223                return unsafe { Some(self._top()) };
224            }
225            None
226        }
227        #[cpp(method = "const T& top() const")]
228        unsafe fn _top(&self) -> &T;
229
230        /// ```
231        /// use hicc_std::PriorityQueueInt;
232        /// let mut priority_queue = PriorityQueueInt::new();
233        /// priority_queue.push(&1);
234        /// let mut other = PriorityQueueInt::new();
235        /// other.push(&2);
236        /// assert_eq!(priority_queue.top(), Some(&1));
237        /// assert_eq!(other.top(), Some(&2));
238        /// priority_queue.swap(&mut other);
239        /// assert_eq!(priority_queue.top(), Some(&2));
240        /// assert_eq!(other.top(), Some(&1));
241        /// ```
242        #[cpp(method = "void swap(Self&)")]
243        pub fn swap(&mut self, other: &mut Self);
244    }
245
246    unsafe impl<T: hicc::AbiType + Sync> Send for priority_queue<T> {}
247    unsafe impl<T: hicc::AbiType + Sync> Sync for priority_queue<T> {}
248}