Skip to content

Commit 254aa63

Browse files
committed
Changed usize to u64 globally stackmuncher/stm_server#30
1 parent d56342a commit 254aa63

File tree

8 files changed

+150
-144
lines changed

8 files changed

+150
-144
lines changed

stackmuncher_lib/src/contributor.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ pub struct Contributor {
2424
/// This can be taken from counting the number of entries in `commits` property, but that may be capped
2525
/// in the future, so it's easier to have a separate counter.
2626
#[serde(default)]
27-
pub commit_count: usize,
27+
pub commit_count: u64,
2828
/// The list of files touched by this contributor as FileName/CommitSHA1 tuple.
2929
pub touched_files: HashSet<ContributorFile>,
3030
/// A list of pointers at contributor commits in recent project commits member of Report.
3131
#[serde(skip_serializing_if = "Vec::is_empty", default = "Vec::new")]
32-
pub commits: Vec<usize>,
32+
pub commits: Vec<u64>,
3333
}
3434

3535
#[derive(Serialize, Deserialize, Debug, Clone, Eq)]
@@ -96,7 +96,8 @@ impl Contributor {
9696
}
9797

9898
// add the commit to the list of contributor commits
99-
contributor.commits.push(commit_idx);
99+
// the cast should be safe because the max number of commits within a project is well within u64 bounds
100+
contributor.commits.push(commit_idx as u64);
100101
} else {
101102
// it's a new contributor - add as-is
102103

@@ -113,7 +114,7 @@ impl Contributor {
113114
}
114115

115116
// add the commit to the list of contributor commits
116-
let contr_commits_list = vec![commit_idx];
117+
let contr_commits_list = vec![commit_idx as u64];
117118

118119
// init the contributor
119120
let contributor = Contributor {
@@ -147,7 +148,7 @@ impl Contributor {
147148
.collect::<HashSet<ContributorFile>>();
148149

149150
// this line will need to move if the list of commits is capped
150-
contributor.commit_count = contributor.commits.len();
151+
contributor.commit_count = contributor.commits.len() as u64;
151152

152153
output_collector.push(contributor);
153154
}

stackmuncher_lib/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ impl Report {
4343

4444
// get the list of files in the tree at HEAD
4545
let all_head_files = git::get_all_tree_files(project_dir, None, &code_rules.ignore_paths).await?;
46-
if all_head_files.len() > Report::MAX_FILES_PER_REPO {
46+
if all_head_files.len() as u64 > Report::MAX_FILES_PER_REPO {
4747
warn!("Repo ignored. Too many files: {}", all_head_files.len());
4848
return Err(());
4949
}
@@ -371,8 +371,8 @@ impl Report {
371371
.commits
372372
.iter()
373373
.filter_map(|idx| {
374-
if project_commits.len() > *idx {
375-
Some(project_commits[*idx].clone())
374+
if project_commits.len() as u64 > *idx {
375+
Some(project_commits[*idx as usize].clone())
376376
} else {
377377
None
378378
}

stackmuncher_lib/src/processors/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ pub(crate) async fn process_file(
7272
}
7373

7474
// get total lines
75-
tech.total_lines = lines.len();
75+
tech.total_lines = lines.len() as u64;
7676

7777
// set to true when the line is inside a block comment
7878
let mut inside_block_comment = false;

stackmuncher_lib/src/report/commit_time_histo.rs

Lines changed: 82 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -10,67 +10,67 @@ pub const RECENT_PERIOD_LENGTH_IN_DAYS: i64 = 365;
1010
/// The structure is skipped in JSON if all values are zero and is initialized to all zeros to have fewer Option<T> unwraps.
1111
#[derive(Serialize, Deserialize, Clone, Debug)]
1212
pub struct CommitTimeHistoHours {
13-
#[serde(skip_serializing_if = "CommitTimeHistoHours::is_zero", default = "usize::default")]
14-
pub h00: usize,
15-
#[serde(skip_serializing_if = "CommitTimeHistoHours::is_zero", default = "usize::default")]
16-
pub h01: usize,
17-
#[serde(skip_serializing_if = "CommitTimeHistoHours::is_zero", default = "usize::default")]
18-
pub h02: usize,
19-
#[serde(skip_serializing_if = "CommitTimeHistoHours::is_zero", default = "usize::default")]
20-
pub h03: usize,
21-
#[serde(skip_serializing_if = "CommitTimeHistoHours::is_zero", default = "usize::default")]
22-
pub h04: usize,
23-
#[serde(skip_serializing_if = "CommitTimeHistoHours::is_zero", default = "usize::default")]
24-
pub h05: usize,
25-
#[serde(skip_serializing_if = "CommitTimeHistoHours::is_zero", default = "usize::default")]
26-
pub h06: usize,
27-
#[serde(skip_serializing_if = "CommitTimeHistoHours::is_zero", default = "usize::default")]
28-
pub h07: usize,
29-
#[serde(skip_serializing_if = "CommitTimeHistoHours::is_zero", default = "usize::default")]
30-
pub h08: usize,
31-
#[serde(skip_serializing_if = "CommitTimeHistoHours::is_zero", default = "usize::default")]
32-
pub h09: usize,
33-
#[serde(skip_serializing_if = "CommitTimeHistoHours::is_zero", default = "usize::default")]
34-
pub h10: usize,
35-
#[serde(skip_serializing_if = "CommitTimeHistoHours::is_zero", default = "usize::default")]
36-
pub h11: usize,
37-
#[serde(skip_serializing_if = "CommitTimeHistoHours::is_zero", default = "usize::default")]
38-
pub h12: usize,
39-
#[serde(skip_serializing_if = "CommitTimeHistoHours::is_zero", default = "usize::default")]
40-
pub h13: usize,
41-
#[serde(skip_serializing_if = "CommitTimeHistoHours::is_zero", default = "usize::default")]
42-
pub h14: usize,
43-
#[serde(skip_serializing_if = "CommitTimeHistoHours::is_zero", default = "usize::default")]
44-
pub h15: usize,
45-
#[serde(skip_serializing_if = "CommitTimeHistoHours::is_zero", default = "usize::default")]
46-
pub h16: usize,
47-
#[serde(skip_serializing_if = "CommitTimeHistoHours::is_zero", default = "usize::default")]
48-
pub h17: usize,
49-
#[serde(skip_serializing_if = "CommitTimeHistoHours::is_zero", default = "usize::default")]
50-
pub h18: usize,
51-
#[serde(skip_serializing_if = "CommitTimeHistoHours::is_zero", default = "usize::default")]
52-
pub h19: usize,
53-
#[serde(skip_serializing_if = "CommitTimeHistoHours::is_zero", default = "usize::default")]
54-
pub h20: usize,
55-
#[serde(skip_serializing_if = "CommitTimeHistoHours::is_zero", default = "usize::default")]
56-
pub h21: usize,
57-
#[serde(skip_serializing_if = "CommitTimeHistoHours::is_zero", default = "usize::default")]
58-
pub h22: usize,
59-
#[serde(skip_serializing_if = "CommitTimeHistoHours::is_zero", default = "usize::default")]
60-
pub h23: usize,
13+
#[serde(skip_serializing_if = "CommitTimeHistoHours::is_zero", default = "u64::default")]
14+
pub h00: u64,
15+
#[serde(skip_serializing_if = "CommitTimeHistoHours::is_zero", default = "u64::default")]
16+
pub h01: u64,
17+
#[serde(skip_serializing_if = "CommitTimeHistoHours::is_zero", default = "u64::default")]
18+
pub h02: u64,
19+
#[serde(skip_serializing_if = "CommitTimeHistoHours::is_zero", default = "u64::default")]
20+
pub h03: u64,
21+
#[serde(skip_serializing_if = "CommitTimeHistoHours::is_zero", default = "u64::default")]
22+
pub h04: u64,
23+
#[serde(skip_serializing_if = "CommitTimeHistoHours::is_zero", default = "u64::default")]
24+
pub h05: u64,
25+
#[serde(skip_serializing_if = "CommitTimeHistoHours::is_zero", default = "u64::default")]
26+
pub h06: u64,
27+
#[serde(skip_serializing_if = "CommitTimeHistoHours::is_zero", default = "u64::default")]
28+
pub h07: u64,
29+
#[serde(skip_serializing_if = "CommitTimeHistoHours::is_zero", default = "u64::default")]
30+
pub h08: u64,
31+
#[serde(skip_serializing_if = "CommitTimeHistoHours::is_zero", default = "u64::default")]
32+
pub h09: u64,
33+
#[serde(skip_serializing_if = "CommitTimeHistoHours::is_zero", default = "u64::default")]
34+
pub h10: u64,
35+
#[serde(skip_serializing_if = "CommitTimeHistoHours::is_zero", default = "u64::default")]
36+
pub h11: u64,
37+
#[serde(skip_serializing_if = "CommitTimeHistoHours::is_zero", default = "u64::default")]
38+
pub h12: u64,
39+
#[serde(skip_serializing_if = "CommitTimeHistoHours::is_zero", default = "u64::default")]
40+
pub h13: u64,
41+
#[serde(skip_serializing_if = "CommitTimeHistoHours::is_zero", default = "u64::default")]
42+
pub h14: u64,
43+
#[serde(skip_serializing_if = "CommitTimeHistoHours::is_zero", default = "u64::default")]
44+
pub h15: u64,
45+
#[serde(skip_serializing_if = "CommitTimeHistoHours::is_zero", default = "u64::default")]
46+
pub h16: u64,
47+
#[serde(skip_serializing_if = "CommitTimeHistoHours::is_zero", default = "u64::default")]
48+
pub h17: u64,
49+
#[serde(skip_serializing_if = "CommitTimeHistoHours::is_zero", default = "u64::default")]
50+
pub h18: u64,
51+
#[serde(skip_serializing_if = "CommitTimeHistoHours::is_zero", default = "u64::default")]
52+
pub h19: u64,
53+
#[serde(skip_serializing_if = "CommitTimeHistoHours::is_zero", default = "u64::default")]
54+
pub h20: u64,
55+
#[serde(skip_serializing_if = "CommitTimeHistoHours::is_zero", default = "u64::default")]
56+
pub h21: u64,
57+
#[serde(skip_serializing_if = "CommitTimeHistoHours::is_zero", default = "u64::default")]
58+
pub h22: u64,
59+
#[serde(skip_serializing_if = "CommitTimeHistoHours::is_zero", default = "u64::default")]
60+
pub h23: u64,
6161
}
6262

6363
/// Contains members and methods related to commit time histogram
6464
#[derive(Serialize, Deserialize, Clone, Debug)]
6565
pub struct CommitTimeHisto {
6666
/// The sum of all commits included in `histogram_recent`. This value is used as the 100% of all recent commits.
6767
/// The value is populated once after all commits have been added.
68-
#[serde(skip_serializing_if = "CommitTimeHistoHours::is_zero", default = "usize::default")]
69-
pub histogram_recent_sum: usize,
68+
#[serde(skip_serializing_if = "CommitTimeHistoHours::is_zero", default = "u64::default")]
69+
pub histogram_recent_sum: u64,
7070
/// The sum of all commits included in `histogram_all`. This value is used as the 100% of all commits.
7171
/// The value is populated once after all commits have been added.
72-
#[serde(skip_serializing_if = "CommitTimeHistoHours::is_zero", default = "usize::default")]
73-
pub histogram_all_sum: usize,
72+
#[serde(skip_serializing_if = "CommitTimeHistoHours::is_zero", default = "u64::default")]
73+
pub histogram_all_sum: u64,
7474

7575
/// The standard deviation of `histogram_recent` values.
7676
#[serde(skip_serializing_if = "CommitTimeHistoHours::is_zero_f64", default = "f64::default")]
@@ -114,7 +114,7 @@ pub struct CommitTimeHisto {
114114

115115
impl CommitTimeHistoHours {
116116
/// A helper function for serde. Returns true if the value is zero.
117-
fn is_zero(val: &usize) -> bool {
117+
fn is_zero(val: &u64) -> bool {
118118
val == &0
119119
}
120120

@@ -188,38 +188,38 @@ impl CommitTimeHistoHours {
188188
}
189189

190190
/// Converts `hxx` values from the number of commits to percentage.
191-
fn convert_counts_to_percentage(&mut self, sum: usize) {
191+
fn convert_counts_to_percentage(&mut self, sum: u64) {
192192
if sum == 0 {
193193
return;
194194
}
195195

196196
// convert the sum into f64 to allow for rounding of the fraction after doing division
197197
let sum = sum as f64;
198198
// re-calculate every member
199-
self.h00 = (self.h00 as f64 * 100.0 / sum).round() as usize;
200-
self.h01 = (self.h01 as f64 * 100.0 / sum).round() as usize;
201-
self.h02 = (self.h02 as f64 * 100.0 / sum).round() as usize;
202-
self.h03 = (self.h03 as f64 * 100.0 / sum).round() as usize;
203-
self.h04 = (self.h04 as f64 * 100.0 / sum).round() as usize;
204-
self.h05 = (self.h05 as f64 * 100.0 / sum).round() as usize;
205-
self.h06 = (self.h06 as f64 * 100.0 / sum).round() as usize;
206-
self.h07 = (self.h07 as f64 * 100.0 / sum).round() as usize;
207-
self.h08 = (self.h08 as f64 * 100.0 / sum).round() as usize;
208-
self.h09 = (self.h09 as f64 * 100.0 / sum).round() as usize;
209-
self.h10 = (self.h10 as f64 * 100.0 / sum).round() as usize;
210-
self.h11 = (self.h11 as f64 * 100.0 / sum).round() as usize;
211-
self.h12 = (self.h12 as f64 * 100.0 / sum).round() as usize;
212-
self.h13 = (self.h13 as f64 * 100.0 / sum).round() as usize;
213-
self.h14 = (self.h14 as f64 * 100.0 / sum).round() as usize;
214-
self.h15 = (self.h15 as f64 * 100.0 / sum).round() as usize;
215-
self.h16 = (self.h16 as f64 * 100.0 / sum).round() as usize;
216-
self.h17 = (self.h17 as f64 * 100.0 / sum).round() as usize;
217-
self.h18 = (self.h18 as f64 * 100.0 / sum).round() as usize;
218-
self.h19 = (self.h19 as f64 * 100.0 / sum).round() as usize;
219-
self.h20 = (self.h20 as f64 * 100.0 / sum).round() as usize;
220-
self.h21 = (self.h21 as f64 * 100.0 / sum).round() as usize;
221-
self.h22 = (self.h22 as f64 * 100.0 / sum).round() as usize;
222-
self.h23 = (self.h23 as f64 * 100.0 / sum).round() as usize;
199+
self.h00 = (self.h00 as f64 * 100.0 / sum).round() as u64;
200+
self.h01 = (self.h01 as f64 * 100.0 / sum).round() as u64;
201+
self.h02 = (self.h02 as f64 * 100.0 / sum).round() as u64;
202+
self.h03 = (self.h03 as f64 * 100.0 / sum).round() as u64;
203+
self.h04 = (self.h04 as f64 * 100.0 / sum).round() as u64;
204+
self.h05 = (self.h05 as f64 * 100.0 / sum).round() as u64;
205+
self.h06 = (self.h06 as f64 * 100.0 / sum).round() as u64;
206+
self.h07 = (self.h07 as f64 * 100.0 / sum).round() as u64;
207+
self.h08 = (self.h08 as f64 * 100.0 / sum).round() as u64;
208+
self.h09 = (self.h09 as f64 * 100.0 / sum).round() as u64;
209+
self.h10 = (self.h10 as f64 * 100.0 / sum).round() as u64;
210+
self.h11 = (self.h11 as f64 * 100.0 / sum).round() as u64;
211+
self.h12 = (self.h12 as f64 * 100.0 / sum).round() as u64;
212+
self.h13 = (self.h13 as f64 * 100.0 / sum).round() as u64;
213+
self.h14 = (self.h14 as f64 * 100.0 / sum).round() as u64;
214+
self.h15 = (self.h15 as f64 * 100.0 / sum).round() as u64;
215+
self.h16 = (self.h16 as f64 * 100.0 / sum).round() as u64;
216+
self.h17 = (self.h17 as f64 * 100.0 / sum).round() as u64;
217+
self.h18 = (self.h18 as f64 * 100.0 / sum).round() as u64;
218+
self.h19 = (self.h19 as f64 * 100.0 / sum).round() as u64;
219+
self.h20 = (self.h20 as f64 * 100.0 / sum).round() as u64;
220+
self.h21 = (self.h21 as f64 * 100.0 / sum).round() as u64;
221+
self.h22 = (self.h22 as f64 * 100.0 / sum).round() as u64;
222+
self.h23 = (self.h23 as f64 * 100.0 / sum).round() as u64;
223223
}
224224

225225
/// Converts `hxx` values from the number of commits to percentage.
@@ -258,7 +258,7 @@ impl CommitTimeHistoHours {
258258
}
259259

260260
/// Returns the sum of all `hxx` members.
261-
fn sum(&self) -> usize {
261+
fn sum(&self) -> u64 {
262262
self.h00
263263
+ self.h01
264264
+ self.h02
@@ -289,13 +289,13 @@ impl CommitTimeHistoHours {
289289
/// Only commit hours above the standard deviation (std) are included.
290290
fn overlap(&self, std: f64) -> Self {
291291
// copy the commit counts into an array for easy referencing in a loop
292-
let commit_counts: [usize; 24] = [
292+
let commit_counts: [u64; 24] = [
293293
self.h00, self.h01, self.h02, self.h03, self.h04, self.h05, self.h06, self.h07, self.h08, self.h09,
294294
self.h10, self.h11, self.h12, self.h13, self.h14, self.h15, self.h16, self.h17, self.h18, self.h19,
295295
self.h20, self.h21, self.h22, self.h23,
296296
];
297297

298-
let mut tz_overlap: [usize; 24] = [0; 24];
298+
let mut tz_overlap: [u64; 24] = [0; 24];
299299

300300
// populate an array for all possible timezones with the number of overlapping hours
301301
for tz in 0..23 {
@@ -315,7 +315,7 @@ impl CommitTimeHistoHours {
315315
0
316316
}
317317
})
318-
.sum::<usize>();
318+
.sum::<u64>();
319319
}
320320

321321
Self {

stackmuncher_lib/src/report/kwc.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub struct KeywordCounter {
1010
#[serde(skip_serializing_if = "Option::is_none")]
1111
pub t: Option<HashSet<String>>,
1212
/// count
13-
pub c: usize,
13+
pub c: u64,
1414
}
1515

1616
pub(crate) trait KeywordCounterSet {
@@ -67,7 +67,7 @@ impl KeywordCounterSet for HashSet<KeywordCounter> {
6767

6868
impl KeywordCounter {
6969
/// Returns Self with `t` as `None`. Panics if `keyword` is empty.
70-
pub(crate) fn new_keyword(keyword: String, count: usize) -> Self {
70+
pub(crate) fn new_keyword(keyword: String, count: u64) -> Self {
7171
if keyword.is_empty() {
7272
error!("Empty keyword for KeywordCounter in new_keyword");
7373
}
@@ -80,7 +80,7 @@ impl KeywordCounter {
8080
}
8181

8282
/// Splits `keyword` into `k` and `t`. Panics if `keyword` is empty.
83-
pub(crate) fn new_ref(keyword: String, count: usize) -> Self {
83+
pub(crate) fn new_ref(keyword: String, count: u64) -> Self {
8484
if keyword.is_empty() {
8585
error!("Empty keyword for KeywordCounter in new_ref");
8686
}

0 commit comments

Comments
 (0)