bookdata::ids::index

Struct 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> Freeze for IdIndex<K>

§

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

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize = _

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

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

Initializes a with the given initializer. Read more
Source§

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

Dereferences the given pointer. Read more
Source§

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

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

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

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

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>,

Source§

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.
Source§

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

Source§

fn vzip(self) -> V

Source§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,