Skip to main content

triblespace_core/query/
constantconstraint.rs

1use super::*;
2
3pub struct ConstantConstraint {
4    variable: VariableId,
5    constant: RawValue,
6}
7
8impl ConstantConstraint {
9    pub fn new<T: ValueSchema>(variable: Variable<T>, constant: Value<T>) -> Self {
10        ConstantConstraint {
11            variable: variable.index,
12            constant: constant.raw,
13        }
14    }
15}
16
17impl<'a> Constraint<'a> for ConstantConstraint {
18    fn variables(&self) -> VariableSet {
19        VariableSet::new_singleton(self.variable)
20    }
21
22    fn estimate(&self, variable: VariableId, _binding: &Binding) -> Option<usize> {
23        if self.variable == variable {
24            Some(1)
25        } else {
26            None
27        }
28    }
29
30    fn propose(&self, variable: VariableId, _binding: &Binding, proposals: &mut Vec<RawValue>) {
31        if self.variable == variable {
32            proposals.push(self.constant);
33        }
34    }
35
36    fn confirm(&self, variable: VariableId, _binding: &Binding, proposals: &mut Vec<RawValue>) {
37        if self.variable == variable {
38            proposals.retain(|v| *v == self.constant);
39        }
40    }
41}