Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion optd-cost-model/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion optd-cost-model/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ datafusion-expr = "32.0.0"
ordered-float = "4.0"
chrono = "0.4"
itertools = "0.13"
lazy_static = "1.5"
once_cell = "1.20"

[dev-dependencies]
crossbeam = "0.8"
Expand Down
21 changes: 9 additions & 12 deletions optd-cost-model/src/stats/arith_encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@

use std::collections::HashMap;

// TODO: Use lazy cell instead of lazy static.
use lazy_static::lazy_static;
use once_cell::sync::Lazy;

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

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

lazy_static! {
static ref CDF: HashMap<char, f64> = {
let length = ALPHANUMERIC_ORDER.len() + 1; // To account for non-alpha-numeric characters.
let mut cdf = HashMap::with_capacity(length);
for (index, &char) in ALPHANUMERIC_ORDER.iter().enumerate() {
cdf.insert(char, (index as f64) / (length as f64));
}
cdf
};
}
static CDF: Lazy<HashMap<char, f64>> = Lazy::new(|| {
let length = ALPHANUMERIC_ORDER.len() + 1; // To account for non-alpha-numeric characters.
let mut cdf = HashMap::with_capacity(length);
for (index, &char) in ALPHANUMERIC_ORDER.iter().enumerate() {
cdf.insert(char, (index as f64) / (length as f64));
}
cdf
});

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