small_db/btree/page/page.rs
1use super::BTreePageID;
2use crate::btree::tuple::Schema;
3
4pub trait BTreePage {
5 fn new(
6 pid: &BTreePageID,
7 bytes: &[u8],
8 tuple_scheme: &Schema,
9 key_field: usize,
10 ) -> Self
11 where
12 Self: Sized;
13
14 fn get_pid(&self) -> BTreePageID;
15
16 fn get_parent_pid(&self) -> BTreePageID;
17 fn set_parent_pid(&mut self, pid: &BTreePageID);
18
19 /// Generates a byte array representing the contents of this page.
20 /// Used to serialize this page to disk.
21 ///
22 /// The invariant here is that it should be possible to pass the
23 /// byte array generated by get_page_data to the BTreePage
24 /// constructor and have it produce an identical BTreeLeafPage
25 /// object.
26 ///
27 /// # Returns
28 /// A byte array representing the contents of this page.
29 fn get_page_data(&self) -> Vec<u8>;
30
31 fn set_before_image(&mut self);
32
33 /// Provide a representation of this page before any modifications
34 /// were made to it. Used by recovery.
35 fn get_before_image(&self) -> Vec<u8>;
36
37 fn peek(&self);
38}