Skip to content

Commit a409cdb

Browse files
authored
Rename level current to head (#61)
1 parent 8c72a0d commit a409cdb

File tree

4 files changed

+29
-23
lines changed

4 files changed

+29
-23
lines changed

src/compressor.rs

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub struct Level {
4444
/// to recursively following `current`
4545
current_chain_length: usize,
4646
/// The head of this level
47-
current: Option<i64>,
47+
head: Option<i64>,
4848
}
4949

5050
impl Level {
@@ -53,25 +53,25 @@ impl Level {
5353
Level {
5454
max_length,
5555
current_chain_length: 0,
56-
current: None,
56+
head: None,
5757
}
5858
}
5959

6060
/// 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 {
6262
Level {
6363
max_length,
6464
current_chain_length,
65-
current,
65+
head,
6666
}
6767
}
6868

6969
/// Update the current head of this level. If delta is true then it means
7070
/// that given state group will (probably) reference the previous head.
7171
///
7272
/// 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);
7575

7676
if delta {
7777
// If we're referencing the previous head then increment our chain
@@ -87,9 +87,19 @@ impl Level {
8787
}
8888
}
8989

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+
90100
/// 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
93103
}
94104

95105
/// Whether there is space in the current chain at this level. If not then a
@@ -142,12 +152,11 @@ impl<'a> Compressor<'a> {
142152
/// in which case the levels heads are also known
143153
pub fn compress_from_save(
144154
original_state_map: &'a BTreeMap<i64, StateGroupEntry>,
145-
// level_info: &[(usize, usize, Option<i64>)],
146155
level_info: &[Level],
147156
) -> Compressor<'a> {
148157
let levels = level_info
149158
.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))
151160
.collect();
152161

153162
let mut compressor = Compressor {
@@ -200,7 +209,7 @@ impl<'a> Compressor<'a> {
200209
let mut prev_state_group = None;
201210
for level in &mut self.levels {
202211
if level.has_space() {
203-
prev_state_group = level.get_current();
212+
prev_state_group = level.get_head();
204213
level.update(state_group, true);
205214
break;
206215
} else {

src/compressor/compressor_tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -677,11 +677,11 @@ fn get_delta_returns_snapshot_if_no_prev_possible() {
677677
let mut levels_iter = compressor.levels.iter_mut();
678678

679679
let l1 = levels_iter.next().unwrap();
680-
l1.current = Some(3);
680+
l1.head = Some(3);
681681
l1.current_chain_length = 1;
682682

683683
let l2 = levels_iter.next().unwrap();
684-
l2.current = Some(3);
684+
l2.head = Some(3);
685685
l2.current_chain_length = 1;
686686

687687
// Now try and find delta for 4 with 3 as pred

src/compressor/level_tests.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ fn new_produces_empty_level() {
55
let l = Level::new(15);
66
assert_eq!(l.max_length, 15);
77
assert_eq!(l.current_chain_length, 0);
8-
assert_eq!(l.current, None);
8+
assert_eq!(l.head, None);
99
}
1010

1111
#[test]
@@ -14,7 +14,7 @@ fn update_adds_to_non_full_level() {
1414
l.update(7, true);
1515
assert_eq!(l.max_length, 10);
1616
assert_eq!(l.current_chain_length, 1);
17-
assert_eq!(l.current, Some(7));
17+
assert_eq!(l.head, Some(7));
1818
}
1919

2020
#[test]
@@ -40,15 +40,15 @@ fn update_resets_level_correctly() {
4040
l.update(6, false);
4141
assert_eq!(l.max_length, 5);
4242
assert_eq!(l.current_chain_length, 1);
43-
assert_eq!(l.current, Some(6));
43+
assert_eq!(l.head, Some(6));
4444
}
4545

4646
#[test]
47-
fn get_current_returns_current() {
47+
fn get_head_returns_head() {
4848
let mut l = Level::new(5);
49-
assert_eq!(l.get_current(), None);
49+
assert_eq!(l.get_head(), None);
5050
l.update(23, true);
51-
assert_eq!(l.get_current(), Some(23));
51+
assert_eq!(l.get_head(), Some(23));
5252
}
5353

5454
#[test]

src/database.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,7 @@ pub fn reload_data_from_db(
126126
/// * `levels' - The levels who's heads are being requested
127127
fn load_level_heads(client: &mut Client, level_info: &[Level]) -> BTreeMap<i64, StateGroupEntry> {
128128
// obtain all of the heads that aren't None from level_info
129-
let level_heads: Vec<i64> = level_info
130-
.iter()
131-
.filter_map(|l| (*l).get_current())
132-
.collect();
129+
let level_heads: Vec<i64> = level_info.iter().filter_map(|l| (*l).get_head()).collect();
133130

134131
// Query to get id, predecessor and deltas for each state group
135132
let sql = r#"

0 commit comments

Comments
 (0)