Skip to content

Commit

Permalink
initial work on GOMap; doc.
Browse files Browse the repository at this point in the history
  • Loading branch information
beling committed Sep 26, 2024
1 parent 460a69e commit 68d2a9a
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 1 deletion.
3 changes: 2 additions & 1 deletion csf/src/fp/collision_solver.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use bitm::{BitAccess, BitVec, n_lowest_bits};

/// Solves value collisions during construction of fingerprinting based maps.
/// Remembers which indices are under collision and decides which collisions are positive and which are negative ones.
pub trait CollisionSolver {
/// Returns true if `index` is under collision and should not be farther processed.
fn is_under_collision(&self, index: usize) -> bool;
Expand Down Expand Up @@ -30,7 +31,7 @@ pub trait CollisionSolverBuilder {
/// The solver supports indices in range [0, 64*`level_size_segments`) and values of the size of `bits_per_fragment` bits.
fn new(&self, level_size_segments: usize, bits_per_fragment: u8) -> Self::CollisionSolver;

/// Gets whether the `new` method, with the current parameters, returns the collision solver that is lossless.
/// Gets whether the `new` method returns the collision solver that is lossless.
fn is_lossless(&self) -> bool;
}

Expand Down
101 changes: 101 additions & 0 deletions csf/src/fp/gomap/conf.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
use crate::fp::collision_solver::{CollisionSolverBuilder, LoMemAcceptEquals};
use crate::fp::OptimalLevelSize;
use ph::BuildDefaultSeededHasher;
use ph::fmph::{GOConf, GroupSize, SeedSize, TwoToPowerBitsStatic};

/// Configuration accepted by [`fp::GOMap`](crate::fp::GOMap) constructors.
#[derive(Clone)]
pub struct GOMapConf<
LSC = OptimalLevelSize,
CSB: CollisionSolverBuilder = LoMemAcceptEquals,
GS: GroupSize = TwoToPowerBitsStatic::<4>,
SS: SeedSize = TwoToPowerBitsStatic<2>,
S = BuildDefaultSeededHasher
> {
/// Bits per each value, 0 for autodetect.
pub bits_per_value: u8,
/// Configuration of family of (group-optimized) hash functions (default: [`GOConf::default`]).
pub goconf: GOConf<GS, SS, S>,
/// Choose the size of each level.
pub level_size_chooser: LSC,
/// Constructs collision solver that decides which collisions are positive, and which are negative.
pub collision_solver: CSB,
}

impl Default for GOMapConf {
fn default() -> Self { Self {
bits_per_value: Default::default(),
goconf: Default::default(),
level_size_chooser: Default::default(),
collision_solver: Default::default(),
} }
}

impl GOMapConf {
pub fn bpv(bits_per_value: u8) -> Self {
Self { bits_per_value, ..Default::default() }
}
}

impl<CSB: CollisionSolverBuilder> GOMapConf<OptimalLevelSize, CSB, TwoToPowerBitsStatic::<4>, TwoToPowerBitsStatic<2>, BuildDefaultSeededHasher> {
#[inline] pub fn cs(collision_solver: CSB) -> Self {
Self::cs_bpv(collision_solver, Default::default())
}

pub fn cs_bpv(collision_solver: CSB, bits_per_value: u8) -> Self {
Self {
bits_per_value,
goconf: Default::default(),
level_size_chooser: Default::default(),
collision_solver,
}
}
}

impl<GS: GroupSize, SS: SeedSize, S> GOMapConf<OptimalLevelSize, LoMemAcceptEquals, GS, SS, S> {
#[inline] pub fn groups(goconf: GOConf<GS, SS, S>) -> Self {
Self::groups_bpv(goconf, Default::default())
}

pub fn groups_bpv(goconf: GOConf<GS, SS, S>, bits_per_value: u8) -> Self {
Self {
bits_per_value,
goconf,
level_size_chooser: Default::default(),
collision_solver: Default::default(),
}
}
}

impl<GS: GroupSize, SS: SeedSize, S> From<GOConf<GS, SS, S>> for GOMapConf<OptimalLevelSize, LoMemAcceptEquals, GS, SS, S> {
#[inline] fn from(value: GOConf<GS, SS, S>) -> Self {
Self::groups(value)
}
}

impl<LSC> GOMapConf<LSC, LoMemAcceptEquals, TwoToPowerBitsStatic::<4>, TwoToPowerBitsStatic<2>, BuildDefaultSeededHasher> {
pub fn lsize(level_size_chooser: LSC) -> Self {
Self::lsize_bpv(level_size_chooser, Default::default())
}

pub fn lsize_bpv(level_size_chooser: LSC, bits_per_value: u8) -> Self {
Self {
bits_per_value,
goconf: Default::default(),
level_size_chooser,
collision_solver: Default::default(),
}
}
}

impl<LSC, GS: GroupSize, SS: SeedSize, S> GOMapConf<LSC, LoMemAcceptEquals, GS, SS, S> {
pub fn groups_lsize_bpv(goconf: GOConf<GS, SS, S>, level_size_chooser: LSC, bits_per_value: u8) -> Self {
Self { bits_per_value, goconf, level_size_chooser, collision_solver: Default::default() }
}
}

impl<LSC, CSB: CollisionSolverBuilder, GS: GroupSize, SS: SeedSize, S> GOMapConf<LSC, CSB, GS, SS, S> {
pub fn groups_lsize_cs_bpv(goconf: GOConf<GS, SS, S>, level_size_chooser: LSC, collision_solver: CSB, bits_per_value: u8) -> Self {
Self { bits_per_value, goconf, level_size_chooser, collision_solver }
}
}
4 changes: 4 additions & 0 deletions csf/src/fp/gomap/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
mod conf;
pub use conf::GOMapConf;

pub struct GOMap {}
3 changes: 3 additions & 0 deletions csf/src/fp/map/conf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ pub struct MapConf<
S: BuildSeededHasher = BuildDefaultSeededHasher
/*, BS: stats::BuildStatsCollector = ()*/
> {
/// Bits per each value, 0 for autodetect.
pub bits_per_value: u8,
/// Choose the size of each level.
pub level_size_chooser: LSC,
/// Constructs collision solver that decides which collisions are positive, and which are negative.
pub collision_solver: CSB,
/// The family of hash functions used by the constructed [`fp::Map`](crate::fp::Map). (default: [`BuildDefaultSeededHasher`])
pub hash: S,
Expand Down
3 changes: 3 additions & 0 deletions csf/src/fp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ pub use map::{Map, MapConf};
mod cmap;
pub use cmap::{CMap, CMapConf};

mod gomap;
pub use gomap::{GOMap, GOMapConf};

mod gocmap;
pub use gocmap::{GOCMap, GOCMapConf};
pub use ph::fmph::{GroupSize, SeedSize, TwoToPowerBits, TwoToPowerBitsStatic, Bits, Bits8, GOConf};
Expand Down

0 comments on commit 68d2a9a

Please sign in to comment.