1
0

fix: fix kernel common module build issue

This commit is contained in:
2026-06-28 22:30:32 +08:00
parent aa6c4f72bd
commit cca66b0cac
5 changed files with 202 additions and 244 deletions

View File

@@ -1,50 +1,6 @@
use strum::IntoEnumIterator;
use strum_macros::EnumIter; use strum_macros::EnumIter;
use thiserror::Error as TeError; use thiserror::Error as TeError;
// /// The error thrown by LCR Connector.
// #[derive(Debug, TeError)]
// pub enum LcrConnError {
// #[error("Device value must be greater than 0")]
// InvalidDeviceValue,
// #[error("Third device cannot exist without second device")]
// ThirdDeviceWithoutSecond,
// #[error("No second device")]
// NoSecondDevice,
// #[error("No third device")]
// NoThirdDevice,
// #[error("Invalid value {0} in dataset")]
// InvalidDatasetValue(f64),
// #[error("Unexpected empty string in dataset item")]
// EmptyDatasetItem,
// #[error("Duplicate item {0} in standard value list")]
// DuplicateDatasetItem(String),
// #[error("Empty standard value list is not allowed")]
// EmptyDataset,
// #[error("Invalid value {0} for target value in request")]
// InvalidTargetValue(f64),
// #[error("Invalid value {0} for tolerance in request")]
// InvalidTolerance(f64),
// #[error("Too large or too less value {0} for response count limit in request")]
// InvalidCountLimit(usize),
// #[error("Invalid human readable value: {0}")]
// InvalidHumanReadableValue(String),
// #[error(transparent)]
// Io(#[from] std::io::Error),
// }
/// The kind of device. /// The kind of device.
#[derive(Debug, Clone, Copy)] #[derive(Debug, Clone, Copy)]
pub enum DeviceKind { pub enum DeviceKind {
@@ -79,6 +35,17 @@ impl JointKind {
} }
} }
/// Error occurs when manipulating [SubCircuit].
#[derive(Debug, TeError)]
pub enum SubCircuitError {
#[error("given circuit device value {0} should greater than zero")]
BadDeviceValue(f64),
#[error("the previous computed circuit value {0} should greater than zero")]
BadPreviousValue(f64),
#[error("bad float point arithmetic")]
BadArithmetic,
}
/// The part of circuit composed of two devices and the joint kind. /// The part of circuit composed of two devices and the joint kind.
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct SubCircuit { pub struct SubCircuit {
@@ -91,54 +58,46 @@ pub struct SubCircuit {
impl SubCircuit { impl SubCircuit {
/// Initialize subcircuit with given device value and joint kind. /// Initialize subcircuit with given device value and joint kind.
/// ///
/// # Panics /// The input device value should greater than zero,
/// /// otherwise an error will return.
/// This function will panic if given device value is equal or lower than zero. pub fn new(device_value: f64, joint_kind: JointKind) -> Result<Self, SubCircuitError> {
pub fn new(device_value: f64, joint_kind: JointKind) -> Self { if device_value > 0f64 {
// Make sure value is greater than zero. Ok(Self {
assert!( device_value,
device_value > 0f64, joint_kind,
"given device value {} should greater than zero", })
device_value } else {
); Err(SubCircuitError::BadDeviceValue(device_value))
// Okey, build and return self
Self {
device_value,
joint_kind,
} }
} }
/// Compute the joint value. /// Compute the joint value with given previous computed value and device kind.
/// ///
/// # Arguments /// Parameter `value` should be the value computed from previous devices.
/// /// And it should greater than zero.
/// * `value` - The value computed from previous devices. /// `device_kind` is the kind of the device.
/// * `device_kind` - The kind of the device. pub fn compute(&self, value: f64, device_kind: DeviceKind) -> Result<f64, SubCircuitError> {
/// // Check the range of provided value for computing
/// # Returns if !(value > 0f64) {
/// return Err(SubCircuitError::BadPreviousValue(value));
/// The joint value computed.
///
/// # Errors
///
/// Returns [`LcrConnError::InvalidDeviceValue`] if any device value is not greater than 0.
pub fn compute(&self, value: f64, device_kind: DeviceKind) -> Result<f64, LcrConnError> {
if self.device_value <= 0.0 || value <= 0.0 {
return Err(LcrConnError::InvalidDeviceValue);
} }
// We perform series connect for: series resistor, series inductor and parallel capacitor. // We perform series connect for: series resistor, series inductor and parallel capacitor.
// We perform parallel connect for: parallel resistor, parallel inductor and series capacitor. // We perform parallel connect for: parallel resistor, parallel inductor and series capacitor.
let joint_kind = if device_kind == DeviceKind::Capacitor { let joint_kind = match device_kind {
self.joint_kind.flip() DeviceKind::Capacitor => self.joint_kind.flip(),
} else { _ => self.joint_kind,
self.joint_kind
}; };
Ok(match joint_kind { let rv = match joint_kind {
JointKind::Series => self.device_value + value, JointKind::Series => self.device_value + value,
JointKind::Parallel => (self.device_value * value) / (self.device_value + value), JointKind::Parallel => (self.device_value * value) / (self.device_value + value),
}) };
if rv.is_finite() {
Ok(rv)
} else {
Err(SubCircuitError::BadArithmetic)
}
} }
/// Get the device value. /// Get the device value.
@@ -153,7 +112,7 @@ impl SubCircuit {
} }
/// The scale of devices in the circuit. /// The scale of devices in the circuit.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] #[derive(Debug, Clone, Copy)]
pub enum CircuitDeviceScale { pub enum CircuitDeviceScale {
/// One device. /// One device.
One, One,
@@ -165,10 +124,7 @@ pub enum CircuitDeviceScale {
impl CircuitDeviceScale { impl CircuitDeviceScale {
/// Convert circuit device scale to device count. /// Convert circuit device scale to device count.
/// /// The return value only can be 1, 2, and 3.
/// # Returns
///
/// The device count.
pub fn to_device_count(self) -> usize { pub fn to_device_count(self) -> usize {
match self { match self {
CircuitDeviceScale::One => 1, CircuitDeviceScale::One => 1,
@@ -178,6 +134,19 @@ impl CircuitDeviceScale {
} }
} }
/// Error occurs when manipulating [Circuit].
#[derive(Debug, TeError)]
pub enum CircuitError {
#[error("given circuit device value {0} should greater than zero")]
BadDeviceValue(f64),
#[error("third device cannot exist without second device when building circuit")]
BlankSecondSubCircuit,
#[error("{0}")]
SubCircuit(#[from] SubCircuitError),
#[error("the joint or device with given index is not presented in circuit")]
NoSuchDevice,
}
/// The circuit composed of multiple joints. /// The circuit composed of multiple joints.
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct Circuit { pub struct Circuit {
@@ -190,27 +159,26 @@ pub struct Circuit {
} }
impl Circuit { impl Circuit {
/// Initialize the circuit. /// Initialize the circuit with subcircuit.
///
/// # Arguments
/// ///
/// * `first_device_value` - The value of the first device. /// * `first_device_value` - The value of the first device.
/// * `second_device_subckt` - The second device and its joint property. /// * `second_device_subckt` - The second device and its joint property.
/// * `third_device_subckt` - The third device and its joint property. /// * `third_device_subckt` - The third device and its joint property.
/// fn new(
/// # Errors
///
/// Returns [`LcrConnError::ThirdDeviceWithoutSecond`] if a third device is provided
/// without a second device.
pub fn new(
first_device_value: f64, first_device_value: f64,
second_device_subckt: Option<SubCircuit>, second_device_subckt: Option<SubCircuit>,
third_device_subckt: Option<SubCircuit>, third_device_subckt: Option<SubCircuit>,
) -> Result<Self, LcrConnError> { ) -> Result<Self, CircuitError> {
// Check the value of first device
if !(first_device_value > 0f64) {
return Err(CircuitError::BadDeviceValue(first_device_value));
}
// Check impossible form
if second_device_subckt.is_none() && third_device_subckt.is_some() { if second_device_subckt.is_none() && third_device_subckt.is_some() {
return Err(LcrConnError::ThirdDeviceWithoutSecond); return Err(CircuitError::BlankSecondSubCircuit);
} }
// Everything is okey
Ok(Self { Ok(Self {
first_device_value, first_device_value,
second_device_subckt, second_device_subckt,
@@ -219,12 +187,8 @@ impl Circuit {
} }
/// Create a circuit from a single device. /// Create a circuit from a single device.
pub fn from_one_device(device1_value: f64) -> Self { pub fn from_one_device(device1_value: f64) -> Result<Self, CircuitError> {
Self { Self::new(device1_value, None, None)
first_device_value: device1_value,
second_device_subckt: None,
third_device_subckt: None,
}
} }
/// Create a circuit from two devices. /// Create a circuit from two devices.
@@ -232,12 +196,12 @@ impl Circuit {
device1_value: f64, device1_value: f64,
device2_value: f64, device2_value: f64,
device2_joint: JointKind, device2_joint: JointKind,
) -> Self { ) -> Result<Self, CircuitError> {
Self { Self::new(
first_device_value: device1_value, device1_value,
second_device_subckt: Some(SubCircuit::new(device2_value, device2_joint)), Some(SubCircuit::new(device2_value, device2_joint)?),
third_device_subckt: None, None,
} )
} }
/// Create a circuit from three devices. /// Create a circuit from three devices.
@@ -247,41 +211,28 @@ impl Circuit {
device2_joint: JointKind, device2_joint: JointKind,
device3_value: f64, device3_value: f64,
device3_joint: JointKind, device3_joint: JointKind,
) -> Self { ) -> Result<Self, CircuitError> {
Self { Self::new(
first_device_value: device1_value, device1_value,
second_device_subckt: Some(SubCircuit::new(device2_value, device2_joint)), Some(SubCircuit::new(device2_value, device2_joint)?),
third_device_subckt: Some(SubCircuit::new(device3_value, device3_joint)), Some(SubCircuit::new(device3_value, device3_joint)?),
} )
} }
/// Compute the circuit value. /// Compute the circuit value with given value and device kind
/// pub fn compute(&self, device_kind: DeviceKind) -> Result<f64, CircuitError> {
/// # Arguments let mut value = self.first_device_value;
///
/// * `device_kind` - The kind of the device. match &self.second_device_subckt {
/// Some(subckt) => value = subckt.compute(value, device_kind)?,
/// # Returns None => return Ok(value),
///
/// The circuit value.
///
/// # Errors
///
/// Returns [`LcrConnError::InvalidDeviceValue`] if any device value is not greater than 0.
pub fn compute(&self, device_kind: DeviceKind) -> Result<f64, LcrConnError> {
if self.first_device_value <= 0.0 {
return Err(LcrConnError::InvalidDeviceValue);
} }
let mut value = self.first_device_value; match &self.third_device_subckt {
if let Some(subckt) = &self.second_device_subckt { Some(subckt) => value = subckt.compute(value, device_kind)?,
value = subckt.compute(value, device_kind)?; None => return Ok(value),
} else {
return Ok(value);
}
if let Some(subckt) = &self.third_device_subckt {
value = subckt.compute(value, device_kind)?;
} }
Ok(value) Ok(value)
} }
@@ -306,82 +257,76 @@ impl Circuit {
} }
/// Get the joint kind of the second device. /// Get the joint kind of the second device.
/// pub fn second_device_joint(&self) -> Result<JointKind, CircuitError> {
/// # Errors
///
/// Returns [`LcrConnError::NoSecondDevice`] if there is no second device.
pub fn second_device_joint(&self) -> Result<JointKind, LcrConnError> {
self.second_device_subckt self.second_device_subckt
.as_ref()
.map(|s| s.joint_kind()) .map(|s| s.joint_kind())
.ok_or(LcrConnError::NoSecondDevice) .ok_or(CircuitError::NoSuchDevice)
} }
/// Get the value of the second device. /// Get the value of the second device.
/// pub fn second_device_value(&self) -> Result<f64, CircuitError> {
/// # Errors
///
/// Returns [`LcrConnError::NoSecondDevice`] if there is no second device.
pub fn second_device_value(&self) -> Result<f64, LcrConnError> {
self.second_device_subckt self.second_device_subckt
.as_ref()
.map(|s| s.device_value()) .map(|s| s.device_value())
.ok_or(LcrConnError::NoSecondDevice) .ok_or(CircuitError::NoSuchDevice)
} }
/// Get the joint kind of the third device. /// Get the joint kind of the third device.
/// pub fn third_device_joint(&self) -> Result<JointKind, CircuitError> {
/// # Errors
///
/// Returns [`LcrConnError::NoThirdDevice`] if there is no third device.
pub fn third_device_joint(&self) -> Result<JointKind, LcrConnError> {
self.third_device_subckt self.third_device_subckt
.as_ref()
.map(|s| s.joint_kind()) .map(|s| s.joint_kind())
.ok_or(LcrConnError::NoThirdDevice) .ok_or(CircuitError::NoSuchDevice)
} }
/// Get the value of the third device. /// Get the value of the third device.
/// pub fn third_device_value(&self) -> Result<f64, CircuitError> {
/// # Errors
///
/// Returns [`LcrConnError::NoThirdDevice`] if there is no third device.
pub fn third_device_value(&self) -> Result<f64, LcrConnError> {
self.third_device_subckt self.third_device_subckt
.as_ref()
.map(|s| s.device_value()) .map(|s| s.device_value())
.ok_or(LcrConnError::NoThirdDevice) .ok_or(CircuitError::NoSuchDevice)
} }
} }
/// Error occurs when manipulating [CircuitCalculator].
#[derive(Debug, TeError)]
pub enum CircuitCalculatorError {
#[error("given target value {0} should be greater than zero")]
BadTargetValue(f64),
#[error("{0}")]
Circuit(#[from] CircuitError),
#[error("bad float point arithmetic")]
BadArithmetic,
#[error("provided value {0} reducing computation steps is invalid")]
BadReuseValue(f64),
}
/// The helper for circuit value computation. /// The helper for circuit value computation.
#[derive(Clone, Debug)] #[derive(Debug, Clone)]
pub struct CircuitValueTrait { pub struct CircuitCalculator {
/// The kind of the device. /// The kind of the device.
device_kind: DeviceKind, device_kind: DeviceKind,
/// The target value. /// The target value.
target_value: f64, target_value: f64,
} }
impl CircuitValueTrait { impl CircuitCalculator {
pub fn new(device_kind: DeviceKind, target_value: f64) -> Self { /// Initialize this calculator with given device kind and target value.
Self { pub fn new(device_kind: DeviceKind, target_value: f64) -> Result<Self, CircuitCalculatorError> {
device_kind, if target_value > 0f64 {
target_value, Ok(Self {
device_kind,
target_value,
})
} else {
Err(CircuitCalculatorError::BadTargetValue(target_value))
} }
} }
/// The value of this circuit. /// The value of this circuit.
/// pub fn value(&self, circuit: &Circuit) -> Result<f64, CircuitCalculatorError> {
/// # Arguments Ok(circuit.compute(self.device_kind)?)
///
/// * `circuit` - The circuit for computation.
///
/// # Returns
///
/// The value.
///
/// # Errors
///
/// See [`Circuit::compute`].
pub fn value(&self, circuit: &Circuit) -> Result<f64, LcrConnError> {
circuit.compute(self.device_kind)
} }
/// The signed difference between the target value and the value of this circuit. /// The signed difference between the target value and the value of this circuit.
@@ -389,56 +334,64 @@ impl CircuitValueTrait {
/// Positive value indicates that the value of this circuit is greater than the target value. /// Positive value indicates that the value of this circuit is greater than the target value.
/// Negative value indicates that the value of this circuit is less than the target value. /// Negative value indicates that the value of this circuit is less than the target value.
/// ///
/// # Arguments
///
/// * `circuit` - The circuit for computation. /// * `circuit` - The circuit for computation.
/// * `value` - The value of the circuit computed by the [`value`](Self::value) method /// * `value` - The value of the circuit computed by the [`value`](Self::value) method
/// for reducing computation steps, or `None` if you request this method to compute the value. /// for reducing computation steps, or `None` if you request this method to compute the value.
/// pub fn difference(
/// # Returns &self,
/// circuit: &Circuit,
/// The signed difference. value: Option<f64>,
/// ) -> Result<f64, CircuitCalculatorError> {
/// # Errors
///
/// See [`Circuit::compute`].
pub fn difference(&self, circuit: &Circuit, value: Option<f64>) -> Result<f64, LcrConnError> {
let value = match value { let value = match value {
Some(v) => v, Some(v) => {
if v.is_finite() {
v
} else {
return Err(CircuitCalculatorError::BadReuseValue(v));
}
}
None => self.value(circuit)?, None => self.value(circuit)?,
}; };
Ok(value - self.target_value)
let rv = value - self.target_value;
if rv.is_finite() {
Ok(rv)
} else {
Err(CircuitCalculatorError::BadArithmetic)
}
} }
/// The unsigned difference between the target value and the value of this circuit. /// The unsigned difference between the target value and the value of this circuit.
/// ///
/// # Arguments
///
/// * `circuit` - The circuit for computation. /// * `circuit` - The circuit for computation.
/// * `value` - The value of the circuit computed by the [`value`](Self::value) method /// * `value` - The value of the circuit computed by the [`value`](Self::value) method
/// for reducing computation steps, or `None` if you request this method to compute the value. /// for reducing computation steps, or `None` if you request this method to compute the value.
/// * `difference` - The difference of the circuit computed by the /// * `difference` - The difference of the circuit computed by the
/// [`difference`](Self::difference) method for reducing computation steps, /// [`difference`](Self::difference) method for reducing computation steps,
/// or `None` if you request this method to compute the difference. /// or `None` if you request this method to compute the difference.
///
/// # Returns
///
/// The unsigned difference.
///
/// # Errors
///
/// See [`Circuit::compute`].
pub fn unsigned_difference( pub fn unsigned_difference(
&self, &self,
circuit: &Circuit, circuit: &Circuit,
value: Option<f64>, value: Option<f64>,
difference: Option<f64>, difference: Option<f64>,
) -> Result<f64, LcrConnError> { ) -> Result<f64, CircuitCalculatorError> {
let diff = match difference { let diff = match difference {
Some(d) => d, Some(d) => {
if d.is_finite() {
d
} else {
return Err(CircuitCalculatorError::BadReuseValue(d));
}
}
None => self.difference(circuit, value)?, None => self.difference(circuit, value)?,
}; };
Ok(diff.abs())
let rv = diff.abs();
if rv.is_finite() {
Ok(rv)
} else {
Err(CircuitCalculatorError::BadArithmetic)
}
} }
/// The signed relative difference between the target value and the value of this circuit. /// The signed relative difference between the target value and the value of this circuit.
@@ -446,39 +399,39 @@ impl CircuitValueTrait {
/// Positive value indicates that the value of this circuit is greater than the target value. /// Positive value indicates that the value of this circuit is greater than the target value.
/// Negative value indicates that the value of this circuit is less than the target value. /// Negative value indicates that the value of this circuit is less than the target value.
/// ///
/// # Arguments
///
/// * `circuit` - The circuit for computation. /// * `circuit` - The circuit for computation.
/// * `value` - The value of the circuit computed by the [`value`](Self::value) method /// * `value` - The value of the circuit computed by the [`value`](Self::value) method
/// for reducing computation steps, or `None` if you request this method to compute the value. /// for reducing computation steps, or `None` if you request this method to compute the value.
/// * `difference` - The difference of the circuit computed by the /// * `difference` - The difference of the circuit computed by the
/// [`difference`](Self::difference) method for reducing computation steps, /// [`difference`](Self::difference) method for reducing computation steps,
/// or `None` if you request this method to compute the difference. /// or `None` if you request this method to compute the difference.
///
/// # Returns
///
/// The signed relative difference.
///
/// # Errors
///
/// See [`Circuit::compute`].
pub fn relative_difference( pub fn relative_difference(
&self, &self,
circuit: &Circuit, circuit: &Circuit,
value: Option<f64>, value: Option<f64>,
difference: Option<f64>, difference: Option<f64>,
) -> Result<f64, LcrConnError> { ) -> Result<f64, CircuitCalculatorError> {
let diff = match difference { let diff = match difference {
Some(d) => d, Some(d) => {
if d.is_finite() {
d
} else {
return Err(CircuitCalculatorError::BadReuseValue(d));
}
}
None => self.difference(circuit, value)?, None => self.difference(circuit, value)?,
}; };
Ok(diff / self.target_value)
let rv = diff / self.target_value;
if rv.is_finite() {
Ok(rv)
} else {
Err(CircuitCalculatorError::BadArithmetic)
}
} }
/// The unsigned relative difference between the target value and the value of this circuit. /// The unsigned relative difference between the target value and the value of this circuit.
/// ///
/// # Arguments
///
/// * `circuit` - The circuit for computation. /// * `circuit` - The circuit for computation.
/// * `value` - The value of the circuit computed by the [`value`](Self::value) method /// * `value` - The value of the circuit computed by the [`value`](Self::value) method
/// for reducing computation steps, or `None` if you request this method to compute the value. /// for reducing computation steps, or `None` if you request this method to compute the value.
@@ -489,24 +442,29 @@ impl CircuitValueTrait {
/// [`relative_difference`](Self::relative_difference) method for reducing computation steps, /// [`relative_difference`](Self::relative_difference) method for reducing computation steps,
/// or `None` if you request this method to compute the relative difference. /// or `None` if you request this method to compute the relative difference.
/// ///
/// # Returns
///
/// The unsigned relative difference.
///
/// # Errors
///
/// See [`Circuit::compute`].
pub fn unsigned_relative_difference( pub fn unsigned_relative_difference(
&self, &self,
circuit: &Circuit, circuit: &Circuit,
value: Option<f64>, value: Option<f64>,
difference: Option<f64>, difference: Option<f64>,
relative_difference: Option<f64>, relative_difference: Option<f64>,
) -> Result<f64, LcrConnError> { ) -> Result<f64, CircuitCalculatorError> {
let rel_diff = match relative_difference { let rel_diff = match relative_difference {
Some(rd) => rd, Some(rd) => {
if rd.is_finite() {
rd
} else {
return Err(CircuitCalculatorError::BadReuseValue(rd));
}
}
None => self.relative_difference(circuit, value, difference)?, None => self.relative_difference(circuit, value, difference)?,
}; };
Ok(rel_diff.abs())
let rv = rel_diff.abs();
if rv.is_finite() {
Ok(rv)
} else {
Err(CircuitCalculatorError::BadArithmetic)
}
} }
} }

View File

@@ -4,7 +4,7 @@ pub mod query;
pub mod resolver; pub mod resolver;
pub use common::{ pub use common::{
Circuit, CircuitDeviceScale, CircuitValueTrait, DeviceKind, JointKind, LcrConnError, SubCircuit, Circuit, CircuitDeviceScale, CircuitCalculator, DeviceKind, JointKind, LcrConnError, SubCircuit,
}; };
pub use dataset::{ pub use dataset::{
from_human_readable_value, get_human_readable_value_scale, to_human_readable_value, Dataset, from_human_readable_value, get_human_readable_value_scale, to_human_readable_value, Dataset,

View File

@@ -1,7 +1,7 @@
use std::cmp::Ordering; use std::cmp::Ordering;
use std::ops::Index; use std::ops::Index;
use crate::common::{Circuit, CircuitValueTrait, DeviceKind, LcrConnError}; use crate::common::{Circuit, CircuitCalculator, DeviceKind, LcrConnError};
/// The priority of the result. /// The priority of the result.
#[derive(Clone, Copy, Debug, PartialEq, Eq)] #[derive(Clone, Copy, Debug, PartialEq, Eq)]
@@ -96,7 +96,7 @@ impl ResponseItem {
/// # Errors /// # Errors
/// ///
/// See [`CircuitValueTrait::value`]. /// See [`CircuitValueTrait::value`].
pub fn new(circuit: Circuit, cv_trait: &CircuitValueTrait) -> Result<Self, LcrConnError> { pub fn new(circuit: Circuit, cv_trait: &CircuitCalculator) -> Result<Self, LcrConnError> {
let value = cv_trait.value(&circuit)?; let value = cv_trait.value(&circuit)?;
let difference = cv_trait.difference(&circuit, Some(value))?; let difference = cv_trait.difference(&circuit, Some(value))?;
let unsigned_difference = cv_trait.unsigned_difference(&circuit, None, Some(difference))?; let unsigned_difference = cv_trait.unsigned_difference(&circuit, None, Some(difference))?;
@@ -183,7 +183,7 @@ impl Response {
request: &Request, request: &Request,
candidates: impl IntoIterator<Item = Circuit>, candidates: impl IntoIterator<Item = Circuit>,
) -> Result<Self, LcrConnError> { ) -> Result<Self, LcrConnError> {
let cv_trait = CircuitValueTrait::new(request.device_kind, request.target_value); let cv_trait = CircuitCalculator::new(request.device_kind, request.target_value);
let mut items: Vec<ResponseItem> = candidates let mut items: Vec<ResponseItem> = candidates
.into_iter() .into_iter()

View File

@@ -3,7 +3,7 @@ use std::collections::BinaryHeap;
use std::iter::FusedIterator; use std::iter::FusedIterator;
use super::Resolver; use super::Resolver;
use crate::common::{Circuit, CircuitValueTrait, DeviceKind, JointKind, LcrConnError}; use crate::common::{Circuit, CircuitCalculator, DeviceKind, JointKind, LcrConnError};
use crate::dataset::{Dataset, DatasetCollection, DatasetItem}; use crate::dataset::{Dataset, DatasetCollection, DatasetItem};
use crate::query::{Request, Response}; use crate::query::{Request, Response};
@@ -263,7 +263,7 @@ impl BfsItem {
/// # Errors /// # Errors
/// ///
/// See [`CircuitValueTrait::value`]. /// See [`CircuitValueTrait::value`].
pub fn new(circuit: Circuit, cv_trait: &CircuitValueTrait) -> Result<Self, LcrConnError> { pub fn new(circuit: Circuit, cv_trait: &CircuitCalculator) -> Result<Self, LcrConnError> {
let value = cv_trait.value(&circuit)?; let value = cv_trait.value(&circuit)?;
let unsigned_difference = cv_trait.unsigned_difference(&circuit, Some(value))?; let unsigned_difference = cv_trait.unsigned_difference(&circuit, Some(value))?;
Ok(Self { Ok(Self {
@@ -454,7 +454,7 @@ impl Resolver for BfsResolver {
// Iterate circuit item one by one // Iterate circuit item one by one
let mut bucket = ResultBucket::new(request.count_limit); let mut bucket = ResultBucket::new(request.count_limit);
let cv_trait = CircuitValueTrait::new(request.device_kind, request.target_value); let cv_trait = CircuitCalculator::new(request.device_kind, request.target_value);
let circuits = Self::iter_one_device_circuit(dataset) let circuits = Self::iter_one_device_circuit(dataset)
.chain(Self::iter_two_devices_circuit(dataset)) .chain(Self::iter_two_devices_circuit(dataset))

View File

@@ -2,7 +2,7 @@ use std::cmp::Ordering;
use super::bfs::BfsResolver; use super::bfs::BfsResolver;
use super::Resolver; use super::Resolver;
use crate::common::{Circuit, CircuitValueTrait, DeviceKind, LcrConnError}; use crate::common::{Circuit, CircuitCalculator, DeviceKind, LcrConnError};
use crate::dataset::{Dataset, DatasetCollection}; use crate::dataset::{Dataset, DatasetCollection};
use crate::query::{Request, Response}; use crate::query::{Request, Response};
@@ -104,7 +104,7 @@ impl Resolver for LutResolver {
let mut right = idx as isize; let mut right = idx as isize;
let lut_len = lut.len() as isize; let lut_len = lut.len() as isize;
let cv_trait = CircuitValueTrait::new(request.device_kind, target); let cv_trait = CircuitCalculator::new(request.device_kind, target);
while left >= 0 || right < lut_len { while left >= 0 || right < lut_len {
if bucket.len() >= count_limit { if bucket.len() >= count_limit {