From 503aff9997e068f07ab6973f56e57282a5ba27a0 Mon Sep 17 00:00:00 2001 From: Avril Date: Wed, 23 Dec 2020 17:35:03 +0000 Subject: [PATCH] clean template --- Cargo.lock | 1 + Cargo.toml | 1 + src/data/clean.rs | 50 +++++++++++++++++++++++++++++++++++++++++++++++ src/data/mod.rs | 3 +++ src/ext/mod.rs | 33 +++++++++++++++++++++++++++++++ src/main.rs | 3 ++- 6 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 src/data/clean.rs diff --git a/Cargo.lock b/Cargo.lock index 33897df..b7457b8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -468,6 +468,7 @@ name = "mtfse" version = "0.1.0" dependencies = [ "ad-hoc-iter", + "bitflags", "bytes 0.6.0", "cryptohelpers", "futures", diff --git a/Cargo.toml b/Cargo.toml index 32b639f..c1cb35c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,7 @@ edition = "2018" [dependencies] ad-hoc-iter = "0.2.2" +bitflags = "1.2.1" bytes = "0.6.0" cryptohelpers = {version = "1.7", features = ["full", "async", "serde"]} futures = "0.3.8" diff --git a/src/data/clean.rs b/src/data/clean.rs new file mode 100644 index 0000000..4f2f576 --- /dev/null +++ b/src/data/clean.rs @@ -0,0 +1,50 @@ +use super::*; + +bitflags!{ + /// What to remove when using `Store::clean()`. + pub struct StoreCleanFlags: u32 + { + /// Dead entry hash (key) mappings. + const MAP = 1 << 0; + /// Dead `tag -> entry hash` mappings. + const TAG_MAP = 1 << 1; + /// Dead tags (i.e. tags with no entries). + const TAGS = 1 << 2; + /// Dead entries (i.e. Inaccessable, corrupt, or missing file entries). + const ENTRY = 1 << 3; + + /// Clean all + const ALL = (1 << 4)-1; + + } +} +impl Default for StoreCleanFlags +{ + #[inline] + fn default() -> Self + { + Self::MAP | Self::TAG_MAP | Self::TAGS + } +} + + +// Refresh and cleaning +impl Store +{ + /// Remove any and all dead mappings / entries specified by the flags here. + /// + /// Pass `Default::default()` to only clean *mappings*, and not dead entries. Otherwise, `StoreCleanFlags::ALL` will perform a full audit. + /// See [`StoreCleanFlags`] for other options. + pub fn clean(&mut self, what: StoreCleanFlags) + { + todo!("What order do we do `what`'s things in?") + } + /// Force a full rebuild of all mappings. + /// + /// The clears the entire store except entries (and entry specific caches), and then rebuilds all the internal mappings from scratch. Any cached mappings (e.g empty tag reserves) are removed. + /// This does not remove invalid entries themselves, for that use `clean(StoreCleanFlags::ENTRY)`. + pub fn rebuild(&mut self) + { + todo!() + } +} diff --git a/src/data/mod.rs b/src/data/mod.rs index 499ff7a..792034c 100644 --- a/src/data/mod.rs +++ b/src/data/mod.rs @@ -35,6 +35,9 @@ pub use search::*; mod mutation; pub use mutation::*; +mod clean; +pub use clean::*; + #[cfg(test)] mod test; /// The key used to look up a single entry in `O(1)` time. diff --git a/src/ext/mod.rs b/src/ext/mod.rs index 2e6f000..c64fc33 100644 --- a/src/ext/mod.rs +++ b/src/ext/mod.rs @@ -41,3 +41,36 @@ pub const PRECOLLECT_STACK_SIZE: usize = 64; } }; } + +#[derive(Debug, Clone, PartialEq, Eq, Hash, Copy)] +pub enum Either +{ + T(T), + U(U), +} + +impl Either +{ + /// Convert this sum type into + pub fn cast(self) -> V + where V: From + From// eh, this doesn't work. forget about it. + { + match self { + Self::T(t) => t.into(), + Self::U(u) => u.into(), + } + } +} + +/// Create an ad-hoc sum type. +macro_rules! either { + (@ type $first:ty) => { + $first + }; + (@ type $first:ty, $($rest:ty),*) => { + Either<$first, either!(@ type $($rest),*)> + }; + (type $($type:ty)|*) => { + either!(@ type $($type),*) + }; +} diff --git a/src/main.rs b/src/main.rs index 66300b8..aeeb9aa 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,6 +3,7 @@ #![allow(dead_code)] #[macro_use] extern crate ad_hoc_iter; +#[macro_use] extern crate bitflags; use serde::{Serialize, Deserialize}; @@ -22,7 +23,7 @@ mod ext; use ext::*; mod slice; -mod data; +pub mod data; fn main() { println!("Hello, world!");