Skip to content

Commit 2c72c7e

Browse files
committed
simplifie the OIDs structure
1 parent ebd1511 commit 2c72c7e

1 file changed

Lines changed: 15 additions & 21 deletions

File tree

asyncgit/src/graph/oids.rs

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,34 @@
11
use crate::sync::CommitId;
22
use std::collections::HashMap;
33

4-
pub struct Oids {
5-
/// alias
6-
pub ids: Vec<CommitId>,
4+
/// mapping of `CommitId` to a numeric alias
5+
pub struct GraphOids(HashMap<CommitId, usize>);
76

8-
/// `CommitId` to alias
9-
pub aliases: HashMap<CommitId, u32>,
10-
}
11-
12-
impl Default for Oids {
7+
impl Default for GraphOids {
138
fn default() -> Self {
149
Self::new()
1510
}
1611
}
1712

18-
impl Oids {
13+
impl GraphOids {
14+
///
1915
pub fn new() -> Self {
20-
Self {
21-
ids: Vec::new(),
22-
aliases: HashMap::new(),
23-
}
16+
Self(HashMap::new())
2417
}
2518

26-
pub fn get_or_insert(&mut self, id: &CommitId) -> u32 {
27-
if let Some(&alias) = self.aliases.get(id) {
19+
///
20+
pub fn get_or_insert(&mut self, id: &CommitId) -> usize {
21+
if let Some(&alias) = self.0.get(id) {
2822
return alias;
2923
}
30-
let alias =
31-
u32::try_from(self.ids.len()).expect("too many oids");
32-
self.ids.push(*id);
33-
self.aliases.insert(*id, alias);
24+
25+
let alias = self.0.len();
26+
self.0.insert(*id, alias);
3427
alias
3528
}
3629

37-
pub fn get(&self, id: &CommitId) -> Option<u32> {
38-
self.aliases.get(id).copied()
30+
///
31+
pub fn get(&self, id: &CommitId) -> Option<usize> {
32+
self.0.get(id).copied()
3933
}
4034
}

0 commit comments

Comments
 (0)