Skip to content

Commit

Permalink
Fix quickphf_codegen implementation to satisfy MSRV
Browse files Browse the repository at this point in the history
  • Loading branch information
dtrifuno committed Oct 18, 2023
1 parent b210f2c commit 5379e43
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
19 changes: 19 additions & 0 deletions quickphf_codegen/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Fixed

- Fix implementation to satisfy minimum supported Rust version.

## [0.1.0] - 2023-10-16

Initial release.

[unreleased]: https://github.com/dtrifuno/quickphf
[0.1.0]: https://github.com/dtrifuno/quickphf/releases/tag/v0.1.0
6 changes: 5 additions & 1 deletion quickphf_codegen/src/phf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ use quickphf::shared::*;
const MAX_ALPHA: f64 = 0.99;
const MIN_C: f64 = 1.5;

fn ilog2(n: u64) -> u32 {
63 - n.leading_zeros()
}

/// Parameters for a PTHash perfect hash function.
#[derive(Debug)]
pub struct Phf {
Expand All @@ -31,7 +35,7 @@ pub fn generate_phf<H: Eq + Hash>(entries: &[H]) -> Phf {
}

let n = entries.len() as u64;
let lg = n.ilog2() as f64;
let lg = ilog2(n) as f64;
let c = MIN_C + 0.2 * lg;
let buckets_len = DivisorU64::new(if n > 1 {
((c * n as f64) / lg).ceil() as u64
Expand Down

0 comments on commit 5379e43

Please sign in to comment.