Add mutable IMap<K, V> stock implementation to windows-collections#4323
Add mutable IMap<K, V> stock implementation to windows-collections#4323
IMap<K, V> stock implementation to windows-collections#4323Conversation
Agent-Logs-Url: https://github.com/microsoft/windows-rs/sessions/910ca931-895f-48da-aab2-ac8539736ced Co-authored-by: kennykerr <9845234+kennykerr@users.noreply.github.com>
| V::Default: Clone, | ||
| { | ||
| fn First(&self) -> Result<IIterator<IKeyValuePair<K, V>>> { | ||
| let pairs: Vec<(K::Default, V::Default)> = self |
There was a problem hiding this comment.
@copilot The Vector implementation avoids the copy in its IIterable implementation. Is there a reason that is not possible here?
There was a problem hiding this comment.
Fixed in cbd0426. StockMapIterator now holds owner: ComObject<StockMap<K, V>> and an AtomicUsize current index — the same pattern as StockVectorIterator. First() no longer copies the map entries; iterator methods read directly from the owner's RwLock<BTreeMap> using map.iter().nth(current) / map.iter().skip(current).
| } | ||
|
|
||
| #[implement(IKeyValuePair<K, V>)] | ||
| struct StockMapKeyValuePair<K, V> |
There was a problem hiding this comment.
@copilot this looks like the same as the one used in map_view.rs - can they be shared?
There was a problem hiding this comment.
Done in c18cd21. The type is now defined once in a new key_value_pair.rs module as StockKeyValuePair, and both map.rs and map_view.rs reference it via super::key_value_pair::StockKeyValuePair. The duplicate StockMapKeyValuePair in map.rs and the old StockKeyValuePair in map_view.rs have been removed.
Agent-Logs-Url: https://github.com/microsoft/windows-rs/sessions/c57d9d3c-70eb-449c-90aa-84061d8e8139 Co-authored-by: kennykerr <9845234+kennykerr@users.noreply.github.com>
…pair.rs Agent-Logs-Url: https://github.com/microsoft/windows-rs/sessions/92d3ddb9-ed80-4996-9c05-5d9a6a16e62e Co-authored-by: kennykerr <9845234+kennykerr@users.noreply.github.com>
Adds a mutable
IMap<K, V>stock implementation towindows-collections, mirroring the mutableIVector<T>added in #4322.src/map.rs:StockMap<K, V>backed byRwLock<BTreeMap<K::Default, V::Default>>, implementingIMap<K, V>+IIterable<IKeyValuePair<K, V>>.Insertreturnstruewhen replacing an existing key;RemovereturnsE_BOUNDSfor missing keys.GetViewreturns a point-in-time snapshot.StockMapIterator: holds aComObject<StockMap<K, V>>reference and anAtomicUsizecurrent index (same pattern asStockVectorIterator), reading directly from the owner'sRwLock<BTreeMap>on each call — no upfront copy atFirst()time.src/key_value_pair.rs: sharedStockKeyValuePair<K, V>type extracted into its own module and used by bothmap.rsandmap_view.rs, eliminating the previous duplication.From<BTreeMap<K::Default, V::Default>>impl forIMap<K, V>.GetViewsnapshot isolation, andHSTRINGkeys.