pub struct PinyinData { /* private fields */ }
pinyin
only.Expand description
§Memory usage
Per pinyin notation: 8 * 1514 ≈ 11.8 KiB.
Unicode
does not require extra memory.AsciiFirstLetter
uses the same storage asAscii
.
§Others
TODO: Optionally generate pinyin notation data at build time.
Less flexible at runtime.
TODO: Is row-major order more cache friendly?
Row-major order requires 7 * 8 * 1514 ≈ 83 KiB, dynamic columns are needed to reduce memory usage. And dynamic columns can also offer better cache locality.
TODO: Order pinyin by frequency to improve cache locality?
Implementations§
Source§impl PinyinData
impl PinyinData
pub fn new(notations: PinyinNotation) -> Self
pub fn init_notations(&self, notations: PinyinNotation)
inmut-data
only.pub fn inited_notations(&self) -> PinyinNotation
pub fn iter(&self) -> impl Iterator<Item = Pinyin<'_>>
Sourcepub fn get_pinyins<'a>(
&'a self,
c: char,
) -> Box<dyn Iterator<Item = Pinyin<'a>> + 'a>
pub fn get_pinyins<'a>( &'a self, c: char, ) -> Box<dyn Iterator<Item = Pinyin<'a>> + 'a>
Prefer PinyinData::get_pinyins_and_for_each
and PinyinData::get_pinyins_and_try_for_each
if applicable.
§Performance
Do not use this method in performance-critical code. The Box
wouldn’t be optimized away even with #[inline(always)]
.
pub fn get_pinyins_and_for_each(&self, c: char, f: impl FnMut(Pinyin<'_>))
pub fn get_pinyins_and_try_for_each<T>( &self, c: char, f: impl FnMut(Pinyin<'_>) -> Option<T>, ) -> Option<T>
Sourcepub fn match_pinyin<'a: 'h, 'h>(
&'a self,
notation: PinyinNotation,
haystack: &'h str,
) -> impl Iterator<Item = &'a str> + 'h
pub fn match_pinyin<'a: 'h, 'h>( &'a self, notation: PinyinNotation, haystack: &'h str, ) -> impl Iterator<Item = &'a str> + 'h
Match pinyin of the given notation in haystack.
Sourcepub fn match_pinyin_partial<'a: 'h, 'h>(
&'a self,
notation: PinyinNotation,
haystack: &'h str,
partial: bool,
) -> impl Iterator<Item = (&'a str, bool)> + 'h
pub fn match_pinyin_partial<'a: 'h, 'h>( &'a self, notation: PinyinNotation, haystack: &'h str, partial: bool, ) -> impl Iterator<Item = (&'a str, bool)> + 'h
Match pinyin of the given notation in haystack, optionally allowing partial matches.
§Returns
(pinyin, partial)
- If
partial
istrue
,haystack.len() < pinyin.len()
.
Trait Implementations§
Source§impl Clone for PinyinData
impl Clone for PinyinData
Source§fn clone(&self) -> PinyinData
fn clone(&self) -> PinyinData
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreAuto Trait Implementations§
impl !Freeze for PinyinData
impl RefUnwindSafe for PinyinData
impl Send for PinyinData
impl Sync for PinyinData
impl Unpin for PinyinData
impl UnwindSafe for PinyinData
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more