coastline 0.0.4
Loading...
Searching...
No Matches
CMapWordToPtr Class Reference

Hash map from 16-bit words to borrowed pointers, with pooled associations. More...

#include <mfc.h>

Inheritance diagram for CMapWordToPtr:
Collaboration diagram for CMapWordToPtr:

Public Member Functions

 CMapWordToPtr (int blockSize=10)
 Initialise an empty map with 17 buckets allocated on first insertion.
 ~CMapWordToPtr () override
 Release buckets and association pools without deleting pointer values.
int GetCount () const
UINT GetHashTableSize () const
BOOL IsEmpty () const
BOOL Lookup (WORD key, void *&value) const
 Look up a pointer without changing the output on a missing key.
void SetAt (WORD key, void *value)
 Insert or replace a pointer without releasing the previous value.
BOOL RemoveKey (WORD key)
 Remove an association and release all storage when the map becomes empty.
void RemoveAll ()
 Release all associations and buckets without deleting pointer values.
POSITION GetStartPosition () const
void GetNextAssoc (POSITION &position, WORD &key, void *&value) const
 Retrieve an association in hash-bucket order and advance the cursor.
void InitHashTable (UINT hashSize, BOOL allocate=TRUE)
 Replace bucket storage in an empty map without changing the association-pool configuration.
Public Member Functions inherited from CObject
virtual CRuntimeClass * GetRuntimeClass () const
virtual ~CObject ()
 The base destructor does not perform additional cleanup.
virtual void Serialize (CArchive &archive)
 Do not serialise archive data.
virtual void AssertValid () const
 Do not validate object state.
virtual void Dump (CDumpContext &context) const
 Do not emit diagnostic output.

Detailed Description

Hash map from 16-bit words to borrowed pointers, with pooled associations.

Pointer values are never deleted. Positions become invalid after their associations are removed or all storage is released. Hash-table reinitialisation requires an empty map.

Constructor & Destructor Documentation

◆ CMapWordToPtr()

CMapWordToPtr::CMapWordToPtr ( int blockSize = 10)
explicit

Initialise an empty map with 17 buckets allocated on first insertion.

Parameters
blockSizeThe positive number of associations allocated per pool block.

◆ ~CMapWordToPtr()

CMapWordToPtr::~CMapWordToPtr ( )
override

Release buckets and association pools without deleting pointer values.

Member Function Documentation

◆ GetCount()

int CMapWordToPtr::GetCount ( ) const
Returns
The number of registered associations.

◆ GetHashTableSize()

UINT CMapWordToPtr::GetHashTableSize ( ) const
Returns
The configured bucket count, even before bucket allocation.

◆ IsEmpty()

BOOL CMapWordToPtr::IsEmpty ( ) const
Returns
TRUE when the association count is zero; otherwise FALSE.

◆ Lookup()

BOOL CMapWordToPtr::Lookup ( WORD key,
void *& value ) const

Look up a pointer without changing the output on a missing key.

Parameters
keyThe word-sized key.
valueThe output borrowed pointer, possibly null for a registered null value.
Returns
TRUE when the key exists; otherwise FALSE.

◆ SetAt()

void CMapWordToPtr::SetAt ( WORD key,
void * value )

Insert or replace a pointer without releasing the previous value.

Parameters
keyThe word-sized key.
valueThe borrowed pointer, possibly null.

◆ RemoveKey()

BOOL CMapWordToPtr::RemoveKey ( WORD key)

Remove an association and release all storage when the map becomes empty.

Parameters
keyThe word-sized key.
Returns
TRUE when an association was removed; otherwise FALSE.

◆ RemoveAll()

void CMapWordToPtr::RemoveAll ( )

Release all associations and buckets without deleting pointer values.

◆ GetStartPosition()

POSITION CMapWordToPtr::GetStartPosition ( ) const
Returns
A cursor before the first association, or null for an empty map.

◆ GetNextAssoc()

void CMapWordToPtr::GetNextAssoc ( POSITION & position,
WORD & key,
void *& value ) const

Retrieve an association in hash-bucket order and advance the cursor.

Parameters
positionA non-null cursor from this map, replaced with the next cursor or null.
keyThe output word-sized key.
valueThe output borrowed pointer, valid while the external object remains allocated.

◆ InitHashTable()

void CMapWordToPtr::InitHashTable ( UINT hashSize,
BOOL allocate = TRUE )

Replace bucket storage in an empty map without changing the association-pool configuration.

Parameters
hashSizeThe positive bucket count.
allocateWhether to allocate buckets immediately rather than on first insertion.

The documentation for this class was generated from the following file: