Skip to main content

GraphMap

Struct GraphMap 

Source
pub struct GraphMap<N, E, S: MapState> { /* private fields */ }
Expand description

グラフベースの探索マップ

ノードとエッジでグラフ構造を表現する。 ExplorationMapGraphExplorationMap を実装。

§型パラメータ

  • N: ノードデータの型(課題 / Action / 状態 など)
  • E: エッジデータの型(アクション / 遷移情報 など)
  • S: 状態の型(MapState を実装)

§使用例

// 文字列をノードデータとするマップ
let mut map: GraphMap<String, String, MapNodeState> = GraphMap::new();

// ルートノードを作成
let root = map.create_root("start".to_string(), MapNodeState::Open);

// 子ノードを追加
let update = GraphMapUpdate::AddChild {
    parent: root,
    edge_data: "action-1".to_string(),
    node_data: "state-1".to_string(),
    node_state: MapNodeState::Open,
    dedup_key: "state-1".to_string(),
};
let result = map.apply(update);

Implementations§

Source§

impl<N, E, S: MapState> GraphMap<N, E, S>

Source

pub fn new() -> Self

空のマップを作成

Source

pub fn index_node<K, F>(&mut self, node_id: MapNodeId, key_fn: F)
where K: Hash, F: FnOnce(&N) -> K,

ノードをインデックスに登録

キー抽出関数でキーを取得し、ハッシュ値でインデックスに登録する。

Source

pub fn get_by_key<K: Hash>(&self, key: &K) -> Option<MapNodeId>

キーでノードを検索

インデックスを使って O(1) で検索。

Source

pub fn contains_key<K: Hash>(&self, key: &K) -> bool

キーが存在するか確認

Source

pub fn clear_index(&mut self)

インデックスをクリア

Source

pub fn rebuild_index<K, F>(&mut self, key_fn: F)
where K: Hash, F: Fn(&N) -> K,

インデックスを再構築

全ノードに対してキー抽出関数を適用し、インデックスを再構築する。

Source

pub fn find_node<F>(&self, predicate: F) -> Option<MapNodeId>
where F: Fn(&MapNode<N, S>) -> bool,

条件に一致する最初のノードを検索

O(n) の線形検索。頻繁に呼ぶ場合はインデックスを使う。

Source

pub fn find_nodes<F>(&self, predicate: F) -> Vec<MapNodeId>
where F: Fn(&MapNode<N, S>) -> bool,

条件に一致する全ノードを検索

Source

pub fn find_by_data(&self, data: &N) -> Option<MapNodeId>
where N: PartialEq,

データで検索(N: PartialEq の場合)

Source

pub fn find_by_state(&self, state: &S) -> Vec<MapNodeId>
where S: PartialEq,

状態で検索(S: PartialEq の場合)

指定した状態のノードを全て返す。 利用者が「Completed 状態のノード」「Failed 状態のノード」等を 取得するのに使う。

Source

pub fn find_nodes_by_state<F>(&self, predicate: F) -> Vec<MapNodeId>
where F: Fn(&S) -> bool,

状態の条件で検索

状態に対する任意の条件でノードを検索する。

Source

pub fn create_root_if_absent<K, F>( &mut self, data: N, state: S, key_fn: F, ) -> AddResult<MapNodeId>
where K: Hash, F: FnOnce(&N) -> K,

重複チェック付きルートノード作成

キーが既に存在する場合は既存ノードを返す。

Source

pub fn add_child_if_absent<K, F>( &mut self, parent: MapNodeId, edge_data: E, node_data: N, node_state: S, key_fn: F, ) -> MapResult<AddResult<MapNodeId>>
where K: Hash, F: FnOnce(&N) -> K,

重複チェック付きノード追加(親ノード指定)

キーが既に存在する場合は既存ノードを返す。 親ノードが見つからない場合はエラー。

Source

pub fn create_root(&mut self, data: N, state: S) -> MapNodeId

ルートノードを作成

Source

pub fn set_state(&mut self, id: MapNodeId, state: S)

ノードの状態を更新

状態変更時に expandables インデックスを自動更新する。

Source

pub fn add_nodes(&mut self, nodes: Vec<(N, S)>) -> Vec<MapNodeId>

複数ノードを一括追加

各 (data, state) ペアからノードを作成。 最初のノードがルートになり、以降は独立したノードとして追加。

Source

pub fn set_states(&mut self, ids: &[MapNodeId], state: S) -> Vec<MapNodeId>

複数ノードの状態を一括変更

Source

pub fn close_nodes(&mut self, ids: &[MapNodeId]) -> Vec<MapNodeId>

複数ノードを一括 Close(S::closed() を使用)

存在しないノード ID はスキップされる。 戻り値は実際に Close されたノード ID のリスト。

Source

pub fn cascade_down(&mut self, id: MapNodeId) -> Vec<MapNodeId>

下方向カスケード: 自身と全子孫を Close

戻り値は Close されたノード ID のリスト(指定ノード含む)。

Source

pub fn children(&self, node: MapNodeId) -> Vec<MapNodeId>

子ノード一覧を取得

Source

pub fn cascade_up_if_all_closed(&mut self, id: MapNodeId) -> Vec<MapNodeId>

上方向カスケード: 全子が is_closed() なら親を Close(再帰)

戻り値は Close されたノード ID のリスト。

Source

pub fn parent(&self, node: MapNodeId) -> Option<MapNodeId>

親ノードを取得

Source

pub fn close_with_cascade_up(&mut self, id: MapNodeId) -> Vec<MapNodeId>

状態変更 + 上方向カスケード

ノードを Close した後、親が Close 可能ならカスケード。 戻り値は Close されたノード ID のリスト(自身含む)。

Source

pub fn get_nodes(&self, ids: &[MapNodeId]) -> Vec<&MapNode<N, S>>

複数ノードを一括取得

存在しない ID はスキップされる。 順序は入力の順序を保持。

Source

pub fn get_node_data(&self, ids: &[MapNodeId]) -> Vec<&N>

複数ノードのデータを一括取得

存在しない ID はスキップされる。 ノード全体ではなくデータ部分のみが必要な場合に使用。

Source

pub fn expandables(&self) -> impl Iterator<Item = MapNodeId> + '_

展開可能なノード一覧(= expandables)

Source

pub fn expandables_count(&self) -> usize

展開可能なノード数

Source

pub fn closed_nodes(&self) -> Vec<MapNodeId>

Closed なノード一覧

Source

pub fn working_nodes(&self) -> Vec<MapNodeId>

作業中のノード一覧(!is_expandable && !is_closed)

フロンティアでも終了でもない中間状態のノード。 例: Processing, Pending など。

Source§

impl<N, E, S> GraphMap<N, E, S>
where N: Debug + Clone, E: Debug + Clone, S: MapState,

Source

pub fn apply_update<K, F>( &mut self, update: MapUpdate<N, E, S>, key_fn: F, ) -> MapUpdateResult
where K: Hash, F: Fn(&str) -> K,

MapUpdate を適用

Source

pub fn apply_updates<K, F>( &mut self, updates: Vec<MapUpdate<N, E, S>>, key_fn: F, ) -> Vec<MapUpdateResult>
where K: Hash + Clone, F: Fn(&str) -> K,

複数の MapUpdate を適用

Trait Implementations§

Source§

impl<N: Clone, E: Clone, S: Clone + MapState> Clone for GraphMap<N, E, S>

Source§

fn clone(&self) -> GraphMap<N, E, S>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<N: Debug, E: Debug, S: Debug + MapState> Debug for GraphMap<N, E, S>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<N, E, S: MapState> Default for GraphMap<N, E, S>

Source§

fn default() -> Self

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

impl<N, E, S> ExplorationMap for GraphMap<N, E, S>
where N: Debug + Clone, E: Debug + Clone, S: MapState,

Source§

type Node = MapNode<N, S>

ノードに持たせるデータ型
Source§

type Edge = MapEdge<E>

エッジに持たせるデータ型
Source§

type Update = GraphMapUpdate<N, E, S>

Tick 更新の入力型
Source§

type Result = MapApplyResult<N>

apply の結果型
Source§

fn apply(&mut self, update: Self::Update) -> Self::Result

更新を適用する(Tick の中心 API) Read more
Source§

fn get(&self, id: MapNodeId) -> Option<&Self::Node>

ノードを取得
Source§

fn get_mut(&mut self, id: MapNodeId) -> Option<&mut Self::Node>

ノードを変更可能で取得
Source§

fn node_count(&self) -> usize

ノード数
Source§

fn frontiers(&self) -> Vec<MapNodeId>

現在のフロンティア(Expandable なノード群)を取得 Read more
Source§

fn apply_batch(&mut self, updates: Vec<Self::Update>) -> Vec<Self::Result>

複数の更新をバッチ適用
Source§

impl<N, E, S> GraphExplorationMap for GraphMap<N, E, S>
where N: Debug + Clone, E: Debug + Clone, S: MapState,

Source§

fn get_edge(&self, id: MapEdgeId) -> Option<&Self::Edge>

エッジを取得
Source§

fn outgoing_edges(&self, node: MapNodeId) -> Vec<MapEdgeId>

ノードからの出ていくエッジを取得
Source§

fn incoming_edge(&self, node: MapNodeId) -> Option<MapEdgeId>

ノードに入ってくるエッジを取得(親エッジ)
Source§

fn edge_count(&self) -> usize

エッジ数
Source§

fn root(&self) -> Option<MapNodeId>

ルートノードを取得
Source§

impl<N, E, S> HierarchicalMap for GraphMap<N, E, S>
where N: Debug + Clone, E: Debug + Clone, S: MapState,

Source§

fn parent(&self, node: MapNodeId) -> Option<MapNodeId>

親ノードを取得
Source§

fn children(&self, node: MapNodeId) -> Vec<MapNodeId>

子ノード群を取得
Source§

fn depth(&self, node: MapNodeId) -> u32

ノードの深さを取得

Auto Trait Implementations§

§

impl<N, E, S> Freeze for GraphMap<N, E, S>

§

impl<N, E, S> RefUnwindSafe for GraphMap<N, E, S>

§

impl<N, E, S> Send for GraphMap<N, E, S>
where N: Send, S: Send, E: Send,

§

impl<N, E, S> Sync for GraphMap<N, E, S>
where N: Sync, S: Sync, E: Sync,

§

impl<N, E, S> Unpin for GraphMap<N, E, S>
where N: Unpin, S: Unpin, E: Unpin,

§

impl<N, E, S> UnwindSafe for GraphMap<N, E, S>
where N: UnwindSafe, S: UnwindSafe, E: 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more