Skip to content

Commit

Permalink
Merge branch 'main' into yuchen/add-workspace-cargo-toml
Browse files Browse the repository at this point in the history
  • Loading branch information
yliang412 authored Nov 16, 2024
2 parents 30d187c + 0050d85 commit d3e17d1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 16 deletions.
1 change: 0 additions & 1 deletion optd-cost-model/Cargo.lock

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

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

[dev-dependencies]
crossbeam = "0.8"
Expand Down
23 changes: 9 additions & 14 deletions optd-cost-model/src/stats/arith_encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
//! Non-alpha-numeric characters are relegated to the end of the encoded value,
//! rendering them indistinguishable from one another in this context.
use std::collections::HashMap;

// TODO: Use lazy cell instead of lazy static.
use lazy_static::lazy_static;
use std::{collections::HashMap, sync::LazyLock};

// The alphanumerical ordering.
const ALPHANUMERIC_ORDER: [char; 95] = [
Expand All @@ -23,16 +20,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: LazyLock<HashMap<char, f64>> = LazyLock::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

0 comments on commit d3e17d1

Please sign in to comment.