pub mod xcsp3_core {
use crate::data_structs::xrelational_operator::xcsp3_core::Operator;
use std::collections::HashSet;
use std::str::FromStr;
#[derive(Clone, Debug)]
pub enum Operand {
Integer(i32),
Variable(String),
Interval(i32, i32),
SetInteger(HashSet<i32>),
}
impl Operand {
pub fn get_operand_by_str(s: &[&str], op: &Operator) -> Option<Self> {
let mut is_set: bool = false;
match op {
Operator::In => is_set = true,
Operator::Notin => is_set = true,
_ => {}
}
return if is_set {
let mut ret: HashSet<i32> = HashSet::new();
for l in s.iter() {
match i32::from_str(l) {
Ok(n) => {
ret.insert(n);
}
Err(_) => {
return None;
}
}
}
Some(Operand::SetInteger(ret))
} else if s.len() != 1 {
None
} else if s[0].contains("..") {
let interval: Vec<&str> = s[0].split("..").collect();
if interval.len() == 2 {
match i32::from_str(interval[0]) {
Ok(l) => match i32::from_str(interval[1]) {
Ok(r) => {
if l <= r {
Some(Operand::Interval(l, r))
} else {
None
}
}
Err(_) => None,
},
Err(_) => None,
}
} else {
None
}
} else {
match i32::from_str(s[0]) {
Ok(n) => Some(Operand::Integer(n)),
Err(_) => Some(Operand::Variable(s[0].to_string())),
}
};
}
}
}