mirror of
https://github.com/lisk77/comet.git
synced 2025-10-23 21:38:50 +00:00
fix(ecs): added safety boundaries to the IdQueue
This commit is contained in:
parent
7cf9f5bd29
commit
88fda5c654
1 changed files with 32 additions and 27 deletions
|
@ -1,40 +1,45 @@
|
|||
#[derive(Debug, Clone)]
|
||||
pub struct IdQueue {
|
||||
queue: Vec<u32>
|
||||
queue: Vec<u32>,
|
||||
}
|
||||
|
||||
impl IdQueue {
|
||||
pub fn new() -> Self {
|
||||
Self { queue: Vec::new() }
|
||||
}
|
||||
pub fn new() -> Self {
|
||||
Self { queue: Vec::new() }
|
||||
}
|
||||
|
||||
pub fn from_vec(queue: Vec<u32>) -> Self {
|
||||
Self { queue }
|
||||
}
|
||||
pub fn from_vec(queue: Vec<u32>) -> Self {
|
||||
Self { queue }
|
||||
}
|
||||
|
||||
pub fn front(&self) -> Option<u32> {
|
||||
Some(self.queue[0])
|
||||
}
|
||||
pub fn front(&self) -> Option<u32> {
|
||||
if self.queue.len() > 0 {
|
||||
return Some(self.queue[0]);
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
pub fn enqueue(&mut self, id: u32) {
|
||||
self.queue.push(id)
|
||||
}
|
||||
pub fn enqueue(&mut self, id: u32) {
|
||||
self.queue.push(id)
|
||||
}
|
||||
|
||||
pub fn sorted_enqueue(&mut self, id: u32) {
|
||||
self.enqueue(id);
|
||||
self.queue.sort();
|
||||
}
|
||||
pub fn sorted_enqueue(&mut self, id: u32) {
|
||||
self.enqueue(id);
|
||||
self.queue.sort();
|
||||
}
|
||||
|
||||
pub fn dequeue(&mut self) -> Option<u32> {
|
||||
Some(self.queue.remove(0))
|
||||
pub fn dequeue(&mut self) -> Option<u32> {
|
||||
if self.queue.len() > 0 {
|
||||
return Some(self.queue.remove(0));
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
}
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.queue.len() == 0
|
||||
}
|
||||
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.queue.len() == 0
|
||||
}
|
||||
|
||||
pub fn size(&self) -> u32 {
|
||||
self.queue.len() as u32
|
||||
}
|
||||
pub fn size(&self) -> u32 {
|
||||
self.queue.len() as u32
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue