#[cfg(doc)]
use crate::{bitmap::Bitmap, topology::support::DiscoverySupport};
use crate::{cpu::cpuset::CpuSet, impl_bitmap_newtype, topology::Topology};
#[allow(unused)]
#[cfg(test)]
use similar_asserts::assert_eq;
use std::ops::Deref;
impl NodeSet {
#[doc(alias = "hwloc_cpuset_to_nodeset")]
pub fn from_cpuset(topology: &Topology, cpuset: impl Deref<Target = CpuSet>) -> Self {
fn polymorphized(topology: &Topology, cpuset: &CpuSet) -> NodeSet {
topology
.pus_from_cpuset(cpuset)
.fold(NodeSet::new(), |mut nodeset, pu| {
nodeset |= pu.nodeset().expect("processing units should have nodesets");
nodeset
})
}
polymorphized(topology, &cpuset)
}
}
impl_bitmap_newtype!(
#[doc(alias = "hwloc_nodeset_t")]
#[doc(alias = "hwloc_const_nodeset_t")]
NodeSet
);
#[cfg(test)]
mod tests {
use super::*;
use crate::strategies::topology_related_set;
use proptest::prelude::*;
proptest! {
#[test]
fn nodeset_from_cpuset(
cpuset in topology_related_set(Topology::cpuset),
) {
let topology = Topology::test_instance();
prop_assert_eq!(
NodeSet::from_cpuset(topology, &cpuset),
topology.pus_from_cpuset(&cpuset)
.map(|pu| pu.nodeset().unwrap().clone_target())
.reduce(|set1, set2| set1 | set2)
.unwrap_or_default()
)
}
}
}