Skip to content

Commit a7bafc8

Browse files
committed
scx_utils: fix clippy error.
``` error: you are deriving `Hash` but have implemented `PartialEq` explicitly --> rust/scx_utils/src/energy_model.rs:27:28 | 27 | #[derive(Debug, Clone, Eq, Hash, Ord, PartialOrd)] ``` Signed-off-by: David Carlier <[email protected]>
1 parent 19c58b3 commit a7bafc8

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

rust/scx_utils/src/energy_model.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ use glob::glob;
2121
use num::clamp;
2222
use std::collections::BTreeMap;
2323
use std::fmt;
24+
use std::hash::{Hash, Hasher};
2425
use std::path::Path;
2526
use std::sync::Arc;
2627

27-
#[derive(Debug, Clone, Eq, Hash, Ord, PartialOrd)]
28+
#[derive(Debug, Clone, Eq, Ord, PartialOrd)]
2829
pub struct PerfState {
2930
pub cost: usize,
3031
pub frequency: usize,
@@ -33,7 +34,7 @@ pub struct PerfState {
3334
pub power: usize,
3435
}
3536

36-
#[derive(Debug, Clone, Eq, Hash, Ord, PartialOrd)]
37+
#[derive(Debug, Clone, Eq, Ord, PartialOrd)]
3738
pub struct PerfDomain {
3839
/// Monotonically increasing unique id.
3940
pub id: usize,
@@ -136,6 +137,14 @@ impl PartialEq for PerfDomain {
136137
}
137138
}
138139

140+
impl Hash for PerfDomain {
141+
fn hash<H: Hasher>(&self, state: &mut H) {
142+
self.id.hash(state);
143+
self.span.hash(state);
144+
self.perf_table.hash(state);
145+
}
146+
}
147+
139148
impl PerfState {
140149
/// Build a PerfState
141150
pub fn new(root: String) -> Result<PerfState> {
@@ -164,6 +173,15 @@ impl PartialEq for PerfState {
164173
}
165174
}
166175

176+
impl Hash for PerfState {
177+
fn hash<H: Hasher>(&self, state: &mut H) {
178+
self.cost.hash(state);
179+
self.frequency.hash(state);
180+
self.performance.hash(state);
181+
self.power.hash(state);
182+
}
183+
}
184+
167185
impl fmt::Display for EnergyModel {
168186
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
169187
for (_, pd) in self.perf_doms.iter() {

0 commit comments

Comments
 (0)