Skip to content

Commit

Permalink
Remove dead data struct IanaToBcp47MapV1
Browse files Browse the repository at this point in the history
  • Loading branch information
sffc committed Dec 18, 2024
1 parent 5d861be commit 65b7375
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 83 deletions.
41 changes: 4 additions & 37 deletions components/timezone/src/provider/names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,42 +14,9 @@
use crate::TimeZoneBcp47Id;
use icu_provider::prelude::*;
use zerotrie::{ZeroAsciiIgnoreCaseTrie, ZeroTrie};
use zerotrie::ZeroAsciiIgnoreCaseTrie;
use zerovec::{VarZeroVec, ZeroVec};

/// A mapping from lowercase IANA time zone identifiers to BCP-47 time zone identifiers.
///
/// Multiple IANA time zone IDs can map to the same BCP-47 time zone ID.
///
/// <div class="stab unstable">
/// 🚧 This code is considered unstable; it may change at any time, in breaking or non-breaking ways,
/// including in SemVer minor releases. While the serde representation of data structs is guaranteed
/// to be stable, their Rust representation might not be. Use with caution.
/// </div>
#[derive(Debug, Clone, PartialEq)]
#[icu_provider::data_struct(marker(
IanaToBcp47MapV1Marker,
"time_zone/iana_to_bcp47@1",
singleton
))]
#[cfg_attr(feature = "datagen", derive(serde::Serialize, databake::Bake))]
#[cfg_attr(feature = "datagen", databake(path = icu_timezone::provider::names))]
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
#[yoke(prove_covariance_manually)]
pub struct IanaToBcp47MapV1<'data> {
/// A map from IANA time zone identifiers to indexes of BCP-47 time zone identifiers.
/// The IANA identifiers are lowercase.
#[cfg_attr(feature = "serde", serde(borrow))]
pub map: ZeroTrie<ZeroVec<'data, u8>>,
/// A sorted list of BCP-47 time zone identifiers.
#[cfg_attr(feature = "serde", serde(borrow))]
// Note: this is 9739B as `ZeroVec<TimeZoneBcp47Id>` (`ZeroVec<TinyStr8>`)
// and 9335B as `VarZeroVec<str>`
pub bcp47_ids: ZeroVec<'data, TimeZoneBcp47Id>,
/// An XxHash64 checksum of [`Self::bcp47_ids`].
pub bcp47_ids_checksum: u64,
}

/// [`IanaToBcp47MapV3`]'s trie cannot handle differently-cased prefixes, like `Mexico/BajaSur`` and `MET`.
///
/// Therefore, any ID that is not of the shape `{region}/{city}` gets prefixed with this character
Expand Down Expand Up @@ -119,13 +86,13 @@ pub struct IanaToBcp47MapV3<'data> {
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
#[yoke(prove_covariance_manually)]
pub struct Bcp47ToIanaMapV1<'data> {
/// An XxHash64 checksum of [`IanaToBcp47MapV1::bcp47_ids`].
/// An XxHash64 checksum of [`IanaToBcp47MapV3::bcp47_ids`].
///
/// The checksum here should match the checksum in [`IanaToBcp47MapV1`]
/// The checksum here should match the checksum in [`IanaToBcp47MapV3`]
/// if these were generated from the same data set.
pub bcp47_ids_checksum: u64,
/// The IANA time zone identifier corresponding to the BCP-47 ID in
/// [`IanaToBcp47MapV1::bcp47_ids`].
/// [`IanaToBcp47MapV3::bcp47_ids`].
///
/// Since there can be more than one IANA identifier for a particular
/// BCP-47 identifier, this list contains only the current canonical
Expand Down
47 changes: 1 addition & 46 deletions provider/source/src/time_zones/names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,54 +10,9 @@ use std::collections::BTreeMap;
use std::collections::BTreeSet;
use std::collections::HashSet;
use std::hash::Hasher;
use zerotrie::{ZeroAsciiIgnoreCaseTrie, ZeroTriePerfectHash};
use zerotrie::ZeroAsciiIgnoreCaseTrie;
use zerovec::{ZeroSlice, ZeroVec};

impl DataProvider<IanaToBcp47MapV1Marker> for SourceDataProvider {
fn load(&self, _: DataRequest) -> Result<DataResponse<IanaToBcp47MapV1Marker>, DataError> {
let iana2bcp = &self.compute_bcp47_tzids_btreemap()?;

// Sort and deduplicate the BCP-47 IDs:
let bcp_set: BTreeSet<TimeZoneBcp47Id> = iana2bcp.values().copied().collect();
let bcp47_ids: ZeroVec<TimeZoneBcp47Id> = bcp_set.iter().copied().collect();
let bcp47_ids_checksum = compute_bcp47_ids_hash(&bcp47_ids);

// Transform the map to use BCP indices:
#[allow(clippy::unwrap_used)] // structures are derived from each other
let map: BTreeMap<Vec<u8>, usize> = iana2bcp
.iter()
.map(|(iana, bcp)| {
(
iana.as_bytes().to_ascii_lowercase().to_vec(),
bcp47_ids.binary_search(bcp).unwrap(),
)
})
.collect();

let data_struct = IanaToBcp47MapV1 {
map: ZeroTriePerfectHash::try_from(&map)
.map_err(|e| {
DataError::custom("Could not create ZeroTrie from timezone.json data")
.with_display_context(&e)
})?
.convert_store()
.into_zerotrie(),
bcp47_ids,
bcp47_ids_checksum,
};
Ok(DataResponse {
metadata: Default::default(),
payload: DataPayload::from_owned(data_struct),
})
}
}

impl crate::IterableDataProviderCached<IanaToBcp47MapV1Marker> for SourceDataProvider {
fn iter_ids_cached(&self) -> Result<HashSet<DataIdentifierCow<'static>>, DataError> {
Ok(HashSet::from_iter([Default::default()]))
}
}

impl DataProvider<IanaToBcp47MapV3Marker> for SourceDataProvider {
fn load(&self, _: DataRequest) -> Result<DataResponse<IanaToBcp47MapV3Marker>, DataError> {
let iana2bcp = &self.compute_bcp47_tzids_btreemap()?;
Expand Down

0 comments on commit 65b7375

Please sign in to comment.