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
147
148
149
150
151
extern crate alloc;
use alloc::string::String;
use alloc::vec::Vec;
use crate::metis::{DotMap, DotSet, Rhapsody};
use super::page::{BlockDot, Field, Page};
impl Page {
/// The visible block order.
#[must_use]
pub fn block_order(&self) -> Vec<BlockDot> {
self.order.state().store().order()
}
/// The surviving kind siblings for `block`, ascending by dot: one entry
/// for an uncontended block, several after concurrent kind writes (the
/// surfaced conflict, never resolved by the machine).
#[must_use]
pub fn kinds(&self, block: BlockDot) -> Vec<&'static str> {
self.fields
.state()
.store()
.get(&block)
.and_then(|fields| fields.get(&Field::Kind))
.map(|register| register.values().copied().collect())
.unwrap_or_default()
}
/// The surviving title siblings for `block`.
#[must_use]
pub fn titles(&self, block: BlockDot) -> Vec<&'static str> {
self.fields
.state()
.store()
.get(&block)
.and_then(|fields| fields.get(&Field::Title))
.map(|register| register.values().copied().collect())
.unwrap_or_default()
}
/// Whether the field layer holds any state for `block`.
#[must_use]
pub fn fields_present(&self, block: BlockDot) -> bool {
self.fields.state().store().get(&block).is_some()
}
/// `block`'s paragraph text in visible sequence order (empty when the
/// paragraph map holds nothing under the block).
#[must_use]
pub fn para_text(&self, block: BlockDot) -> String {
self.para
.state()
.store()
.get(&block)
.map(|rhapsody| {
rhapsody
.order()
.into_iter()
.filter_map(|dot| self.chars.get(&dot).copied())
.collect()
})
.unwrap_or_default()
}
/// Whether the paragraph layer holds any state for `block` (visible chars
/// or tombstoned sequence skeleton alike: the key survives while either
/// does, which is what keeps late anchors resolvable).
#[must_use]
pub fn para_present(&self, block: BlockDot) -> bool {
self.para.state().store().get(&block).is_some()
}
/// The visible char count under `block`'s paragraph.
#[must_use]
pub fn para_visible_len(&self, block: BlockDot) -> usize {
self.para
.state()
.store()
.get(&block)
.map(Rhapsody::visible_len)
.unwrap_or_default()
}
/// The sequence skeleton size under `block`'s paragraph (tombstones
/// included): the per-container walk cost, the tree-viewport quantity.
#[must_use]
pub fn para_skeleton_len(&self, block: BlockDot) -> usize {
self.para
.state()
.store()
.get(&block)
.map(Rhapsody::skeleton_len)
.unwrap_or_default()
}
/// Whether the table layer holds any state for `block`.
#[must_use]
pub fn table_present(&self, block: BlockDot) -> bool {
self.table.state().store().get(&block).is_some()
}
/// The live row count under `block`'s table.
#[must_use]
pub fn table_rows(&self, block: BlockDot) -> usize {
self.table
.state()
.store()
.get(&block)
.map(DotMap::len)
.unwrap_or_default()
}
/// The surviving cell values at `(block, row)`, ascending by dot.
#[must_use]
pub fn cell(&self, block: BlockDot, row: u32) -> Vec<&'static str> {
self.table
.state()
.store()
.get(&block)
.and_then(|rows| rows.get(&row))
.map(|register| register.values().copied().collect())
.unwrap_or_default()
}
/// The order pair's context (everything this replica's order layer has
/// seen).
#[must_use]
pub fn order_context(&self) -> &DotSet {
self.order.state().context()
}
/// The field pair's context.
#[must_use]
pub fn fields_context(&self) -> &DotSet {
self.fields.state().context()
}
/// The paragraph pair's context.
#[must_use]
pub fn para_context(&self) -> &DotSet {
self.para.state().context()
}
/// The table pair's context.
#[must_use]
pub fn table_context(&self) -> &DotSet {
self.table.state().context()
}
}