Skip to content

Commit

Permalink
volatileDB compiles
Browse files Browse the repository at this point in the history
  • Loading branch information
cqstanford committed Apr 10, 2024
1 parent 3a84607 commit c8ee90b
Showing 1 changed file with 42 additions and 6 deletions.
48 changes: 42 additions & 6 deletions src/database/volatile/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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(),
Expand All @@ -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);
}

Expand All @@ -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!()
}
Expand All @@ -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);
}
}

0 comments on commit c8ee90b

Please sign in to comment.