Skip to content

Commit

Permalink
Use u64 where u32 won't fit
Browse files Browse the repository at this point in the history
  • Loading branch information
mmarx committed Dec 15, 2023
1 parent a6a36b9 commit 7bc58f8
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 22 deletions.
1 change: 1 addition & 0 deletions helpers/rust/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub use statistics::DumpStatistics;

type Id = u32;
type Count = u32;
type LargeCount = u64;

/// Returns true if the value is zero. Used to skip serialisation for
/// empty counters.
Expand Down
28 changes: 14 additions & 14 deletions helpers/rust/src/types/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use super::{
ids::{Item, Property, Qualifier},
is_zero,
sparql::{PropertyLabelAndType, PropertyUsage, PropertyUsageType},
ClassLabelAndUsage, Count,
ClassLabelAndUsage, Count, LargeCount,
};

const ENGLISH: &str = "en";
Expand Down Expand Up @@ -174,17 +174,17 @@ pub struct PropertyRecord {
#[serde(rename = "i", skip_serializing_if = "is_zero")]
pub(crate) in_items: Count,
#[serde(rename = "s", skip_serializing_if = "is_zero")]
pub(crate) in_statements: Count,
pub(crate) in_statements: LargeCount,
#[serde(rename = "q", skip_serializing_if = "is_zero")]
pub(crate) in_qualifiers: Count,
pub(crate) in_qualifiers: LargeCount,
#[serde(rename = "e", skip_serializing_if = "is_zero")]
pub(crate) in_references: Count,
pub(crate) in_references: LargeCount,
#[serde(rename = "u", skip_serializing_if = "Option::is_none")]
pub(crate) url_pattern: Option<String>,
#[serde(rename = "pc", skip_serializing_if = "HashSet::is_empty")]
pub(crate) instance_of: HashSet<Item>,
#[serde(rename = "qs", skip_serializing_if = "HashMap::is_empty")]
pub(crate) with_qualifiers: HashMap<Qualifier, Count>,
pub(crate) with_qualifiers: HashMap<Qualifier, LargeCount>,
#[serde(rename = "r", skip_serializing_if = "HashMap::is_empty")]
pub(crate) related_properties: HashMap<Property, Count>,
#[serde(skip)]
Expand Down Expand Up @@ -260,15 +260,15 @@ pub struct PropertyUsageRecord {
#[serde(rename = "i", skip_serializing_if = "is_zero")]
pub(crate) in_items: Count,
#[serde(rename = "s", skip_serializing_if = "is_zero")]
pub(crate) in_statements: Count,
pub(crate) in_statements: LargeCount,
#[serde(rename = "q", skip_serializing_if = "is_zero")]
pub(crate) in_qualifiers: Count,
pub(crate) in_qualifiers: LargeCount,
#[serde(rename = "e", skip_serializing_if = "is_zero")]
pub(crate) in_references: Count,
pub(crate) in_references: LargeCount,
#[serde(rename = "pc", skip_serializing_if = "HashSet::is_empty")]
pub(crate) instance_of: HashSet<Item>,
#[serde(rename = "qs", skip_serializing_if = "HashMap::is_empty")]
pub(crate) with_qualifiers: HashMap<Qualifier, Count>,
pub(crate) with_qualifiers: HashMap<Qualifier, LargeCount>,
}

#[derive(Debug, Default, PartialEq, Eq, Deserialize, Serialize)]
Expand Down Expand Up @@ -368,15 +368,15 @@ impl Classes {
#[serde(default)]
pub struct EntityStatistics {
#[serde(rename = "cDesc")]
pub(crate) descriptions: Count,
pub(crate) descriptions: LargeCount,
#[serde(rename = "cStmts")]
pub(crate) statements: Count,
pub(crate) statements: LargeCount,
#[serde(rename = "cLabels")]
pub(crate) labels: Count,
pub(crate) labels: LargeCount,
#[serde(rename = "cAliases")]
pub(crate) aliases: Count,
pub(crate) aliases: LargeCount,
#[serde(rename = "c")]
pub(crate) count: Count,
pub(crate) count: LargeCount,
}

#[derive(Debug, Default, PartialEq, Eq, Deserialize, Serialize)]
Expand Down
4 changes: 2 additions & 2 deletions helpers/rust/src/types/sparql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize};
use super::{
ids::{Entity, Item, Property, Qualifier, Reference},
json::Type,
Count,
Count, LargeCount,
};

#[derive(Debug, PartialEq, Eq, Deserialize, Serialize)]
Expand Down Expand Up @@ -39,7 +39,7 @@ pub struct PropertyUsage {
#[serde(rename = "p")]
pub(crate) property: PropertyUsageType,
#[serde(rename = "c")]
pub(crate) count: Count,
pub(crate) count: LargeCount,
}

impl PropertyUsage {
Expand Down
12 changes: 6 additions & 6 deletions helpers/rust/src/types/statistics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use super::{
dump::{CommonData, Rank, Record, Sitelink},
ClassRecord, PropertyRecord,
},
Classes, Count, EntityStatistics, Settings, SiteRecord, Statistics, Type,
Classes, Count, EntityStatistics, LargeCount, Settings, SiteRecord, Statistics, Type,
};

#[derive(Debug, Default)]
Expand Down Expand Up @@ -293,14 +293,14 @@ impl DumpStatistics {
EntityKind::Property => &mut self.statistics.properties,
_ => bail!("Unsupported entity kind {:?}", target),
};
stats.labels += Count::try_from(common.labels.len()).expect("should fit");
stats.descriptions += Count::try_from(common.descriptions.len()).expect("should fit");
stats.labels += LargeCount::try_from(common.labels.len()).expect("should fit");
stats.descriptions += LargeCount::try_from(common.descriptions.len()).expect("should fit");
stats.aliases += common
.aliases
.values()
.map(|aliases| aliases.len())
.filter_map(|count| Count::try_from(count).ok())
.sum::<Count>();
.filter_map(|count| LargeCount::try_from(count).ok())
.sum::<LargeCount>();

Ok(())
}
Expand Down Expand Up @@ -341,7 +341,7 @@ impl DumpStatistics {

for (property, statements) in common.claims.iter() {
self.stats_for_entity_kind(target)?.statements +=
Count::try_from(statements.len()).expect("should fit");
LargeCount::try_from(statements.len()).expect("should fit");
Self::count_cooccurring_properties(
common,
&mut self.properties.entry(*property).or_default().cooccurrences,
Expand Down

0 comments on commit 7bc58f8

Please sign in to comment.