Skip to content

Commit

Permalink
fixes in doc. and names
Browse files Browse the repository at this point in the history
  • Loading branch information
beling committed Sep 25, 2024
1 parent 0460321 commit 460a69e
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 97 deletions.
60 changes: 30 additions & 30 deletions csf/src/fp/cmap/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl<C: Coding, S: BuildSeededHasher> CMap<C, S> {
self.get_stats(k, &mut ())
}

/// Build BBMap for given keys -> values map, where:
/// Build `CMap` for given keys -> values map, where:
/// - keys are given directly
/// - values are encoded by `value_coding` and given in as values_fragments and corresponding values_fragments_sizes
/// All three arrays must be of the same length.
Expand Down Expand Up @@ -199,7 +199,7 @@ impl<C: SerializableCoding, S: BuildSeededHasher> CMap<C, S> {
AsIs::write_all(output, self.value_fragments.iter())
}

/// Read self from the input, using read_value to read values (hasher must be the same as used by written `BBMap`).
/// Read self from the input, using read_value to read values (hasher must be the same as used by written `CMap`).
pub fn read_with_hasher<F>(input: &mut dyn io::Read, read_value: F, hasher: S) -> io::Result<Self>
where F: FnMut(&mut dyn io::Read) -> io::Result<C::Value>
{
Expand All @@ -220,7 +220,7 @@ impl<C: SerializableCoding, S: BuildSeededHasher> CMap<C, S> {

impl<C: SerializableCoding> CMap<C> {
/// Reads `Self` from the `input`, using `read_value` to read values.
/// Only `BBMap`s that use default hasher can be read by this method.
/// Only `CMap`s that use default hasher can be read by this method.
pub fn read<F>(input: &mut dyn io::Read, read_value: F) -> io::Result<Self>
where F: FnMut(&mut dyn io::Read) -> io::Result<C::Value>
{
Expand Down Expand Up @@ -317,31 +317,31 @@ mod tests {
use bitm::ceiling_div;
use crate::coding::BuildMinimumRedundancy;

fn test_read_write<C: SerializableCoding<Value=u8>>(bbmap: &CMap<C>) {
fn test_read_write<C: SerializableCoding<Value=u8>>(fpmap: &CMap<C>) {
let mut buff = Vec::new();
bbmap.write(&mut buff, |b, v| AsIs::write(b, *v)).unwrap();
assert_eq!(buff.len(), bbmap.write_bytes(1));
fpmap.write(&mut buff, |b, v| AsIs::write(b, *v)).unwrap();
assert_eq!(buff.len(), fpmap.write_bytes(1));
let read = CMap::<C>::read(&mut &buff[..], |b| AsIs::read(b)).unwrap();
assert_eq!(bbmap.array.content, read.array.content);
assert_eq!(bbmap.level_sizes, read.level_sizes);
assert_eq!(fpmap.array.content, read.array.content);
assert_eq!(fpmap.level_sizes, read.level_sizes);
}

fn test_bbmap_invariants<C: Coding>(bbmap: &CMap<C>) {
assert_eq!(bbmap.level_sizes.iter().map(|v|*v as usize).sum::<usize>(), bbmap.array.content.len());
fn test_fpmap_invariants<C: Coding>(fpmap: &CMap<C>) {
assert_eq!(fpmap.level_sizes.iter().map(|v|*v as usize).sum::<usize>(), fpmap.array.content.len());
assert_eq!(
ceiling_div(bbmap.array.content.iter().map(|v|v.count_ones()).sum::<u32>() as usize * bbmap.value_coding.bits_per_fragment() as usize, 64),
bbmap.value_fragments.len()
ceiling_div(fpmap.array.content.iter().map(|v|v.count_ones()).sum::<u32>() as usize * fpmap.value_coding.bits_per_fragment() as usize, 64),
fpmap.value_fragments.len()
);
}

fn test_4pairs<LSC: LevelSizeChooser>(conf: CMapConf<BuildMinimumRedundancy, LSC>) {
let bbmap = CMap::from_map_with_conf(&hashmap!('a'=>1u8, 'b'=>2u8, 'c'=>1u8, 'd'=>3u8), conf, &mut ());
assert_eq!(bbmap.get(&'a'), Some(&1));
assert_eq!(bbmap.get(&'b'), Some(&2));
assert_eq!(bbmap.get(&'c'), Some(&1));
assert_eq!(bbmap.get(&'d'), Some(&3));
test_bbmap_invariants(&bbmap);
test_read_write(&bbmap);
let fpmap = CMap::from_map_with_conf(&hashmap!('a'=>1u8, 'b'=>2u8, 'c'=>1u8, 'd'=>3u8), conf, &mut ());
assert_eq!(fpmap.get(&'a'), Some(&1));
assert_eq!(fpmap.get(&'b'), Some(&2));
assert_eq!(fpmap.get(&'c'), Some(&1));
assert_eq!(fpmap.get(&'d'), Some(&3));
test_fpmap_invariants(&fpmap);
test_read_write(&fpmap);
}

#[test]
Expand All @@ -350,19 +350,19 @@ mod tests {
}

fn test_8pairs<LSC: LevelSizeChooser>(conf: CMapConf<BuildMinimumRedundancy, LSC>) {
let bbmap = CMap::from_map_with_conf(&hashmap!(
let fpmap = CMap::from_map_with_conf(&hashmap!(
'a' => 1, 'b' => 2, 'c' => 1, 'd' => 3,
'e' => 4, 'f' => 1, 'g' => 5, 'h' => 6), conf, &mut ());
assert_eq!(bbmap.get(&'a'), Some(&1));
assert_eq!(bbmap.get(&'b'), Some(&2));
assert_eq!(bbmap.get(&'c'), Some(&1));
assert_eq!(bbmap.get(&'d'), Some(&3));
assert_eq!(bbmap.get(&'e'), Some(&4));
assert_eq!(bbmap.get(&'f'), Some(&1));
assert_eq!(bbmap.get(&'g'), Some(&5));
assert_eq!(bbmap.get(&'h'), Some(&6));
test_bbmap_invariants(&bbmap);
test_read_write(&bbmap);
assert_eq!(fpmap.get(&'a'), Some(&1));
assert_eq!(fpmap.get(&'b'), Some(&2));
assert_eq!(fpmap.get(&'c'), Some(&1));
assert_eq!(fpmap.get(&'d'), Some(&3));
assert_eq!(fpmap.get(&'e'), Some(&4));
assert_eq!(fpmap.get(&'f'), Some(&1));
assert_eq!(fpmap.get(&'g'), Some(&5));
assert_eq!(fpmap.get(&'h'), Some(&6));
test_fpmap_invariants(&fpmap);
test_read_write(&fpmap);
}

#[test]
Expand Down
8 changes: 4 additions & 4 deletions csf/src/fp/collision_solver.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use bitm::{BitAccess, BitVec, n_lowest_bits};

/// Solves value collisions during construction of BBMap.
/// Solves value collisions during construction of fingerprinting based maps.
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 @@ -34,11 +34,11 @@ pub trait CollisionSolverBuilder {
fn is_lossless(&self) -> bool;
}

/// Shows that the builder always produces the collision solver that is lossless and thus can be used with compressed BBmap.
/// Shows that the builder always produces the collision solver that is lossless and thus can be used with compressed maps.
pub trait IsLossless: CollisionSolverBuilder {} // TODO: maybe check only in runtime by is_lossless method


/// BBMap collision solver that permits assigning only one value (few equal values) to each index.
/// Collision solver that permits assigning only one value (few equal values) to each index.
pub struct LoMemAcceptEqualsSolver {
/// Which indices are under collision.
collided: Box<[u64]>,
Expand Down Expand Up @@ -94,7 +94,7 @@ impl CollisionSolverBuilder for LoMemAcceptEquals {
impl IsLossless for LoMemAcceptEquals {}


/// BBMap collision solver that permits assigning only one value (few equal values) to each index.
/// Collision solver that permits assigning only one value (few equal values) to each index.
pub struct AcceptEqualsSolver {
/// Which indices are under collision.
collided: Box<[u64]>,
Expand Down
5 changes: 4 additions & 1 deletion csf/src/fp/gocmap/conf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ use crate::coding::BuildMinimumRedundancy;
pub struct GOCMapConf<
BC = BuildMinimumRedundancy,
LSC = OptimalLevelSize,
GS: GroupSize = TwoToPowerBitsStatic::<4>, SS: SeedSize = TwoToPowerBitsStatic<2>, S = BuildDefaultSeededHasher
GS: GroupSize = TwoToPowerBitsStatic::<4>,
SS: SeedSize = TwoToPowerBitsStatic<2>,
S = BuildDefaultSeededHasher
> {
/// Coding used to map the values to codewords that are sequences of code fragments.
pub coding: BC,
/// Configuration of family of (group-optimized) hash functions (default: [`GOConf::default`]).
pub goconf: GOConf<GS, SS, S>,
Expand Down
70 changes: 35 additions & 35 deletions csf/src/fp/gocmap/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ impl<C: Coding, GS: GroupSize, SS: SeedSize, S: BuildSeededHasher> GOCMap<C, GS,
self.get_stats(k, &mut ())
}

/// Build BBMap2 for given keys -> values map, where:
/// Build `GOCMap` for given keys -> values map, where:
/// - keys are given directly
/// - values are encoded by Minimum-Redundancy (value_coding) and given in as values_fragments and corresponding values_fragments_sizes
/// All three arrays must be of the same length.
Expand Down Expand Up @@ -280,7 +280,7 @@ impl<C: SerializableCoding, S: BuildSeededHasher, GS: GroupSize, SS: SeedSize> G

impl<GS: GroupSize, SS: SeedSize, C: SerializableCoding> GOCMap<C, GS, SS> {
/// Reads `Self` from the `input`, using `read_value` to read values.
/// Only `BBMap2`s that use default hasher can be read by this method.
/// Only `GOCMap`s that use default hasher can be read by this method.
pub fn read<F>(input: &mut dyn io::Read, read_value: F) -> io::Result<Self>
where F: FnMut(&mut dyn io::Read) -> io::Result<C::Value>
{
Expand Down Expand Up @@ -376,37 +376,37 @@ mod tests {
use crate::coding::BuildMinimumRedundancy;
//use minimum_redundancy::{write_int, read_int};

fn test_read_write<GS: GroupSize, SS: SeedSize, C: SerializableCoding<Value=u8>>(bbmap: &GOCMap<C, GS, SS>) where SS::VecElement: PartialEq + Debug {
fn test_read_write<GS: GroupSize, SS: SeedSize, C: SerializableCoding<Value=u8>>(fpmap: &GOCMap<C, GS, SS>) where SS::VecElement: PartialEq + Debug {
let mut buff = Vec::new();
bbmap.write(&mut buff, |b, v| AsIs::write(b, *v)).unwrap();
assert_eq!(buff.len(), bbmap.write_bytes(1));
fpmap.write(&mut buff, |b, v| AsIs::write(b, *v)).unwrap();
assert_eq!(buff.len(), fpmap.write_bytes(1));
let read = GOCMap::<C, GS, SS>::read(&mut &buff[..], |b| AsIs::read(b)).unwrap();
assert_eq!(bbmap.level_size, read.level_size);
assert_eq!(bbmap.array.content, read.array.content);
assert_eq!(bbmap.group_seeds, read.group_seeds);
assert_eq!(bbmap.value_fragments, read.value_fragments);
assert_eq!(bbmap.goconf.bits_per_group.into(), read.goconf.bits_per_group.into());
assert_eq!(bbmap.goconf.bits_per_seed.into(), read.goconf.bits_per_seed.into());
assert_eq!(fpmap.level_size, read.level_size);
assert_eq!(fpmap.array.content, read.array.content);
assert_eq!(fpmap.group_seeds, read.group_seeds);
assert_eq!(fpmap.value_fragments, read.value_fragments);
assert_eq!(fpmap.goconf.bits_per_group.into(), read.goconf.bits_per_group.into());
assert_eq!(fpmap.goconf.bits_per_seed.into(), read.goconf.bits_per_seed.into());
}

fn test_bbmap2_invariants<GS: GroupSize, SS: SeedSize, C: Coding>(bbmap: &GOCMap<C, GS, SS>) {
let number_of_groups = bbmap.level_size.iter().map(|v| *v as usize).sum::<usize>();
assert_eq!(bbmap.goconf.bits_per_group * number_of_groups, bbmap.array.content.len() * 64);
assert_eq!(ceiling_div(bbmap.goconf.bits_per_seed.into() as usize * number_of_groups, 64), bbmap.group_seeds.len());
fn test_fpcmap_invariants<GS: GroupSize, SS: SeedSize, C: Coding>(fpmap: &GOCMap<C, GS, SS>) {
let number_of_groups = fpmap.level_size.iter().map(|v| *v as usize).sum::<usize>();
assert_eq!(fpmap.goconf.bits_per_group * number_of_groups, fpmap.array.content.len() * 64);
assert_eq!(ceiling_div(fpmap.goconf.bits_per_seed.into() as usize * number_of_groups, 64), fpmap.group_seeds.len());
assert_eq!(
ceiling_div(bbmap.array.content.iter().map(|v|v.count_ones()).sum::<u32>() as usize * bbmap.value_coding.bits_per_fragment() as usize, 64),
bbmap.value_fragments.len()
ceiling_div(fpmap.array.content.iter().map(|v|v.count_ones()).sum::<u32>() as usize * fpmap.value_coding.bits_per_fragment() as usize, 64),
fpmap.value_fragments.len()
);
}

fn test_4pairs<GS: GroupSize, SS: SeedSize, LSC: LevelSizeChooser>(conf: GOCMapConf<BuildMinimumRedundancy, LSC, GS, SS>) where SS::VecElement: PartialEq + Debug {
let bbmap = GOCMap::from_map_with_conf(&hashmap!('a'=>1u8, 'b'=>2u8, 'c'=>1u8, 'd'=>3u8), conf, &mut ());
assert_eq!(bbmap.get(&'a'), Some(&1));
assert_eq!(bbmap.get(&'b'), Some(&2));
assert_eq!(bbmap.get(&'c'), Some(&1));
assert_eq!(bbmap.get(&'d'), Some(&3));
test_bbmap2_invariants(&bbmap);
test_read_write(&bbmap);
let fpmap = GOCMap::from_map_with_conf(&hashmap!('a'=>1u8, 'b'=>2u8, 'c'=>1u8, 'd'=>3u8), conf, &mut ());
assert_eq!(fpmap.get(&'a'), Some(&1));
assert_eq!(fpmap.get(&'b'), Some(&2));
assert_eq!(fpmap.get(&'c'), Some(&1));
assert_eq!(fpmap.get(&'d'), Some(&3));
test_fpcmap_invariants(&fpmap);
test_read_write(&fpmap);
}

#[test]
Expand All @@ -415,19 +415,19 @@ mod tests {
}

fn test_8pairs<GS: GroupSize, SS: SeedSize, LSC: LevelSizeChooser>(conf: GOCMapConf<BuildMinimumRedundancy, LSC, GS, SS>) where SS::VecElement: PartialEq + Debug {
let bbmap = GOCMap::from_map_with_conf(&hashmap!(
let fpmap = GOCMap::from_map_with_conf(&hashmap!(
'a' => 1, 'b' => 2, 'c' => 1, 'd' => 3,
'e' => 4, 'f' => 1, 'g' => 5, 'h' => 6), conf, &mut ());
assert_eq!(bbmap.get(&'a'), Some(&1));
assert_eq!(bbmap.get(&'b'), Some(&2));
assert_eq!(bbmap.get(&'c'), Some(&1));
assert_eq!(bbmap.get(&'d'), Some(&3));
assert_eq!(bbmap.get(&'e'), Some(&4));
assert_eq!(bbmap.get(&'f'), Some(&1));
assert_eq!(bbmap.get(&'g'), Some(&5));
assert_eq!(bbmap.get(&'h'), Some(&6));
test_bbmap2_invariants(&bbmap);
test_read_write(&bbmap);
assert_eq!(fpmap.get(&'a'), Some(&1));
assert_eq!(fpmap.get(&'b'), Some(&2));
assert_eq!(fpmap.get(&'c'), Some(&1));
assert_eq!(fpmap.get(&'d'), Some(&3));
assert_eq!(fpmap.get(&'e'), Some(&4));
assert_eq!(fpmap.get(&'f'), Some(&1));
assert_eq!(fpmap.get(&'g'), Some(&5));
assert_eq!(fpmap.get(&'h'), Some(&6));
test_fpcmap_invariants(&fpmap);
test_read_write(&fpmap);
}

#[test]
Expand Down
54 changes: 27 additions & 27 deletions csf/src/fp/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl<S: BuildSeededHasher> Map<S> {
self.get_stats(k, &mut ())
}

/// Build BBMap for given keys -> values map, where:
/// Build `Map` for given keys -> values map, where:
/// - keys are given directly,
/// - TODO values are given as bit vector with bit_per_value.
/// These arrays must be of the same length.
Expand Down Expand Up @@ -237,30 +237,30 @@ mod tests {
use bitm::ceiling_div;
use maplit::hashmap;

fn test_read_write(bbmap: &Map) {
fn test_read_write(fpmap: &Map) {
let mut buff = Vec::new();
bbmap.write(&mut buff).unwrap();
assert_eq!(buff.len(), bbmap.write_bytes());
fpmap.write(&mut buff).unwrap();
assert_eq!(buff.len(), fpmap.write_bytes());
let read = Map::read(&mut &buff[..]).unwrap();
assert_eq!(bbmap.level_sizes, read.level_sizes);
assert_eq!(fpmap.level_sizes, read.level_sizes);
}

fn test_bbmap_invariants(bbmap: &Map) {
assert_eq!(bbmap.level_sizes.iter().map(|v| *v as usize).sum::<usize>(), bbmap.array.content.len());
fn test_fpmap_invariants(fpmap: &Map) {
assert_eq!(fpmap.level_sizes.iter().map(|v| *v as usize).sum::<usize>(), fpmap.array.content.len());
assert_eq!(
ceiling_div(bbmap.array.content.iter().map(|v|v.count_ones()).sum::<u32>() as usize * bbmap.bits_per_value as usize, 64),
bbmap.values.len()
ceiling_div(fpmap.array.content.iter().map(|v|v.count_ones()).sum::<u32>() as usize * fpmap.bits_per_value as usize, 64),
fpmap.values.len()
);
}

fn test_4pairs(conf: MapConf) {
let bbmap = Map::with_map_conf(&hashmap!('a'=>1u8, 'b'=>2u8, 'c'=>1u8, 'd'=>3u8), conf, &mut ());
assert_eq!(bbmap.get(&'a'), Some(1));
assert_eq!(bbmap.get(&'b'), Some(2));
assert_eq!(bbmap.get(&'c'), Some(1));
assert_eq!(bbmap.get(&'d'), Some(3));
test_bbmap_invariants(&bbmap);
test_read_write(&bbmap);
let fpmap = Map::with_map_conf(&hashmap!('a'=>1u8, 'b'=>2u8, 'c'=>1u8, 'd'=>3u8), conf, &mut ());
assert_eq!(fpmap.get(&'a'), Some(1));
assert_eq!(fpmap.get(&'b'), Some(2));
assert_eq!(fpmap.get(&'c'), Some(1));
assert_eq!(fpmap.get(&'d'), Some(3));
test_fpmap_invariants(&fpmap);
test_read_write(&fpmap);
}

#[test]
Expand All @@ -269,19 +269,19 @@ mod tests {
}

fn test_8pairs<LSC: SimpleLevelSizeChooser>(conf: MapConf<LSC>) {
let bbmap = Map::with_map_conf(&hashmap!(
let fpmap = Map::with_map_conf(&hashmap!(
'a' => 1, 'b' => 2, 'c' => 1, 'd' => 3,
'e' => 4, 'f' => 1, 'g' => 5, 'h' => 6), conf, &mut ());
assert_eq!(bbmap.get(&'a'), Some(1));
assert_eq!(bbmap.get(&'b'), Some(2));
assert_eq!(bbmap.get(&'c'), Some(1));
assert_eq!(bbmap.get(&'d'), Some(3));
assert_eq!(bbmap.get(&'e'), Some(4));
assert_eq!(bbmap.get(&'f'), Some(1));
assert_eq!(bbmap.get(&'g'), Some(5));
assert_eq!(bbmap.get(&'h'), Some(6));
test_bbmap_invariants(&bbmap);
test_read_write(&bbmap);
assert_eq!(fpmap.get(&'a'), Some(1));
assert_eq!(fpmap.get(&'b'), Some(2));
assert_eq!(fpmap.get(&'c'), Some(1));
assert_eq!(fpmap.get(&'d'), Some(3));
assert_eq!(fpmap.get(&'e'), Some(4));
assert_eq!(fpmap.get(&'f'), Some(1));
assert_eq!(fpmap.get(&'g'), Some(5));
assert_eq!(fpmap.get(&'h'), Some(6));
test_fpmap_invariants(&fpmap);
test_read_write(&fpmap);
}

#[test]
Expand Down

0 comments on commit 460a69e

Please sign in to comment.