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
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// These impls for PartialEq, Eq, etc are written by hand. This is
// because the `#[derive()]` would add requirements onto the context
// object that are not needed.

use std::cmp::{Ordering, PartialEq, Eq, PartialOrd, Ord};
use std::hash::{Hash, Hasher};
use std::mem;
use super::*;

impl<C: Context> PartialEq for DelayedLiteralSet<C> {
    fn eq(&self, other: &Self) -> bool {
        let DelayedLiteralSet { delayed_literals: a1 } = self;
        let DelayedLiteralSet { delayed_literals: a2 } = other;
        a1 == a2
    }
}

impl<C: Context> Eq for DelayedLiteralSet<C> {
}

impl<C: Context> PartialOrd for DelayedLiteralSet<C> {
    fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
        Some(self.cmp(other))
    }
}

impl<C: Context> Ord for DelayedLiteralSet<C> {
    fn cmp(&self, other: &Self) -> Ordering {
        let DelayedLiteralSet { delayed_literals: a1 } = self;
        let DelayedLiteralSet { delayed_literals: a2 } = other;
        a1.cmp(a2)
    }
}

impl<C: Context> Hash for DelayedLiteralSet<C> {
    fn hash<H: Hasher>(&self, hasher: &mut H) {
        let DelayedLiteralSet { delayed_literals } = self;
        delayed_literals.hash(hasher);
    }
}

///////////////////////////////////////////////////////////////////////////

impl<C: Context> PartialEq for DelayedLiteral<C> {
    fn eq(&self, other: &Self) -> bool {
        if mem::discriminant(self) != mem::discriminant(other) {
            return false;
        }

        match (self, other) {
            (DelayedLiteral::CannotProve(()), DelayedLiteral::CannotProve(())) =>
                true,

            (DelayedLiteral::Negative(a1), DelayedLiteral::Negative(a2)) =>
                a1 == a2,

            (DelayedLiteral::Positive(a1, b1), DelayedLiteral::Positive(a2, b2)) =>
                a1 == a2 && b1 == b2,

            _ => panic!()
        }
    }
}

impl<C: Context> Eq for DelayedLiteral<C> {
}

impl<C: Context> PartialOrd for DelayedLiteral<C> {
    fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
        Some(self.cmp(other))
    }
}

impl<C: Context> Ord for DelayedLiteral<C> {
    fn cmp(&self, other: &Self) -> Ordering {
        match (self, other) {
            (DelayedLiteral::CannotProve(()), DelayedLiteral::CannotProve(())) =>
                Ordering::Equal,

            (DelayedLiteral::CannotProve(()), _) =>
                Ordering::Greater,

            (_, DelayedLiteral::CannotProve(())) =>
                Ordering::Less,

            (DelayedLiteral::Negative(a1), DelayedLiteral::Negative(a2)) =>
                a1.cmp(a2),

            (DelayedLiteral::Negative(..), _) =>
                Ordering::Greater,

            (_, DelayedLiteral::Negative(..)) =>
                Ordering::Less,

            (DelayedLiteral::Positive(a1, b1), DelayedLiteral::Positive(a2, b2)) =>
                a1.cmp(a2).then_with(|| b1.cmp(b2)),
        }
    }
}

impl<C: Context> Hash for DelayedLiteral<C> {
    fn hash<H: Hasher>(&self, hasher: &mut H) {
        mem::discriminant(self).hash(hasher);

        match self {
            DelayedLiteral::CannotProve(()) => (),

            DelayedLiteral::Negative(a) => {
                a.hash(hasher);
            }

            DelayedLiteral::Positive(a, b) => {
                a.hash(hasher);
                b.hash(hasher);
            }
        }
    }
}

///////////////////////////////////////////////////////////////////////////

impl<C: Context> PartialEq for Literal<C> {
    fn eq(&self, other: &Literal<C>) -> bool {
        match (self, other) {
            (Literal::Positive(goal1), Literal::Positive(goal2))
            | (Literal::Negative(goal1), Literal::Negative(goal2)) => goal1 == goal2,

            _ => false,
        }
    }
}

impl<C: Context> Eq for Literal<C> {
}

impl<C: Context> Hash for Literal<C> {
    fn hash<H: Hasher>(&self, state: &mut H) {
        mem::discriminant(self).hash(state);
        match self {
            Literal::Positive(goal) | Literal::Negative(goal) => {
                goal.hash(state);
            }
        }
    }
}