共用方式為


CAtlMap::CAtlMap

建構函式。

CAtlMap(
   UINT nBins = 17,
   float fOptimalLoad = 0.75f,
   float fLoThreshold = 0.25f,
   float fHiThreshold = 2.25f,
   UINT nBlockSize = 10 
) throw ( );

參數

  • nBins
    提供指標容器的數目寫入儲存的項目。 為容器 (Container) 的解譯後請參閱"備註"本主題後面的。

  • fOptimalLoad
    最佳載入比例。

  • fLoThreshold
    載入指定的臨界值。

  • fHiThreshold
    載入指定的臨界值上限。

  • nBlockSize
    區塊大小。

備註

使用,在金鑰的雜湊演算法CAtlMap 先建立索引參考任何儲存的項目。 這個索引參考含有指向儲存項目的「Bin」。 如果容器已經在使用中,連接清單建立存取後續項目。 周遊清單比直接存取正確的項目,慢,因此導覽結構平衡儲存需求避免效能。 預設參數已選取在許多情況下提供最佳結果。

載入比例是容器的數目與在對應物件儲存的項目數目。 當網站導覽結構重新計算, fOptimalLoad 參數值會用來計算需要的容器的數目。 使用 CAtlMap::SetOptimalLoad 方法,這個值可以變更。

fLoThreshold 參數是載入率可能達到的較小的值,在 CAtlMap 會重新對應之前的最佳大小。

fHiThreshold 參數是載入率可能達到的上限值,在 CAtlMap 物件將重新對應之前的最佳大小。

這個處理序會將重新計算 (稱為) 預設為啟用狀態。 如果您想要停用這個處理序,可能,當一次輸入大量資料,請呼叫方法。 CAtlMap::DisableAutoRehash 重新啟動它。 CAtlMap::EnableAutoRehash 方法。

如果需要, nBlockSize 參數是數量的測量記憶體配置新的項目。 較大的區塊大小讓呼叫減少記憶體配置常式,不過,使用更多資源。

在可以儲存所有資料,初始化時呼叫的雜湊資料表加入至 CAtlMap::InitHashTable是必要的。

範例

// Create a map which stores a double
// value using an integer key

CAtlMap<int, double> mySinTable;
int i;

// Initialize the Hash Table
mySinTable.InitHashTable(257);

// Add items to the map
for (i = 0; i < 90; i++)
   mySinTable[i] = sin((double)i);

// Confirm the map is valid
mySinTable.AssertValid();

// Confirm the number of elements in the map
ATLASSERT(mySinTable.GetCount() == 90);

// Remove elements with even key values
for (i = 0; i < 90; i += 2)
   mySinTable.RemoveKey(i);

// Confirm the number of elements in the map
ATLASSERT(mySinTable.GetCount() == 45);

// Walk through all the elements in the map.
// First, get start position.
POSITION pos;
int key;
double value;
pos = mySinTable.GetStartPosition();

// Now iterate the map, element by element
while (pos != NULL) 
{
   key = mySinTable.GetKeyAt(pos);
   value = mySinTable.GetNextValue(pos);
}

需求

Header: atlcoll.h

請參閱

參考

CAtlMap 類別

CAtlMap::~CAtlMap