mirror of
https://github.com/lisk77/comet.git
synced 2025-10-26 06:38:50 +00:00
initial commit
This commit is contained in:
commit
6154c72b0e
55 changed files with 9481 additions and 0 deletions
40
crates/comet_ecs/src/id.rs
Normal file
40
crates/comet_ecs/src/id.rs
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
#[derive(Debug, Clone)]
|
||||
pub struct IdQueue {
|
||||
queue: Vec<u32>
|
||||
}
|
||||
|
||||
impl IdQueue {
|
||||
pub fn new() -> Self {
|
||||
Self { queue: Vec::new() }
|
||||
}
|
||||
|
||||
pub fn from_vec(queue: Vec<u32>) -> Self {
|
||||
Self { queue }
|
||||
}
|
||||
|
||||
pub fn front(&self) -> Option<u32> {
|
||||
Some(self.queue[0])
|
||||
}
|
||||
|
||||
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 dequeue(&mut self) -> Option<u32> {
|
||||
Some(self.queue.remove(0))
|
||||
|
||||
}
|
||||
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.queue.len() == 0
|
||||
}
|
||||
|
||||
pub fn size(&self) -> u32 {
|
||||
self.queue.len() as u32
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue