@@ -89,7 +89,7 @@ pub struct Segment {
8989impl Segment {
9090 #[ allow( clippy:: len_without_is_empty) ]
9191 pub fn len ( & self ) -> usize {
92- self . seq . len ( )
92+ self . seq . len as usize
9393 }
9494}
9595
@@ -423,34 +423,29 @@ pub struct SeqSpan {
423423 /// The logical index of the first element of the sequence
424424 pub start : u32 ,
425425
426- /// One greater than the logical index of the final element of the sequence
427- pub end : u32 ,
426+ /// The length of the sequence
427+ pub len : u16 ,
428428}
429429
430430impl SeqSpan {
431- // Returns the length of this SeqSpan
432- pub fn len ( & self ) -> usize {
433- ( self . end - self . start ) as usize
434- }
435-
436431 /// Returns true if this SeqSpan is empty, else return false
437432 pub fn is_empty ( & self ) -> bool {
438- self . len ( ) == 0
433+ self . len == 0
439434 }
440435
441436 /// Given `range`, returns the equivalent SeqSpan
442437 pub fn from_range ( range : Range < usize > ) -> Self {
443438 Self {
444439 start : range. start as u32 ,
445- end : range. end as u32 ,
440+ len : ( range. end - range . start ) as u16 ,
446441 }
447442 }
448443
449444 /// Returns the range that is equivalent to this SeqSpan
450445 pub fn to_range ( & self ) -> Range < usize > {
451446 Range {
452447 start : self . start as usize ,
453- end : self . end as usize ,
448+ end : self . end ( ) as usize ,
454449 }
455450 }
456451
@@ -466,7 +461,7 @@ impl SeqSpan {
466461
467462 // Returns the index one greater than the end byte index
468463 pub fn end_byte_index ( & self ) -> usize {
469- self . end . div_ceil ( 2 ) as usize
464+ self . end ( ) . div_ceil ( 2 ) as usize
470465 }
471466
472467 // Returns the nibble offset of the beginning of the sequence
@@ -476,7 +471,13 @@ impl SeqSpan {
476471
477472 // Returns the nibble offset of the ending of the sequence
478473 pub fn get_nibble_end ( & self ) -> bool {
479- ( self . end % 2 ) != 1
474+ ( self . end ( ) % 2 ) != 1
475+ }
476+ pub fn len_from_end ( & self , end : usize ) -> u16 {
477+ ( ( end as u32 ) - self . start ) as u16
478+ }
479+ pub fn end ( & self ) -> usize {
480+ ( self . start as usize ) + ( self . len as usize )
480481 }
481482}
482483
@@ -512,7 +513,10 @@ impl<'a, P: StoreFamily<'a>> GFAStore<'a, P> {
512513 let end = SeqSpan :: to_logical ( byte_span. end . index ( ) - 1 , end_offset) + 1 ;
513514 self . segs . add ( Segment {
514515 name,
515- seq : SeqSpan { start, end } ,
516+ seq : SeqSpan {
517+ start,
518+ len : ( end - start) as u16 ,
519+ } ,
516520 optional : self . optional_data . add_slice ( optional) ,
517521 } )
518522 }
@@ -529,7 +533,10 @@ impl<'a, P: StoreFamily<'a>> GFAStore<'a, P> {
529533 let end = SeqSpan :: to_logical ( byte_span. end . index ( ) - 1 , seq. high_nibble_end ) + 1 ;
530534 self . segs . add ( Segment {
531535 name,
532- seq : SeqSpan { start, end } ,
536+ seq : SeqSpan {
537+ start,
538+ len : ( end - start) as u16 ,
539+ } ,
533540 optional : self . optional_data . add_slice ( optional) ,
534541 } )
535542 }
0 commit comments