clean template

master
Avril 4 years ago
parent e2eee6beb1
commit 503aff9997
Signed by: flanchan
GPG Key ID: 284488987C31F630

1
Cargo.lock generated

@ -468,6 +468,7 @@ name = "mtfse"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"ad-hoc-iter", "ad-hoc-iter",
"bitflags",
"bytes 0.6.0", "bytes 0.6.0",
"cryptohelpers", "cryptohelpers",
"futures", "futures",

@ -9,6 +9,7 @@ edition = "2018"
[dependencies] [dependencies]
ad-hoc-iter = "0.2.2" ad-hoc-iter = "0.2.2"
bitflags = "1.2.1"
bytes = "0.6.0" bytes = "0.6.0"
cryptohelpers = {version = "1.7", features = ["full", "async", "serde"]} cryptohelpers = {version = "1.7", features = ["full", "async", "serde"]}
futures = "0.3.8" futures = "0.3.8"

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

@ -35,6 +35,9 @@ pub use search::*;
mod mutation; mod mutation;
pub use mutation::*; pub use mutation::*;
mod clean;
pub use clean::*;
#[cfg(test)] mod test; #[cfg(test)] mod test;
/// The key used to look up a single entry in `O(1)` time. /// The key used to look up a single entry in `O(1)` time.

@ -41,3 +41,36 @@ pub const PRECOLLECT_STACK_SIZE: usize = 64;
} }
}; };
} }
#[derive(Debug, Clone, PartialEq, Eq, Hash, Copy)]
pub enum Either<T,U>
{
T(T),
U(U),
}
impl<T,U> Either<T,U>
{
/// Convert this sum type into
pub fn cast<V>(self) -> V
where V: From<T> + From<U>// 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),*)
};
}

@ -3,6 +3,7 @@
#![allow(dead_code)] #![allow(dead_code)]
#[macro_use] extern crate ad_hoc_iter; #[macro_use] extern crate ad_hoc_iter;
#[macro_use] extern crate bitflags;
use serde::{Serialize, Deserialize}; use serde::{Serialize, Deserialize};
@ -22,7 +23,7 @@ mod ext;
use ext::*; use ext::*;
mod slice; mod slice;
mod data; pub mod data;
fn main() { fn main() {
println!("Hello, world!"); println!("Hello, world!");

Loading…
Cancel
Save