use std::collections::HashMap;
use std::sync::LazyLock;
use super::get_static_value_id::StaticValueId;
use super::get_static_value_id::hash_empty_string;
use super::get_static_value_id::hash_short_string;
use crate::values::FrozenValue;
use crate::values::layout::static_string::VALUE_BYTE_STRINGS;
use crate::values::layout::static_string::VALUE_EMPTY_STRING;
pub(super) struct StaticStringMaps {
pub(super) addr_to_id: HashMap<usize, StaticValueId>,
pub(super) id_to_value: HashMap<StaticValueId, FrozenValue>,
}
pub(super) static STATIC_STRING_MAPS: LazyLock<StaticStringMaps> = LazyLock::new(|| {
let mut addr_to_id = HashMap::new();
let mut id_to_value = HashMap::new();
let empty_fv = VALUE_EMPTY_STRING.unpack();
let empty_id = hash_empty_string();
addr_to_id.insert(empty_fv.ptr_value().ptr_value_untagged(), empty_id);
id_to_value.insert(empty_id, empty_fv);
for (i, repr) in VALUE_BYTE_STRINGS.iter().enumerate() {
let fv = repr.unpack();
let id = hash_short_string(i as u8);
addr_to_id.insert(fv.ptr_value().ptr_value_untagged(), id);
id_to_value.insert(id, fv);
}
StaticStringMaps {
addr_to_id,
id_to_value,
}
});