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
use std::cmp::Ordering;
pub type Dot = u32;
pub type Origin = u32;
#[derive(Clone, Copy, Debug)]
pub struct Item<N> {
pub(in super) origin: Origin,
pub(in super) dot: Dot,
pub node: N,
}
#[derive(Clone, Copy, Debug)]
pub struct CompletedItem<N> {
pub(in super) dot: Dot,
pub(in super) origin: Origin,
pub left_node: N,
pub right_node: Option<N>,
}
#[derive(Clone, Copy, Debug)]
pub struct CompletedItemLinked<N> {
pub idx: u32,
pub node: Option<N>,
}
impl<L> PartialEq for Item<L> {
fn eq(&self, other: &Self) -> bool {
(self.origin, self.dot) == (other.origin, other.dot)
}
}
impl<L> Eq for Item<L> {}
impl<L> PartialOrd for Item<L> {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}
impl<L> Ord for Item<L> {
fn cmp(&self, other: &Self) -> Ordering {
(self.origin, self.dot).cmp(&(other.origin, other.dot))
}
}
impl<L> PartialEq for CompletedItem<L> {
fn eq(&self, other: &Self) -> bool {
(self.origin, self.dot) == (other.origin, other.dot)
}
}
impl<L> Eq for CompletedItem<L> {}
impl<L> PartialOrd for CompletedItem<L> {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some((self.origin, self.dot).cmp(&(other.origin, other.dot)))
}
}
impl<L> Ord for CompletedItem<L> {
fn cmp(&self, other: &Self) -> Ordering {
(self.origin, self.dot).cmp(&(other.origin, other.dot))
}
}
impl<N> Into<Item<N>> for CompletedItem<N> {
fn into(self) -> Item<N> {
Item {
origin: self.origin,
dot: self.dot,
node: self.left_node,
}
}
}