@@ -44,7 +44,7 @@ pub struct Level {
44
44
/// to recursively following `current`
45
45
current_chain_length : usize ,
46
46
/// The head of this level
47
- current : Option < i64 > ,
47
+ head : Option < i64 > ,
48
48
}
49
49
50
50
impl Level {
@@ -53,25 +53,25 @@ impl Level {
53
53
Level {
54
54
max_length,
55
55
current_chain_length : 0 ,
56
- current : None ,
56
+ head : None ,
57
57
}
58
58
}
59
59
60
60
/// Creates a new level from stored state
61
- pub fn restore ( max_length : usize , current_chain_length : usize , current : Option < i64 > ) -> Level {
61
+ pub fn restore ( max_length : usize , current_chain_length : usize , head : Option < i64 > ) -> Level {
62
62
Level {
63
63
max_length,
64
64
current_chain_length,
65
- current ,
65
+ head ,
66
66
}
67
67
}
68
68
69
69
/// Update the current head of this level. If delta is true then it means
70
70
/// that given state group will (probably) reference the previous head.
71
71
///
72
72
/// Panics if `delta` is true and the level is already full.
73
- fn update ( & mut self , current : i64 , delta : bool ) {
74
- self . current = Some ( current ) ;
73
+ fn update ( & mut self , new_head : i64 , delta : bool ) {
74
+ self . head = Some ( new_head ) ;
75
75
76
76
if delta {
77
77
// If we're referencing the previous head then increment our chain
@@ -87,9 +87,19 @@ impl Level {
87
87
}
88
88
}
89
89
90
+ /// Get the max length of the level
91
+ pub fn get_max_length ( & self ) -> usize {
92
+ self . max_length
93
+ }
94
+
95
+ /// Get the current length of the level
96
+ pub fn get_current_length ( & self ) -> usize {
97
+ self . current_chain_length
98
+ }
99
+
90
100
/// Get the current head of the level
91
- pub fn get_current ( & self ) -> Option < i64 > {
92
- self . current
101
+ pub fn get_head ( & self ) -> Option < i64 > {
102
+ self . head
93
103
}
94
104
95
105
/// Whether there is space in the current chain at this level. If not then a
@@ -142,12 +152,11 @@ impl<'a> Compressor<'a> {
142
152
/// in which case the levels heads are also known
143
153
pub fn compress_from_save (
144
154
original_state_map : & ' a BTreeMap < i64 , StateGroupEntry > ,
145
- // level_info: &[(usize, usize, Option<i64>)],
146
155
level_info : & [ Level ] ,
147
156
) -> Compressor < ' a > {
148
157
let levels = level_info
149
158
. iter ( )
150
- . map ( |l| Level :: restore ( ( * l) . max_length , ( * l) . current_chain_length , ( * l) . current ) )
159
+ . map ( |l| Level :: restore ( ( * l) . max_length , ( * l) . current_chain_length , ( * l) . head ) )
151
160
. collect ( ) ;
152
161
153
162
let mut compressor = Compressor {
@@ -200,7 +209,7 @@ impl<'a> Compressor<'a> {
200
209
let mut prev_state_group = None ;
201
210
for level in & mut self . levels {
202
211
if level. has_space ( ) {
203
- prev_state_group = level. get_current ( ) ;
212
+ prev_state_group = level. get_head ( ) ;
204
213
level. update ( state_group, true ) ;
205
214
break ;
206
215
} else {
0 commit comments