tablestg 0.4.5

Storage for database tables
Documentation
//! Everything is very preliminary, this crate is not yet at all stable.

pub use atom_file::Data;
use std::hash::Hash;
use std::sync::Arc;

/// Value for Hash Map lookup.
pub trait SmallFixed {
    fn size() -> usize;
    fn load(bytes: &[u8]) -> Self;
    fn save(&self, bytes: &mut [u8]);
}

/// Key for Hash Map lookup.
pub trait Key<T>: Hash
where
    T: SmallFixed,
{
    /// Check that hash lookup has found correct value.
    fn ok(&self, addr: T, ps: &mut PageSet) -> Option<(T, Value)>;
}

/// [PageSet] - keeps track of changed pages that need saving.
pub mod pageset;
pub use pageset::*;

/// [HashMap] - maps keys to values using 64 bit hash.
pub mod hashmap;
pub use hashmap::*;

/// [Table] -- fixed size record storage. Divided into pages, each page stores up to 128 records.
pub mod table;
pub use table::*;

/// [VarValAddr] -- storage of variable length values.
pub mod varval;
pub use varval::*;

/// ToDo
pub mod sys;
pub use sys::*;

/// [DataType] -- describes data type
pub mod datatype;
pub use datatype::*;

/// [Value] -- generic instance of a data type
pub mod value;
pub use value::*;

// Private modules.

/// [PageTree] - list of pages implemented as tree.
mod pagetree;
use pagetree::*;

/// [TreeVec] -- a variable length list of bytes. Used to implement [Table].
mod treevec;
use treevec::*;

/// Hash Map Bucket - maps keys to values using 64 bit hash.
mod bucket;

const PAGE_SIZE: u64 = 3952;
// pub const PAGE_SIZE: u64 =  3952;
// pub const PAGE_SIZE: u64 =  4612;

use pstd::localalloc::Local;
/// `StringA<Local>`
pub type LString = pstd::StringA<Local>;
/// `VecA<T, Local>`
pub type LVec<T> = pstd::VecA<T, Local>;
/// `BoxA<T, Local>`
pub type LBox<T> = pstd::BoxA<T, Local>;

mod test;

#[cfg(test)]
fn tos(s: &[u8]) -> &str {
    str::from_utf8(s).unwrap()
}

/*
   Could have multiple VarVarStores (each is a simple TreeVec).
   When free space becomes significant (say 20%, or after a long time), garbage collect the store.
   When the Store has been emptied, free all pages and add it to free slot list.
   Note: large records (>16kb) are stored as TreeVec not in a VarValStore.
   Stores should be limited to some reasonable size, say 4MB.
   Index into store is then 22 bits. Index into Store TreeVec can be 32 bits.
   This means garbage collecting a store is reasonably cheap.

   To Access a Store, we first get the Meta info using a TreeVec.
   Meta Data for store: 
      Total Free Bytes, TreeVec root and length, Next free Slot.

   Global Info: TreeVec ( root + length ).
   Header : First Free Slot, Number of Slots, Current Store (index).

   Table module is no longer used.
*/