1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
use std::fmt::Debug;

use crate::Predicate;

#[derive(Copy, Clone, PartialEq, Debug)]
pub enum Type {
    INT,
}

pub fn get_type_length(t: Type) -> usize {
    match t {
        Type::INT => 4,
    }
}

#[derive(PartialEq, Debug, Clone)]
pub struct FieldItem {
    pub field_type: Type,
    pub field_name: String,
}

#[derive(Copy, Clone, PartialEq, Eq, Ord, Debug, PartialOrd)]
pub struct IntField {
    pub value: i32,
}

impl IntField {
    pub fn new(v: i32) -> IntField {
        IntField { value: v }
    }

    pub fn len(&self) -> usize {
        4
    }

    pub fn satisfy(&self, predicate: &Predicate) -> bool {
        match predicate.op {
            crate::Op::Equals => self.value == predicate.field.value,
            crate::Op::GreaterThan => self.value > predicate.field.value,
            crate::Op::LessThan => self.value < predicate.field.value,
            crate::Op::LessThanOrEq => self.value <= predicate.field.value,
            crate::Op::GreaterThanOrEq => self.value >= predicate.field.value,
            crate::Op::Like => todo!(),
            crate::Op::NotEquals => self.value != predicate.field.value,
        }
    }
}