Skip to content

Commit 0050d85

Browse files
authored
fix: use once cell instead of lazy static (#35)
1 parent 91deb07 commit 0050d85

File tree

3 files changed

+9
-16
lines changed

3 files changed

+9
-16
lines changed

optd-cost-model/Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

optd-cost-model/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ datafusion-expr = "32.0.0"
1313
ordered-float = "4.0"
1414
chrono = "0.4"
1515
itertools = "0.13"
16-
lazy_static = "1.5"
1716

1817
[dev-dependencies]
1918
crossbeam = "0.8"

optd-cost-model/src/stats/arith_encoder.rs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@
77
//! Non-alpha-numeric characters are relegated to the end of the encoded value,
88
//! rendering them indistinguishable from one another in this context.
99
10-
use std::collections::HashMap;
11-
12-
// TODO: Use lazy cell instead of lazy static.
13-
use lazy_static::lazy_static;
10+
use std::{collections::HashMap, sync::LazyLock};
1411

1512
// The alphanumerical ordering.
1613
const ALPHANUMERIC_ORDER: [char; 95] = [
@@ -23,16 +20,14 @@ const ALPHANUMERIC_ORDER: [char; 95] = [
2320

2421
const PMF: f64 = 1.0 / (ALPHANUMERIC_ORDER.len() as f64);
2522

26-
lazy_static! {
27-
static ref CDF: HashMap<char, f64> = {
28-
let length = ALPHANUMERIC_ORDER.len() + 1; // To account for non-alpha-numeric characters.
29-
let mut cdf = HashMap::with_capacity(length);
30-
for (index, &char) in ALPHANUMERIC_ORDER.iter().enumerate() {
31-
cdf.insert(char, (index as f64) / (length as f64));
32-
}
33-
cdf
34-
};
35-
}
23+
static CDF: LazyLock<HashMap<char, f64>> = LazyLock::new(|| {
24+
let length = ALPHANUMERIC_ORDER.len() + 1; // To account for non-alpha-numeric characters.
25+
let mut cdf = HashMap::with_capacity(length);
26+
for (index, &char) in ALPHANUMERIC_ORDER.iter().enumerate() {
27+
cdf.insert(char, (index as f64) / (length as f64));
28+
}
29+
cdf
30+
});
3631

3732
pub fn encode(string: &str) -> f64 {
3833
let mut left = 0.0;

0 commit comments

Comments
 (0)