pub struct MutItem { /* private fields */ }Expand description
たとえばキャラクターAとキャラクターBの間で出来事Cが起こったとする。 キャラクターAのIDをa, BのIDをbとする。 グローバルの出来事リストに出来事Cを記録し、next_idからidを振り、そのidをcとする。その出来事のオブジェクトにはaとbもvaluesに記録されている。 AのRelationリストのID bの項目にアクセスし、なければ作成し、insertする。 AのRelationリストbにある出来事ID保持用のlistに出来事ID cを記憶しておく。ID保持用のlistは、idだけで中身のないオブジェクトを集めたlistだ。 同様にキャラクターBのRelationリストaの出来事リストにも、出来事ID cを記録。 これにより、たとえば出来事Cを削除したい場合、Cにあるaとbを読み、AのbにあるID cのものを削除、 Bのaにあるcも削除、さらに出来事リストからCも削除すると、全部消える。 AとBとの間で何があったかの一覧がほしいなら、Aのbにアクセスし、出来事IDリストを取得、出来事リストからid検索し、出来事を取得、という感じになる。 出来事リストのIDはnext_id方式により、時系列に積み上がっていくため、何年何月に起きた出来事はID x から y という情報があれば、 その間の出来事を全部調べたり、一定期間が過ぎた出来事データのうち重要じゃないものは消す、といった処理もできる。 キャラクターBを削除したい場合、他のキャラクターのRelationリストのbの部分を全部消し、BのRelationリストから取れる出来事IDを全部調べて 出来事リストから全部消す、といった感じで消していくことが可能だ。
こういったユースケース(あるのか?)のためにLinkedHashM(u64,MutListItem)を使うとRelationを効率的に処理できるだろう。 あるいはBTreeMap(index_value, u64)でindex_valueでソートされたMapを作り、「index_valueがAからBの間にあるアイテム」といった条件で検索が可能になる。 そういったシステムを、出来事リストを読み出して外部にRelationを構築したり、パラメータをindex-keyとしてBTreeを構築したりすることで (パラメータは上書きされうるので、その場合(item_id, BTreeのid)のRelationも使って、上書き時にBTreeをアップデートできるようにしておく必要もあり大変だが) Relationとパラメータ範囲での検索が効率的にできるシステムが作れる。ただそれは外部に作ればいいので、このシステム自体の守備範囲ではない それが出来る土台として、idとLinkedHashMで出来たMutListがある
Implementations§
Source§impl MutItem
impl MutItem
pub fn new( values: HashM<String, ListSabValue>, refs: HashM<String, RefSabValue>, ) -> MutItem
pub fn muts( &mut self, ) -> (&mut HashM<String, ListSabValue>, &mut HashM<String, RefSabValue>)
pub fn construct( values: Arc<HashM<String, ListSabValue>>, refs: Arc<HashM<String, RefSabValue>>, ) -> MutItem
pub fn values(&self) -> &HashM<String, ListSabValue>
pub fn values_mut(&mut self) -> &mut HashM<String, ListSabValue>
pub fn refs(&self) -> &HashM<String, RefSabValue>
pub fn refs_mut(&mut self) -> &mut HashM<String, RefSabValue>
Trait Implementations§
Source§impl IdentityEqual for MutItem
impl IdentityEqual for MutItem
fn identity_eq(&self, other: &Self) -> bool
impl StructuralPartialEq for MutItem
Auto Trait Implementations§
impl Freeze for MutItem
impl RefUnwindSafe for MutItem
impl Send for MutItem
impl Sync for MutItem
impl Unpin for MutItem
impl UnwindSafe for MutItem
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