@@ -7,19 +7,21 @@ use crate::errors::{Error, ErrorKind, TaxonomyResult};
7
7
use crate :: rank:: TaxRank ;
8
8
use crate :: taxonomy:: Taxonomy ;
9
9
10
+ pub type InternalIndex = usize ;
11
+
10
12
#[ derive( Clone , Debug , Deserialize , Serialize , PartialEq ) ]
11
13
pub struct GeneralTaxonomy {
12
14
pub tax_ids : Vec < String > ,
13
- pub parent_ids : Vec < usize > ,
15
+ pub parent_ids : Vec < InternalIndex > ,
14
16
pub parent_distances : Vec < f32 > ,
15
17
pub names : Vec < String > ,
16
18
pub ranks : Vec < TaxRank > ,
17
19
// Only used by the JSON format
18
20
pub data : Vec < HashMap < String , Value > > ,
19
21
20
22
// these are lookup tables that dramatically speed up some operations
21
- pub ( crate ) tax_id_lookup : HashMap < String , usize > ,
22
- pub ( crate ) children_lookup : Vec < Vec < usize > > ,
23
+ pub ( crate ) tax_id_lookup : HashMap < String , InternalIndex > ,
24
+ pub ( crate ) children_lookup : Vec < Vec < InternalIndex > > ,
23
25
}
24
26
25
27
impl Default for GeneralTaxonomy {
@@ -104,15 +106,15 @@ impl GeneralTaxonomy {
104
106
}
105
107
106
108
#[ inline]
107
- pub ( crate ) fn to_internal_index ( & self , tax_id : & str ) -> TaxonomyResult < usize > {
109
+ pub fn to_internal_index ( & self , tax_id : & str ) -> TaxonomyResult < InternalIndex > {
108
110
self . tax_id_lookup . get ( tax_id) . map_or_else (
109
111
|| Err ( Error :: new ( ErrorKind :: NoSuchTaxId ( tax_id. to_owned ( ) ) ) ) ,
110
112
|t| Ok ( * t) ,
111
113
)
112
114
}
113
115
114
116
#[ inline]
115
- pub fn from_internal_index ( & self , tax_id : usize ) -> TaxonomyResult < & str > {
117
+ pub fn from_internal_index ( & self , tax_id : InternalIndex ) -> TaxonomyResult < & str > {
116
118
if tax_id >= self . tax_ids . len ( ) {
117
119
return Err ( Error :: new ( ErrorKind :: NoSuchTaxId ( format ! (
118
120
"Internal ID: {}" ,
@@ -124,7 +126,7 @@ impl GeneralTaxonomy {
124
126
125
127
pub fn from_arrays (
126
128
tax_ids : Vec < String > ,
127
- parent_ids : Vec < usize > ,
129
+ parent_ids : Vec < InternalIndex > ,
128
130
names : Option < Vec < String > > ,
129
131
ranks : Option < Vec < TaxRank > > ,
130
132
distances : Option < Vec < f32 > > ,
0 commit comments