Skip to content

Commit a8a75f2

Browse files
Merge pull request #101 from JakeRoggenbuck/buffer-pool
Add bufferpool
2 parents 20bc41e + 4ecd81d commit a8a75f2

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

src/bufferpool.rs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
use std::sync::{Arc, Mutex};
2+
3+
struct BufferPool {
4+
// The physical directory on disk that data will be written to
5+
pub physical_directory: Arc<Mutex<String>>,
6+
}
7+
8+
impl BufferPool {
9+
fn new(directory: &str) -> Self {
10+
BufferPool {
11+
physical_directory: Arc::new(Mutex::new(directory.to_string())),
12+
}
13+
}
14+
15+
fn write_page(page_id: usize) {
16+
todo!();
17+
}
18+
19+
fn read_page(page_id: usize) {
20+
// TODO: How does it know the page id?
21+
todo!();
22+
}
23+
24+
fn save_state(&self) {}
25+
26+
fn load_state(&self, directory: &str) -> BufferPool {
27+
BufferPool {
28+
physical_directory: Arc::new(Mutex::new(directory.to_string())),
29+
}
30+
}
31+
}
32+
33+
#[cfg(test)]
34+
mod tests {
35+
use super::*;
36+
37+
#[test]
38+
fn load_and_save_test() {
39+
let b = BufferPool::new("/data");
40+
41+
b.save_state();
42+
43+
let new_b = b.load_state("/data");
44+
45+
assert_eq!(
46+
b.physical_directory.lock().unwrap().to_string(),
47+
new_b.physical_directory.lock().unwrap().to_string()
48+
);
49+
}
50+
51+
#[test]
52+
fn bufferpool_test() {
53+
assert!(true);
54+
}
55+
}

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use query::RQuery;
44
use record::Record;
55
use table::RTable;
66

7+
pub mod bufferpool;
78
pub mod container;
89
pub mod database;
910
pub mod index;

0 commit comments

Comments
 (0)