| ... | @@ -180,12 +180,24 @@ pub fn Deque(comptime T: type) type { | ... | @@ -180,12 +180,24 @@ pub fn Deque(comptime T: type) type { |
| 180 | return deque.buffer[deque.head]; | 180 | return deque.buffer[deque.head]; |
| 181 | } | 181 | } |
| 182 | | 182 | |
| | 183 | /// Return pointer to the first item in the deque or null if empty. |
| | 184 | pub fn frontPtr(deque: *const Self) ?*T { |
| | 185 | if (deque.len == 0) return null; |
| | 186 | return &deque.buffer[deque.head]; |
| | 187 | } |
| | 188 | |
| 183 | /// Return the last item in the deque or null if empty. | 189 | /// Return the last item in the deque or null if empty. |
| 184 | pub fn back(deque: *const Self) ?T { | 190 | pub fn back(deque: *const Self) ?T { |
| 185 | if (deque.len == 0) return null; | 191 | if (deque.len == 0) return null; |
| 186 | return deque.buffer[deque.bufferIndex(deque.len - 1)]; | 192 | return deque.buffer[deque.bufferIndex(deque.len - 1)]; |
| 187 | } | 193 | } |
| 188 | | 194 | |
| | 195 | /// Return the last item in the deque or null if empty. |
| | 196 | pub fn backPtr(deque: *const Self) ?*T { |
| | 197 | if (deque.len == 0) return null; |
| | 198 | return &deque.buffer[deque.bufferIndex(deque.len - 1)]; |
| | 199 | } |
| | 200 | |
| 189 | /// Return the item at the given index in the deque. | 201 | /// Return the item at the given index in the deque. |
| 190 | /// | 202 | /// |
| 191 | /// The first item in the queue is at index 0. | 203 | /// The first item in the queue is at index 0. |
| ... | @@ -196,6 +208,16 @@ pub fn Deque(comptime T: type) type { | ... | @@ -196,6 +208,16 @@ pub fn Deque(comptime T: type) type { |
| 196 | return deque.buffer[deque.bufferIndex(index)]; | 208 | return deque.buffer[deque.bufferIndex(index)]; |
| 197 | } | 209 | } |
| 198 | | 210 | |
| | 211 | /// Return pointer to the item at the given index in the deque. |
| | 212 | /// |
| | 213 | /// The first item in the queue is at index 0. |
| | 214 | /// |
| | 215 | /// Asserts that the index is in-bounds. |
| | 216 | pub fn atPtr(deque: *const Self, index: usize) *T { |
| | 217 | assert(index < deque.len); |
| | 218 | return &deque.buffer[deque.bufferIndex(index)]; |
| | 219 | } |
| | 220 | |
| 199 | /// Remove and return the first item in the deque or null if empty. | 221 | /// Remove and return the first item in the deque or null if empty. |
| 200 | pub fn popFront(deque: *Self) ?T { | 222 | pub fn popFront(deque: *Self) ?T { |
| 201 | if (deque.len == 0) return null; | 223 | if (deque.len == 0) return null; |