Skip to content

Commit 8eaf7f8

Browse files
committed
lib: diff two &[MergeHashKaniList]
1 parent eb9b9cf commit 8eaf7f8

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/diff.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::{BoxStr, ProofKind, SerFunction};
22
use indexmap::{IndexMap, IndexSet};
33
use serde::{Deserialize, Serialize};
44
use std::{
5+
collections::HashSet,
56
hash::Hash,
67
path::{Component, MAIN_SEPARATOR, Path, PathBuf},
78
};
@@ -246,11 +247,18 @@ impl MergedHarnesses<'_> {
246247
}
247248

248249
/// Merge hash json and kani-list.
249-
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
250+
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
250251
pub struct MergeHashKaniList {
251252
pub file: Box<str>,
252253
pub func: Box<str>,
253254
#[serde(skip_serializing_if = "Option::is_none")]
254255
#[serde(default)]
255256
pub hash: Option<Box<str>>,
256257
}
258+
259+
/// Compare two `MergeHashKaniList`, and returns the ones from new that don't have hash values or
260+
/// whoes hash values changed.
261+
pub fn diff(old: &[MergeHashKaniList], new: &[MergeHashKaniList]) -> Vec<MergeHashKaniList> {
262+
let set: HashSet<_> = old.iter().collect();
263+
new.iter().filter(|item| !set.contains(item)).cloned().collect()
264+
}

0 commit comments

Comments
 (0)