@@ -21,7 +21,7 @@ pub use iterator::Iterator;
2121/// assert_eq!(flat_tree::index(3, 1), 23);
2222/// ```
2323#[ inline]
24- pub const fn index ( depth : usize , offset : usize ) -> usize {
24+ pub const fn index ( depth : u64 , offset : u64 ) -> u64 {
2525 ( offset << ( depth + 1 ) ) | ( ( 1 << depth) - 1 )
2626}
2727
@@ -36,9 +36,9 @@ pub const fn index(depth: usize, offset: usize) -> usize {
3636/// assert_eq!(flat_tree::depth(4), 0);
3737/// ```
3838#[ inline]
39- pub const fn depth ( i : usize ) -> usize {
39+ pub const fn depth ( i : u64 ) -> u64 {
4040 // Count trailing `1`s of the binary representation of the number.
41- ( !i) . trailing_zeros ( ) as usize
41+ ( !i) . trailing_zeros ( ) as u64
4242}
4343
4444/// Returns the offset of a node.
@@ -52,7 +52,7 @@ pub const fn depth(i: usize) -> usize {
5252/// assert_eq!(flat_tree::offset(4), 2);
5353/// ```
5454#[ inline]
55- pub fn offset ( i : usize ) -> usize {
55+ pub fn offset ( i : u64 ) -> u64 {
5656 let depth = self :: depth ( i) ;
5757 if is_even ( i) {
5858 i / 2
@@ -72,7 +72,7 @@ pub fn offset(i: usize) -> usize {
7272/// assert_eq!(flat_tree::parent(4), 5);
7373/// ```
7474#[ inline]
75- pub fn parent ( i : usize ) -> usize {
75+ pub fn parent ( i : u64 ) -> u64 {
7676 let depth = self :: depth ( i) ;
7777 index ( depth + 1 , offset ( i) >> 1 )
7878}
@@ -87,7 +87,7 @@ pub fn parent(i: usize) -> usize {
8787/// assert_eq!(flat_tree::sibling(5), 1);
8888/// ```
8989#[ inline]
90- pub fn sibling ( i : usize ) -> usize {
90+ pub fn sibling ( i : u64 ) -> u64 {
9191 let depth = self :: depth ( i) ;
9292 index ( depth, offset ( i) ^ 1 )
9393}
@@ -102,7 +102,7 @@ pub fn sibling(i: usize) -> usize {
102102/// assert_eq!(flat_tree::uncle(5), 11);
103103/// ```
104104#[ inline]
105- pub fn uncle ( i : usize ) -> usize {
105+ pub fn uncle ( i : u64 ) -> u64 {
106106 let depth = self :: depth ( i) ;
107107 index ( depth + 1 , offset ( parent ( i) ) ^ 1 )
108108}
@@ -117,7 +117,7 @@ pub fn uncle(i: usize) -> usize {
117117/// assert_eq!(flat_tree::children(9), Some((8, 10)));
118118/// ```
119119#[ inline]
120- pub fn children ( i : usize ) -> Option < ( usize , usize ) > {
120+ pub fn children ( i : u64 ) -> Option < ( u64 , u64 ) > {
121121 let depth = self :: depth ( i) ;
122122 if is_even ( i) {
123123 None
@@ -138,7 +138,7 @@ pub fn children(i: usize) -> Option<(usize, usize)> {
138138/// assert_eq!(flat_tree::left_child(3), Some(1));
139139/// ```
140140#[ inline]
141- pub fn left_child ( i : usize ) -> Option < usize > {
141+ pub fn left_child ( i : u64 ) -> Option < u64 > {
142142 let depth = self :: depth ( i) ;
143143 if is_even ( i) {
144144 None
@@ -159,7 +159,7 @@ pub fn left_child(i: usize) -> Option<usize> {
159159/// ```
160160// TODO: handle errors
161161#[ inline]
162- pub fn right_child ( i : usize ) -> Option < usize > {
162+ pub fn right_child ( i : u64 ) -> Option < u64 > {
163163 let depth = self :: depth ( i) ;
164164 if is_even ( i) {
165165 None
@@ -181,7 +181,7 @@ pub fn right_child(i: usize) -> Option<usize> {
181181/// assert_eq!(flat_tree::right_span(27), 30);
182182/// ```
183183#[ inline]
184- pub fn right_span ( i : usize ) -> usize {
184+ pub fn right_span ( i : u64 ) -> u64 {
185185 let depth = self :: depth ( i) ;
186186 if depth == 0 {
187187 i
@@ -201,7 +201,7 @@ pub fn right_span(i: usize) -> usize {
201201/// assert_eq!(flat_tree::left_span(27), 24);
202202/// ```
203203#[ inline]
204- pub fn left_span ( i : usize ) -> usize {
204+ pub fn left_span ( i : u64 ) -> u64 {
205205 let depth = self :: depth ( i) ;
206206 if depth == 0 {
207207 i
@@ -221,7 +221,7 @@ pub fn left_span(i: usize) -> usize {
221221/// assert_eq!(flat_tree::spans(27), (24, 30));
222222/// ```
223223#[ inline]
224- pub fn spans ( i : usize ) -> ( usize , usize ) {
224+ pub fn spans ( i : u64 ) -> ( u64 , u64 ) {
225225 ( left_span ( i) , right_span ( i) )
226226}
227227
@@ -237,7 +237,7 @@ pub fn spans(i: usize) -> (usize, usize) {
237237/// assert_eq!(flat_tree::count(27), 7);
238238/// ```
239239#[ inline]
240- pub const fn count ( i : usize ) -> usize {
240+ pub const fn count ( i : u64 ) -> u64 {
241241 let depth = self :: depth ( i) ;
242242 ( 2 << depth) - 1
243243}
@@ -281,7 +281,7 @@ pub const fn count(i: usize) -> usize {
281281/// assert_eq!(nodes, [7]);
282282/// ```
283283#[ inline]
284- pub fn full_roots ( i : usize , nodes : & mut Vec < usize > ) {
284+ pub fn full_roots ( i : u64 , nodes : & mut Vec < u64 > ) {
285285 assert ! (
286286 is_even( i) ,
287287 format!(
@@ -308,12 +308,12 @@ pub fn full_roots(i: usize, nodes: &mut Vec<usize>) {
308308}
309309
310310#[ inline]
311- pub ( crate ) const fn is_even ( num : usize ) -> bool {
311+ pub ( crate ) const fn is_even ( num : u64 ) -> bool {
312312 ( num & 1 ) == 0
313313}
314314
315315#[ inline]
316- pub ( crate ) const fn is_odd ( num : usize ) -> bool {
316+ pub ( crate ) const fn is_odd ( num : u64 ) -> bool {
317317 ( num & 1 ) != 0
318318}
319319
0 commit comments