File tree Expand file tree Collapse file tree 2 files changed +56
-0
lines changed
Expand file tree Collapse file tree 2 files changed +56
-0
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ use query::RQuery;
44use record:: Record ;
55use table:: RTable ;
66
7+ pub mod bufferpool;
78pub mod container;
89pub mod database;
910pub mod index;
You can’t perform that action at this time.
0 commit comments