use super::*;
pub struct ConstantConstraint {
variable: VariableId,
constant: RawInline,
}
impl ConstantConstraint {
pub fn new<T: InlineEncoding>(variable: Variable<T>, constant: Inline<T>) -> Self {
ConstantConstraint {
variable: variable.index,
constant: constant.raw,
}
}
}
impl<'a> Constraint<'a> for ConstantConstraint {
fn variables(&self) -> VariableSet {
VariableSet::new_singleton(self.variable)
}
fn estimate(&self, variable: VariableId, _binding: &Binding) -> Option<usize> {
if self.variable == variable {
Some(1)
} else {
None
}
}
fn propose(
&self,
variable: VariableId,
frontier: &Frontier<'_>,
proposals: &mut ProposalBuffer,
) {
if self.variable == variable {
for row in 0..frontier.len() {
proposals.open(row as u32);
proposals.push(self.constant);
}
}
}
fn confirm(&self, variable: VariableId, _frontier: &Frontier<'_>, cands: &mut Candidates<'_>) {
if self.variable == variable {
for i in 0..cands.len() {
let v = &cands.values()[i];
if cands.is_live(i) && *v != self.constant {
cands.kill(i);
}
}
}
}
fn satisfied(&self, binding: &Binding) -> bool {
match binding.get(self.variable) {
Some(v) => *v == self.constant,
None => true,
}
}
}