Struct bookdata::ids::index::IdIndex

source ·
pub struct IdIndex<K> {
    map: HashMap<K, i32>,
    frozen: bool,
}
Expand description

Index identifiers from a data type

Fields§

§map: HashMap<K, i32>§frozen: bool

Implementations§

source§

impl<K> IdIndex<K>
where K: Eq + Hash,

source

pub fn new() -> IdIndex<K>

Create a new index.

source

pub fn freeze(self) -> IdIndex<K>

Freeze the index so no new items can be added.

source

pub fn len(&self) -> usize

Get the index length

source

pub fn intern<Q>(&mut self, key: &Q) -> Result<i32, IndexError>
where K: Borrow<Q>, Q: Hash + Eq + ToOwned<Owned = K> + ?Sized,

Get the ID for a key, adding it to the index if needed.

source

pub fn intern_owned(&mut self, key: K) -> Result<i32, IndexError>

Get the ID for a key, adding it to the index if needed and transferring ownership.

source

pub fn lookup<Q>(&self, key: &Q) -> Option<i32>
where K: Borrow<Q>, Q: Hash + Eq + ?Sized,

Look up the ID for a key if it is present.

source

pub fn keys(&self) -> Keys<'_, K, i32>

Iterate over keys (see std::collections::HashMap::keys).

source§

impl IdIndex<String>

source

pub fn key_vec(&self) -> Vec<&str>

Get the keys in order.

source

pub fn data_frame( &self, id_col: &str, key_col: &str ) -> Result<DataFrame, PolarsError>

Conver this ID index into a DataFrame, with columns for ID and key.

source

pub fn load_standard<P: AsRef<Path>>(path: P) -> Result<IdIndex<String>>

Load from a Parquet file, with a standard configuration.

This assumes the Parquet file has the following columns:

  • key, of type String, storing the keys
  • id, of type i32, storing the IDs
source

pub fn load<P: AsRef<Path>>( path: P, id_col: &str, key_col: &str ) -> Result<IdIndex<String>>

Load from a Parquet file.

This loads two columns from a Parquet file. The ID column is expected to have type UInt32 (or a type projectable to it), and the key column should be Utf8.

source

pub fn load_csv<P: AsRef<Path>, K: Eq + Hash + DeserializeOwned>( path: P ) -> Result<IdIndex<K>>

Load an index from a CSV file.

This loads an index from a CSV file. It assumes the first column is the ID, and the second column is the key.

source

pub fn save_standard<P: AsRef<Path>>(&self, path: P) -> Result<()>

Save to a Parquet file with the standard configuration.

source

pub fn save<P: AsRef<Path>>( &self, path: P, id_col: &str, key_col: &str ) -> Result<()>

Save to a Parquet file with the standard configuration.

Auto Trait Implementations§

§

impl<K> RefUnwindSafe for IdIndex<K>
where K: RefUnwindSafe,

§

impl<K> Send for IdIndex<K>
where K: Send,

§

impl<K> Sync for IdIndex<K>
where K: Sync,

§

impl<K> Unpin for IdIndex<K>
where K: Unpin,

§

impl<K> UnwindSafe for IdIndex<K>
where K: UnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where 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 T
where 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> IntoResult<T> for T

§

type Err = Infallible

source§

fn into_result(self) -> Result<T, <T as IntoResult<T>>::Err>

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where 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 T
where 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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V