Inserts a new item into the queue, ensuring spatial distancing between items of the same group. Returns true if inserted successfully, false if group is full.
(&mut self, value: Arc<V>)
| 58 | /// Inserts a new item into the queue, ensuring spatial distancing between items of the same group. |
| 59 | /// Returns true if inserted successfully, false if group is full. |
| 60 | pub fn insert(&mut self, value: Arc<V>) -> bool { |
| 61 | //value.trace_message("INSERT"); |
| 62 | match value.group_id() { |
| 63 | None => { |
| 64 | // Control group (group_id is None) |
| 65 | self.ctrl_group.push_back(value); |
| 66 | true |
| 67 | } |
| 68 | Some(group_id) => { |
| 69 | // Regular group |
| 70 | if let Some(group) = self |
| 71 | .groups |
| 72 | .iter_mut() |
| 73 | .find(|group| group.front().map(|v| v.group_id()) == Some(Some(group_id))) |
| 74 | { |
| 75 | if group.len() >= self.max_group_size { |
| 76 | return false; // Group is full |
| 77 | } |
| 78 | group.push_back(value); |
| 79 | } else { |
| 80 | let mut new_group = VecDeque::new(); |
| 81 | new_group.push_back(value); |
| 82 | self.groups.push(new_group); |
| 83 | } |
| 84 | true |
| 85 | } |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | #[inline(always)] |
| 90 | pub fn pop(&mut self) -> Option<Arc<V>> { |