Dictionary and Hash container base classes and functions.
Dictionary and Hash containers store and manipulate their Items by reference to a Key. This Key could be of any type: Strings, Numbers, or blocks of memory. In the rjExContainers Library, Dictionary containers store Keys of variable-length (different Keys may have different lengths), while Hash containers handle fixed-length Keys (all keys have the same length).
Both Dictionary and Hash containers implement the same, fast lookup mechanism called hashing: First, a hashing function (see OnHashKey
) calculates a numberic fingerprint of a Key. Based on this hash value, the Key can then be instantly located in the container.
Hashing is one of the fastest methods available for searching if all Items fit into memory.
Dictionary and Hash containers in rjExContainers Library include:
Hash Containers | Dictionary Containers |
TExHash | TExAnsiDict TExAnsiCSDict TExAnsiCIDict TAnsiStringAnsiCSDict TAnsiStringAnsiCIDict TCardinalAnsiCSDict TCardinalAnsiCIDict TCardinal2AnsiCSDict TCardinal2AnsiCIDict |
Name | Description |
---|---|
Class TExAbstractDictHash | Abstract base class for Dictionary and Hash containers. |
Class TExHash | Base class for Hash containers. |
function AnsiBufferHashCI(const Buffer: Pointer; const BufferSize: Cardinal): Cardinal; |
Calculates a hash value for a Buffer pointet to by Buffer
with the length of BufferSize
. AnsiBufferHashCI
is case insensitive.
function AnsiBufferHashCS(const Buffer: Pointer; const BufferSize: Cardinal): Cardinal; |
Calculates a hash value for a Buffer pointet to by Buffer
with the length of BufferLength
. AnsiBufferHashCS
is case sensitive.
function AnsiHashCI(const s: AnsiString): Cardinal; |
Calculates a hash value for an AnsiString. AnsiHashCI
is case insensitive.
function AnsiHashCS(const s: AnsiString): Cardinal; |
Calculates a hash value for an AnsiString. AnsiHashCS
is case sensitive.
procedure CopyKey(const PFromKey, PToKey: Pointer; const KeySize: Cardinal); |
Copies KeySize
bytes of memory from PFromKey to PToKey.
procedure CopyKey04(const PFromKey, PToKey: Pointer; const KeySize: Cardinal); |
Copies exactly 4 bytes of memory from PFromKey
to PToKey
, ignoring KeySize
. If KeySize
is known in advance, CopyKey04
is generally faster than CopyKey
.
procedure CopyKey08(const PFromKey, PToKey: Pointer; const KeySize: Cardinal); |
Copies exactly 8 bytes of memory from PFromKey
to PToKey
, ignoring KeySize
. If KeySize
is known in advance, CopyKey08
is generally faster than CopyKey
.
procedure CopyKey12(const PFromKey, PToKey: Pointer; const KeySize: Cardinal); |
Copies exactly 12 bytes of memory from PFromKey
to PToKey
, ignoring KeySize
. If KeySize
is known in advance, CopyKey12
is generally faster than CopyKey
.
function HashKey04(const PKey: Pointer; const KeySize: Cardinal): Cardinal; |
Hashes a Key of 4 bytes size, ignonring KeySize.
function SameKeys04(const PKey1, PKey2: Pointer; const KeySize: Cardinal): Boolean; |
Compares two keys of 4 bytes size, ignonring KeySize.
Name | Description |
---|---|
HASH_DELETED | Holds the leftmost bit of an Integer / Cardinal. It is used to mark deleted slots in the vector. Both HASH_DELETED and HASH_END limit the maximum number of items a hash container can hold to 2^30. Only for internal use. Do not modify. |
HASH_END | Holds the second leftmost bit of an Integer / Cardinal. It is used to indicate the end of the linked hash list. Both HASH_END and HASH_DELETED limit the maximum number of items a hash container can hold to 2^30. Only for internal use. Do not modify. |
MIN_HASH_SIZE | The minimum size of FHash initially allocated. Increase it for speed, decrease it for smaller memory footprint. Use a prime number if possible. Default is 11. |
None.
Ralf Junker -- delphi@zeitungsjunge.de