待整理
不錯的參考資料:
https://www.hotaery.top/brpc/BRPC源碼分析之容器篇——FLATMAP和FLATSET/#FlatMapIterator
https://blog.csdn.net/guangyacyb/article/details/104047730
https://illx10000.github.io/2019/01/20/12.html#2-flatmap
https://blog.csdn.net/whizchen/article/details/9286557
注意:
FlatMap的模板聲明如下,FlatMap將會根據_Sparse的布爾值來決定選擇迭代器類型。當_Sparse為
false時將會使用FlatMapIterator
作為其迭代器,這也是默認行為,當_Sparse
為true
時,將會使用SparseFlatMapIterator
作為迭代器類型,需要注意的是,SparseFlatMapIterator
作為迭代器類型時,FlatMap不支持多線程訪問、插入或者刪除。
template <typename _K, typename _T,
typename _Hash = DefaultHasher<_K>,
typename _Equal = DefaultEqualTo<_K>,
bool _Sparse = false>
class FlatMap;
多線程迭代FlatMap可能遇到不的問題
save_iterator
、restore_iterator
用於在多線程環境中用於將迭代大map的關鍵部分划分為較小的部分。 “不一致”是指:
在迭代過程中添加的元素可能會丟失。
某些元素可能會多次迭代。
調整地圖大小時,迭代會在開始時重新開始。