hicc_std/
std_queue.rs

1
2hicc::import_class! {
3    /// 对应`std::queue<T>`
4    ///
5    /// 需和`include/hicc/std/queue.hpp`接口定义保持一致.
6    pub class queue<T> {
7        /// ```
8        /// use hicc_std::QueueInt;
9        /// let mut queue = QueueInt::new();
10        /// assert!(queue.is_empty());
11        /// queue.push(&1);
12        /// assert!(!queue.is_empty());
13        /// ```
14        pub fn is_empty(&self) -> bool;
15
16        /// ```
17        /// use hicc_std::QueueInt;
18        /// let mut queue = QueueInt::new();
19        /// assert_eq!(queue.size(), 0);
20        /// queue.push(&1);
21        /// assert_eq!(queue.size(), 1);
22        /// ```
23        pub fn size(&self) -> usize;
24
25        /// ```
26        /// use hicc_std::QueueInt;
27        /// let mut queue = QueueInt::new();
28        /// queue.push(&1);
29        /// assert_eq!(queue.size(), 1);
30        /// queue.pop();
31        /// assert_eq!(queue.size(), 0);
32        /// ```
33        pub fn pop(&mut self);
34
35        /// ```
36        /// use hicc_std::QueueInt;
37        /// let mut queue = QueueInt::new();
38        /// queue.push(&1);
39        /// assert_eq!(queue.front(), &1);
40        /// ```
41        pub fn push(&mut self, val: &T);
42
43        /// ```
44        /// use hicc_std::QueueInt;
45        /// let mut queue = QueueInt::new();
46        /// queue.push(&1);
47        /// queue.push(&2);
48        /// assert_eq!(queue.front(), &1);
49        /// ```
50        pub fn front(&self) -> &T;
51
52        /// ```
53        /// use hicc_std::QueueInt;
54        /// let mut queue = QueueInt::new();
55        /// queue.push(&1);
56        /// queue.push(&3);
57        /// *queue.front_mut() += 1;
58        /// assert_eq!(queue.front(), &2);
59        ///
60        /// use hicc_std::{string, QueueString};
61        /// use hicc::AbiClass;
62        /// let mut queue = QueueString::new();
63        /// queue.push(&string::from(c"hello"));
64        /// queue.push(&string::new());
65        /// assert!(*queue.front() == string::from(c"hello"));
66        /// queue.front_mut().write(string::from(c"world"));
67        /// assert!(*queue.front() == string::from(c"world"));
68        /// ```
69        pub fn front_mut(&self) -> &mut T;
70
71        /// ```
72        /// use hicc_std::QueueInt;
73        /// let mut queue = QueueInt::new();
74        /// queue.push(&2);
75        /// queue.push(&1);
76        /// assert_eq!(queue.back(), &1);
77        /// ```
78        pub fn back(&self) -> &T;
79
80        /// ```
81        /// use hicc_std::QueueInt;
82        /// let mut queue = QueueInt::new();
83        /// queue.push(&3);
84        /// queue.push(&1);
85        /// *queue.back_mut() += 1;
86        /// assert_eq!(queue.back(), &2);
87        ///
88        /// use hicc_std::{string, QueueString};
89        /// use hicc::AbiClass;
90        /// let mut queue = QueueString::new();
91        /// queue.push(&string::new());
92        /// queue.push(&string::from(c"hello"));
93        /// assert!(*queue.back() == string::from(c"hello"));
94        /// queue.back_mut().write(string::from(c"world"));
95        /// assert!(*queue.back() == string::from(c"world"));
96        /// ```
97        pub fn back_mut(&self) -> &mut T;
98
99        /// ```
100        /// use hicc_std::QueueInt;
101        /// let mut queue = QueueInt::new();
102        /// queue.push(&1);
103        /// let mut other = QueueInt::new();
104        /// other.push(&2);
105        /// assert_eq!(queue.front(), &1);
106        /// assert_eq!(other.front(), &2);
107        /// queue.swap(&mut other);
108        /// assert_eq!(queue.front(), &2);
109        /// assert_eq!(other.front(), &1);
110        /// ```
111        pub fn swap(&mut self, other: &mut Self);
112    }
113
114
115    unsafe impl<T: hicc::AbiType + Sync> Send for queue<T> {}
116    unsafe impl<T: hicc::AbiType + Sync> Sync for queue<T> {}
117
118    /// 对应`std::priority_queue<T>`
119    ///
120    /// 需和`include/hicc/std/queue.hpp`接口定义保持一致.
121    pub class priority_queue<T> {
122        /// ```
123        /// use hicc_std::PriorityQueueInt;
124        /// let mut priority_queue = PriorityQueueInt::new();
125        /// assert!(priority_queue.is_empty());
126        /// priority_queue.push(&1);
127        /// assert!(!priority_queue.is_empty());
128        /// ```
129        pub fn is_empty(&self) -> bool;
130
131        /// ```
132        /// use hicc_std::PriorityQueueInt;
133        /// let mut priority_queue = PriorityQueueInt::new();
134        /// assert_eq!(priority_queue.size(), 0);
135        /// priority_queue.push(&1);
136        /// assert_eq!(priority_queue.size(), 1);
137        /// ```
138        pub fn size(&self) -> usize;
139
140        /// ```
141        /// use hicc_std::PriorityQueueInt;
142        /// let mut priority_queue = PriorityQueueInt::new();
143        /// priority_queue.push(&1);
144        /// assert_eq!(priority_queue.size(), 1);
145        /// priority_queue.pop();
146        /// assert_eq!(priority_queue.size(), 0);
147        /// ```
148        pub fn pop(&mut self);
149
150        /// ```
151        /// use hicc_std::PriorityQueueInt;
152        /// let mut priority_queue = PriorityQueueInt::new();
153        /// priority_queue.push(&1);
154        /// assert_eq!(priority_queue.top(), &1);
155        /// ```
156        pub fn push(&mut self, val: &T);
157
158        /// ```
159        /// use hicc_std::PriorityQueueInt;
160        /// let mut priority_queue = PriorityQueueInt::new();
161        /// priority_queue.push(&1);
162        /// priority_queue.push(&3);
163        /// priority_queue.push(&2);
164        /// assert_eq!(priority_queue.top(), &3);
165        /// ```
166        pub fn top(&self) -> &T;
167
168        /// ```
169        /// use hicc_std::PriorityQueueInt;
170        /// let mut priority_queue = PriorityQueueInt::new();
171        /// priority_queue.push(&1);
172        /// let mut other = PriorityQueueInt::new();
173        /// other.push(&2);
174        /// assert_eq!(priority_queue.top(), &1);
175        /// assert_eq!(other.top(), &2);
176        /// priority_queue.swap(&mut other);
177        /// assert_eq!(priority_queue.top(), &2);
178        /// assert_eq!(other.top(), &1);
179        /// ```
180        pub fn swap(&mut self, other: &mut Self);
181    }
182
183    unsafe impl<T: hicc::AbiType + Sync> Send for priority_queue<T> {}
184    unsafe impl<T: hicc::AbiType + Sync> Sync for priority_queue<T> {}
185}