File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11use crate :: sync:: CommitId ;
22use 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}
You can’t perform that action at this time.
0 commit comments