triblespace_core/query/
constantconstraint.rs1use super::*;
2
3pub struct ConstantConstraint {
10 variable: VariableId,
11 constant: RawValue,
12}
13
14impl ConstantConstraint {
15 pub fn new<T: ValueSchema>(variable: Variable<T>, constant: Value<T>) -> Self {
17 ConstantConstraint {
18 variable: variable.index,
19 constant: constant.raw,
20 }
21 }
22}
23
24impl<'a> Constraint<'a> for ConstantConstraint {
25 fn variables(&self) -> VariableSet {
26 VariableSet::new_singleton(self.variable)
27 }
28
29 fn estimate(&self, variable: VariableId, _binding: &Binding) -> Option<usize> {
31 if self.variable == variable {
32 Some(1)
33 } else {
34 None
35 }
36 }
37
38 fn propose(&self, variable: VariableId, _binding: &Binding, proposals: &mut Vec<RawValue>) {
40 if self.variable == variable {
41 proposals.push(self.constant);
42 }
43 }
44
45 fn confirm(&self, variable: VariableId, _binding: &Binding, proposals: &mut Vec<RawValue>) {
47 if self.variable == variable {
48 proposals.retain(|v| *v == self.constant);
49 }
50 }
51
52 fn satisfied(&self, binding: &Binding) -> bool {
54 match binding.get(self.variable) {
55 Some(v) => *v == self.constant,
56 None => true,
57 }
58 }
59}