Skip to content

Commit

Permalink
work on fp GOMap
Browse files Browse the repository at this point in the history
  • Loading branch information
beling committed Sep 26, 2024
1 parent 68d2a9a commit 7142977
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 1 deletion.
1 change: 1 addition & 0 deletions bitm/src/rank_select/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,7 @@ impl<const MAX_RESULT: u8> CombinedSamplingDensity for AdaptiveCombinedSamplingD
/// - Zhou D., Andersen D.G., Kaminsky M. (2013) "Space-Efficient, High-Performance Rank and Select Structures on Uncompressed Bit Sequences".
/// In: Bonifaci V., Demetrescu C., Marchetti-Spaccamela A. (eds) Experimental Algorithms. SEA 2013.
/// Lecture Notes in Computer Science, vol 7933. Springer, Berlin, Heidelberg. <https://doi.org/10.1007/978-3-642-38527-8_15>
///
/// However, our implementation can automatically adjust the sampling density according to the content of the vector
/// (see [`AdaptiveCombinedSamplingDensity`]).
///
Expand Down
30 changes: 30 additions & 0 deletions csf/src/fp/gomap/conf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,21 @@ impl<GS: GroupSize, SS: SeedSize, S> GOMapConf<OptimalLevelSize, LoMemAcceptEqua
}
}

impl<CSB: CollisionSolverBuilder, GS: GroupSize, SS: SeedSize, S> GOMapConf<OptimalLevelSize, CSB, GS, SS, S> {
#[inline] pub fn groups_cs(goconf: GOConf<GS, SS, S>, collision_solver: CSB) -> Self {
Self::groups_cs_bpv(goconf, collision_solver, Default::default())
}

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

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)
Expand All @@ -88,6 +103,21 @@ impl<LSC> GOMapConf<LSC, LoMemAcceptEquals, TwoToPowerBitsStatic::<4>, TwoToPowe
}
}

impl<LSC, CSB: CollisionSolverBuilder> GOMapConf<LSC, CSB, TwoToPowerBitsStatic::<4>, TwoToPowerBitsStatic<2>, BuildDefaultSeededHasher> {
pub fn lsize_cs(level_size_chooser: LSC, collision_solver: CSB) -> Self {
Self::lsize_cs_bpv(level_size_chooser, collision_solver, Default::default())
}

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

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() }
Expand Down
31 changes: 30 additions & 1 deletion csf/src/fp/gomap/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,33 @@
use ph::{BuildDefaultSeededHasher, BuildSeededHasher, stats, utils::ArrayWithRank};
use ph::fmph::{goindexing::group_nr, GroupSize, SeedSize, TwoToPowerBitsStatic};
pub use ph::fmph::GOConf;
use dyn_size_of::GetSize;

mod conf;
pub use conf::GOMapConf;

pub struct GOMap {}
/// Finger-printing based compressed static function (immutable map)
/// that uses group optimization and maps hashable keys to unsigned integer values of given bit-size.
///
/// It usually takes somewhat more than *nb* bits to represent a function from an *n*-element set into a set of *b*-bit values.
/// (Smaller sizes are achieved when the set of values is small and the same values are assigned to multiple keys.)
/// The expected time complexities of its construction and evaluation are *O(n)* and *O(1)*, respectively.
pub struct GOMap<GS: GroupSize = TwoToPowerBitsStatic::<4>, SS: SeedSize = TwoToPowerBitsStatic<2>, S = BuildDefaultSeededHasher> {
array: ArrayWithRank,
values: Box<[u64]>, // BitVec
bits_per_value: u8,
group_seeds: Box<[SS::VecElement]>, // Box<[u8]>,
level_size: Box<[u64]>, // number of groups
goconf: GOConf<GS, SS, S>,
}

impl<GS: GroupSize, SS: SeedSize, S> GetSize for GOMap<GS, SS, S> {
fn size_bytes_dyn(&self) -> usize {
self.array.size_bytes_dyn()
+ self.values.size_bytes_dyn()
+ self.group_seeds.size_bytes_dyn()
+ self.level_size.size_bytes_dyn()
}
const USES_DYN_MEM: bool = true;
}

0 comments on commit 7142977

Please sign in to comment.