Skip to content

Commit 144a775

Browse files
committed
use once cell instead of lazy static
1 parent 91deb07 commit 144a775

File tree

3 files changed

+12
-15
lines changed

3 files changed

+12
-15
lines changed

optd-cost-model/Cargo.lock

Lines changed: 1 addition & 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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ datafusion-expr = "32.0.0"
1313
ordered-float = "4.0"
1414
chrono = "0.4"
1515
itertools = "0.13"
16-
lazy_static = "1.5"
16+
once_cell = "1.20"
1717

1818
[dev-dependencies]
1919
crossbeam = "0.8"

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

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@
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;
10+
use std::{cell::LazyCell, collections::HashMap};
1111

12-
// TODO: Use lazy cell instead of lazy static.
13-
use lazy_static::lazy_static;
12+
use once_cell::sync::Lazy;
1413

1514
// The alphanumerical ordering.
1615
const ALPHANUMERIC_ORDER: [char; 95] = [
@@ -23,16 +22,14 @@ const ALPHANUMERIC_ORDER: [char; 95] = [
2322

2423
const PMF: f64 = 1.0 / (ALPHANUMERIC_ORDER.len() as f64);
2524

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-
}
25+
static CDF: Lazy<HashMap<char, f64>> = Lazy::new(|| {
26+
let length = ALPHANUMERIC_ORDER.len() + 1; // To account for non-alpha-numeric characters.
27+
let mut cdf = HashMap::with_capacity(length);
28+
for (index, &char) in ALPHANUMERIC_ORDER.iter().enumerate() {
29+
cdf.insert(char, (index as f64) / (length as f64));
30+
}
31+
cdf
32+
});
3633

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

0 commit comments

Comments
 (0)