[][src]Struct dary::double_array::DoubleArray

pub struct DoubleArray<T: Serialize + DeserializeOwned + Debug> { /* fields omitted */ }

ダブル配列の実装。

Examples

use std::fmt::Debug;
use dary::DoubleArray;
use dary::Trie;
use serde_derive::{Serialize, Deserialize};
 
fn main() {
  let key1 = String::from("foo");
  let key2 = String::from("bar");
  let key3 = String::from("baz");
 
  let sample1 = Sample { surface: key1.clone(), cost: 1 };
  let sample2 = Sample { surface: key1.clone(), cost: 2 };
  let sample3 = Sample { surface: key2.clone(), cost: 1 };
  let sample4 = Sample { surface: key3.clone(), cost: 1 };
 
  let mut trie: Trie<Sample> = Trie::new();
  trie.set(&key1, sample1.clone());
  trie.set(&key1, sample2.clone());
  trie.set(&key2, sample3.clone());
  trie.set(&key3, sample4.clone());
 
  let double_array = trie.to_double_array().ok().unwrap();
  assert_eq!(vec![sample1, sample2], double_array.get(&key1).unwrap());
  assert_eq!(vec![sample3]         , double_array.get(&key2).unwrap());
  assert_eq!(vec![sample4]         , double_array.get(&key3).unwrap());
}
 
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
struct Sample {
    surface: String,
    cost: usize,
}

Methods

impl<T: Serialize + DeserializeOwned + Debug> DoubleArray<T>[src]

pub fn from_arrays(
    base_arr: &[u32],
    check_arr: &[u32],
    data_bytes: &[u8]
) -> Result<Self, Error>
[src]

base配列, check配列, data配列からDoubleArrayインスタンスを生成する。

Arguments

  • base_arr - base配列
  • check_arr - check配列
  • data_bytes - data配列

pub fn from_slice(bytes: &[u8]) -> Result<Self, Error>[src]

u8の配列からDoubleArrayインスタンスを生成する。

Arguments

  • bytes - base配列, check配列, data配列を u8 の配列として連結させた配列

pub fn from_file(dictionary_path: &str) -> Result<Self, Error>[src]

ファイルからDoubleArrayインスタンスを生成する。

Arguments

  • dictionary_path - 辞書ファイルパス

pub fn dump(self, output_path: &str) -> Result<Self, Error>[src]

DoubleArrayをファイルにダンプする

Arguments

  • output_path - 辞書ファイルパス

pub fn get(&self, key: &str) -> Option<Vec<T>>[src]

ダブル配列から指定されたkeyを探索する関数 途中で遷移できなくなった場合、data_arrに値が存在しない場合はNoneを返す 遷移ができて、data_arrに値が存在する場合はdata_arrのスライスを返す デバッグ用

Arguments

  • key - 探索対象の文字列

ダブル配列で共通接頭辞検索を行う デバッグ用

Arguments

  • key - 探索対象の文字列

Important traits for PrefixSearchIter<'a, T>
pub fn prefix_search_iter<'a>(&'a self, key: &'a str) -> PrefixSearchIter<'a, T>[src]

Trait Implementations

impl<T: Debug + Serialize + DeserializeOwned> Debug for DoubleArray<T>[src]

Auto Trait Implementations

impl<T> Send for DoubleArray<T> where
    T: Send

impl<T> Sync for DoubleArray<T> where
    T: Sync

impl<T> Unpin for DoubleArray<T> where
    T: Unpin

impl<T> UnwindSafe for DoubleArray<T> where
    T: UnwindSafe

impl<T> RefUnwindSafe for DoubleArray<T> where
    T: RefUnwindSafe

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

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