pub struct RefIDSet<R> { /* private fields */ }
Expand description

Data structure for interning sequence names efficiently.

The structure is parameterized over the reference type R used to intern strings. Typically, this would be Rc for single-threaded access or Arc for multi-threaded access. These reference types provide fast, reference-counted cloning with no new allocation, which can make sequence location calculations faster as well as reducing the memory footprint required.

use std::rc::Rc;
use bio_types::strand::ReqStrand;
use bio_types::annot::contig::Contig;
use bio_types::annot::loc::Loc;
use bio_types::annot::refids::RefIDSet;
let mut refids: RefIDSet<Rc<String>> = RefIDSet::new();
let pau8 = Contig::new(refids.intern("chrI"), 1807, 2170 - 1807, ReqStrand::Reverse);
{
  let chr_i = refids.intern("chrI");
  // One reference for the RefIDSet itself, one for the pau8 Contig, one for chr_i
  assert_eq!(Rc::strong_count(&chr_i), 3);
}
let seo1 = Contig::new(refids.intern("chrI"), 7235, 9017 - 7235, ReqStrand::Reverse);
let tda8 = Contig::new(refids.intern("chrI"), 13363, 13744 - 13363, ReqStrand::Reverse);
{
  let chr_i = refids.intern("chrI");
  assert_eq!(Rc::strong_count(&chr_i), 5);
}
let seo1_beginning = seo1.first_pos();
let seo1_ending = seo1.last_pos();
{
  let chr_i = refids.intern("chrI");
  assert_eq!(Rc::strong_count(&chr_i), 7);
}

Implementations§

source§

impl<R> RefIDSet<R>

source

pub fn new() -> Self

Create a new, empty table of interned reference names

source

pub fn intern(&mut self, id: &str) -> Rwhere R: Deref<Target = String> + From<String> + Clone,

Intern a reference name.

This returns a shared reference of type R for the name. This reference will be shared with any other intern calls for the same name. The name is given originally as a reference, and it will be cloned into an owned String only when the name is new for the data type.

Trait Implementations§

source§

impl<R> Default for RefIDSet<R>

source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<R> RefUnwindSafe for RefIDSet<R>where R: RefUnwindSafe,

§

impl<R> Send for RefIDSet<R>where R: Send,

§

impl<R> Sync for RefIDSet<R>where R: Sync,

§

impl<R> Unpin for RefIDSet<R>where R: Unpin,

§

impl<R> UnwindSafe for RefIDSet<R>where R: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.