Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
149 changes: 141 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ edition = "2021"
[workspace]
members = [
"process-list",
"performance-queue"
"bounded-queue",
"dynamic-list"
]

authours = ["rhasler1 <rhasler@luc.edu>"]
Expand All @@ -19,4 +20,6 @@ serde = { version = "1.0.188", features = ["derive"] }
anyhow = "1.0.97"
itertools = "0.10.0"
process-list = {path = "./process-list", version = "0.1.0"}
performance-queue = {path = "./performance-queue", version = "0.1.0"}
bounded-queue = {path = "./bounded-queue", version = "0.1.0"}
dynamic-list = {path = "./dynamic-list", version = "0.1.0"}
clippy = "0.0.302"
4 changes: 2 additions & 2 deletions performance-queue/Cargo.toml → bounded-queue/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[package]
name = "performance-queue"
name = "bounded-queue"
version = "0.1.0"
edition = "2021"

authours = ["rhasler1 <rhasler@luc.edu>"]

[dependencies]
[dependencies]
Original file line number Diff line number Diff line change
@@ -1,59 +1,58 @@
use std::{collections::VecDeque, io};

Check warning on line 1 in bounded-queue/src/bounded_queue.rs

View workflow job for this annotation

GitHub Actions / Unit Tests (macos-latest, stable)

unused import: `io`

Check warning on line 1 in bounded-queue/src/bounded_queue.rs

View workflow job for this annotation

GitHub Actions / Unit Tests (macos-latest, stable)

unused import: `io`

Check warning on line 1 in bounded-queue/src/bounded_queue.rs

View workflow job for this annotation

GitHub Actions / Unit Tests (ubuntu-latest, stable)

unused import: `io`

Check warning on line 1 in bounded-queue/src/bounded_queue.rs

View workflow job for this annotation

GitHub Actions / Unit Tests (ubuntu-latest, stable)

unused import: `io`

Check warning on line 1 in bounded-queue/src/bounded_queue.rs

View workflow job for this annotation

GitHub Actions / Unit Tests (windows-latest, stable)

unused import: `io`

Check warning on line 1 in bounded-queue/src/bounded_queue.rs

View workflow job for this annotation

GitHub Actions / Unit Tests (windows-latest, stable)

unused import: `io`

Check warning on line 1 in bounded-queue/src/bounded_queue.rs

View workflow job for this annotation

GitHub Actions / Unit Tests (macos-latest, stable)

unused import: `io`

Check warning on line 1 in bounded-queue/src/bounded_queue.rs

View workflow job for this annotation

GitHub Actions / Unit Tests (macos-latest, stable)

unused import: `io`

Check warning on line 1 in bounded-queue/src/bounded_queue.rs

View workflow job for this annotation

GitHub Actions / Unit Tests (ubuntu-latest, stable)

unused import: `io`

Check warning on line 1 in bounded-queue/src/bounded_queue.rs

View workflow job for this annotation

GitHub Actions / Unit Tests (ubuntu-latest, stable)

unused import: `io`

Check warning on line 1 in bounded-queue/src/bounded_queue.rs

View workflow job for this annotation

GitHub Actions / Unit Tests (windows-latest, stable)

unused import: `io`

Check warning on line 1 in bounded-queue/src/bounded_queue.rs

View workflow job for this annotation

GitHub Actions / Unit Tests (windows-latest, stable)

unused import: `io`

#[derive(Default)]
pub struct PerformanceQueue<T> {
pub performance_items: VecDeque<T>,
pub struct BoundedQueue<T> {
pub items: VecDeque<T>,
capacity: usize,
}

// Clone trait is required for T to clone elements when adding items.
impl<T: Clone> PerformanceQueue<T> {
impl<T: Clone> BoundedQueue<T> {
pub fn new(capacity: usize) -> Self {
Self {
performance_items: VecDeque::with_capacity(capacity),
items: VecDeque::with_capacity(capacity),
capacity,
}
}

pub fn add_item(&mut self, item: &T) {
if self.performance_items.len() < self.capacity {
let item = item.clone();
self.performance_items.push_back(item);
pub fn add_item(&mut self, item: T) {
let len = self.items.len();

if len < self.capacity {
self.items.push_back(item);
}
else if self.performance_items.len() == self.capacity {
self.performance_items.pop_front();
let item = item.clone();
self.performance_items.push_back(item);
else if len == self.capacity {
self.items.pop_front();
self.items.push_back(item);
}
else {
while self.performance_items.len() >= self.capacity {
self.performance_items.pop_front();
else { // should never occur
while len >= self.capacity {
self.items.pop_front();
}
let item = item.clone();
self.performance_items.push_back(item);
self.items.push_back(item);
}
}

pub fn front(&self) -> Option<&T> {
return self.performance_items.front()
self.items.front()
}

pub fn back(&self) -> Option<&T> {
return self.performance_items.back()
self.items.back()
}

pub fn capacity(&self) -> usize {
self.capacity
}

pub fn iter(&self) -> std::collections::vec_deque::Iter<'_, T> {
self.performance_items.iter()
self.items.iter()
}
}

#[cfg(test)]
mod test {
use super::PerformanceQueue;
use super::BoundedQueue;
use crate::CpuItem;

/*#[test]
Expand All @@ -73,4 +72,4 @@
assert_eq!(instance.back().unwrap().global_usage(), 15.7);
assert_eq!(instance.front().unwrap().global_usage(), 13.2);
}*/
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
id: usize,
usage: f32,
frequency: u64,
name: String,

Check warning on line 6 in bounded-queue/src/cpu_item.rs

View workflow job for this annotation

GitHub Actions / Unit Tests (macos-latest, stable)

fields `name` and `vendor_id` are never read

Check warning on line 6 in bounded-queue/src/cpu_item.rs

View workflow job for this annotation

GitHub Actions / Unit Tests (macos-latest, stable)

fields `name` and `vendor_id` are never read

Check warning on line 6 in bounded-queue/src/cpu_item.rs

View workflow job for this annotation

GitHub Actions / Unit Tests (ubuntu-latest, stable)

fields `name` and `vendor_id` are never read

Check warning on line 6 in bounded-queue/src/cpu_item.rs

View workflow job for this annotation

GitHub Actions / Unit Tests (ubuntu-latest, stable)

fields `name` and `vendor_id` are never read

Check warning on line 6 in bounded-queue/src/cpu_item.rs

View workflow job for this annotation

GitHub Actions / Unit Tests (windows-latest, stable)

fields `name` and `vendor_id` are never read

Check warning on line 6 in bounded-queue/src/cpu_item.rs

View workflow job for this annotation

GitHub Actions / Unit Tests (windows-latest, stable)

fields `name` and `vendor_id` are never read

Check warning on line 6 in bounded-queue/src/cpu_item.rs

View workflow job for this annotation

GitHub Actions / Unit Tests (macos-latest, stable)

fields `name` and `vendor_id` are never read

Check warning on line 6 in bounded-queue/src/cpu_item.rs

View workflow job for this annotation

GitHub Actions / Unit Tests (macos-latest, stable)

fields `name` and `vendor_id` are never read

Check warning on line 6 in bounded-queue/src/cpu_item.rs

View workflow job for this annotation

GitHub Actions / Unit Tests (ubuntu-latest, stable)

fields `name` and `vendor_id` are never read

Check warning on line 6 in bounded-queue/src/cpu_item.rs

View workflow job for this annotation

GitHub Actions / Unit Tests (ubuntu-latest, stable)

fields `name` and `vendor_id` are never read

Check warning on line 6 in bounded-queue/src/cpu_item.rs

View workflow job for this annotation

GitHub Actions / Unit Tests (windows-latest, stable)

fields `name` and `vendor_id` are never read

Check warning on line 6 in bounded-queue/src/cpu_item.rs

View workflow job for this annotation

GitHub Actions / Unit Tests (windows-latest, stable)

fields `name` and `vendor_id` are never read
brand: String,
vendor_id: String,
}
Expand Down Expand Up @@ -71,4 +71,4 @@
assert_eq!(instance.brand(), String::from("Apple"));
}
*/
}
}
2 changes: 1 addition & 1 deletion performance-queue/src/lib.rs → bounded-queue/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ mod bounded_queue;

pub use cpu_item::CpuItem;
pub use memory_item::MemoryItem;
pub use bounded_queue::PerformanceQueue;
pub use bounded_queue::BoundedQueue;
Loading
Loading