-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3a84607
commit c8ee90b
Showing
1 changed file
with
42 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,9 +6,10 @@ | |
//! #### Authorship | ||
//! | ||
//! - Max Fierro, 2/24/2024 ([email protected]) | ||
//! - Implementation: Casey Stanford, 4/10/2024 ([email protected]) | ||
use anyhow::Result; | ||
use bitvec::{order::Msb0, slice::BitSlice, store::BitStore}; | ||
use bitvec::{prelude::*, order::Msb0, slice::BitSlice, store::BitStore}; | ||
|
||
use std::collections::HashMap; | ||
|
||
|
@@ -21,10 +22,10 @@ use crate::{ | |
//TODO: efficient version: have a huge Vec chunk of memory, and HashMap just stores indexes in that memory chunk | ||
|
||
pub struct Database { | ||
memory: HashMap<State, Vec<Record>>, | ||
memory: HashMap<State, BitVec<u8, Msb0>>, | ||
} | ||
|
||
impl Database<'_> { | ||
impl Database { | ||
pub fn initialize() -> Self { | ||
Self { | ||
memory: HashMap::new(), | ||
|
@@ -33,9 +34,9 @@ impl Database<'_> { | |
} | ||
|
||
|
||
impl<R:Record> KVStore<R> for Database<'_> { | ||
impl<R:Record> KVStore<R> for Database { | ||
fn put(&mut self, key: State, value: &R) { | ||
let new = Vec::from(value).clone(); | ||
let new = BitVec::from(value.raw()).clone(); | ||
self.memory.insert(key, new); | ||
} | ||
|
||
|
@@ -54,7 +55,7 @@ impl<R:Record> KVStore<R> for Database<'_> { | |
|
||
|
||
|
||
impl Tabular for Database<'_> { | ||
impl Tabular for Database { | ||
fn create_table(&self, id: &str, schema: Schema) -> Result<()> { | ||
todo!() | ||
} | ||
|
@@ -67,3 +68,38 @@ impl Tabular for Database<'_> { | |
todo!() | ||
} | ||
} | ||
|
||
|
||
|
||
#[cfg(test)] | ||
mod tests { | ||
|
||
use super::*; | ||
|
||
pub struct Rec { | ||
value: BitVec<u8, Msb0>, | ||
} | ||
|
||
impl Rec { | ||
pub fn initialize(val: BitVec<u8, Msb0>) -> Self { | ||
Self { | ||
value: val.clone(), | ||
} | ||
} | ||
} | ||
|
||
impl Record for Rec { | ||
fn raw(&self) -> &BitSlice<u8, Msb0> { | ||
return &self.value[..]; | ||
} | ||
} | ||
|
||
#[test] | ||
fn put_data_and_get_it() { | ||
let mut db: Database = Database::initialize(); | ||
let test_state: State = 7; | ||
//assert!(db.get(test_state).is_none()); | ||
let test_rec: Rec = Rec::initialize(BitVec::<u8, Msb0>::new()); | ||
db.put(test_state, &test_rec); | ||
} | ||
} |