Units
Classes, Interfaces, Objects
Types
Variables
Constants
Functions, Procedures
Identifiers

Class TExAnsiDict

Unit

rjExAnsiDict

Declaration

type TExAnsiDict = class(TExAbstractDictHash)

Description

Base class for AnsiString Dictionary containers. Dictionary containers, like Hash Containers, store their Items by reference to a Key. This AnsiString Dictionary container implements its Keys as AnsiStrings.

To store or to retrieve and Item, applications must always provide the appropriate key. As in all hash-based containers, duplicated Keys are not allowed in Dictionary containers.

TExAnsiDict is fully functional except that the OnHashKey and OnSameKeys properties have not yet been set. Before adding any Items to a TExAnsiDict container, they must be set by either the application itself or by descendant classes, preferably within the constructor.

Note: TExAnsiDict containers also work with an ItemSize of 0 (zero). In this case, they act like very fast "lookup" containers. They are very powerful if applications only need to test the existance of a particular key and are by far superior to sorted vectors.

Related containers: TExAnsiCSDict, TExAnsiCIDict.

Hierarchy

TExAbstractDictHash > TExContainer > TErrorObject

Fields

None.

Methods

Overview

constructor Create; override;
procedure ClearVector; override;
function DeleteByKey(const AKey: AnsiString): Boolean;
function DeleteByKeyBuf(const Buffer: Pointer; const BufferSize: Cardinal): Boolean;
function GetIndexOfKey(const AKey: AnsiString): Integer;
function GetIndexOfKeyBuf(const Buffer: Pointer; const BufferSize: Cardinal): Integer;
function GetIndexOfKeyBufEx(const Buffer: Pointer; const BufferSize: Cardinal; out Hash: Cardinal; out Previous: Integer): Integer;
function GetIndexOfKeyEx(const AKey: AnsiString; out Hash: Cardinal; out Previous: Integer): Integer;
function GetKeyAt(const Index: Integer): AnsiString;
function GetPItemAt(const Index: Integer): Pointer;
function GetPItemOfKey(const AKey: AnsiString): Pointer;
function GetPItemOfKeyBuf(const Buffer: Pointer; const BufferSize: Cardinal): Pointer;
function GetPItemOfKeyBufEx(const Buffer: Pointer; const BufferSize: Cardinal; out Hash: Cardinal; out Previous: Integer): Pointer;
function GetPItemOfKeyEx(const AKey: AnsiString; out Hash: Cardinal; out Previous: Integer): Pointer;
function InsertItemByKey(const AKey: AnsiString): Pointer;
function InsertItemByKeyBuf(const Buffer: Pointer; BufferSize: Cardinal): Pointer;
procedure RebuildHash; override;
procedure SetItemSize(const NewItemSize: Integer); override;

Description

constructor Create; override;

Creates an instance of TExAnsiDict.

procedure ClearVector; override;

 

function DeleteByKey(const AKey: AnsiString): Boolean;

Deletes the Item associated with a key AKey. If the Key could be located and its Item deleted, DeleteByKey returns True, otherwise False.

If the number of undeleted Items in the hash container falls to below 1/3 of VectorCount as a result of calling DeleteByKey, the container is shrunk to roughly half its size.

See also: DeleteByKeyBuf.

function DeleteByKeyBuf(const Buffer: Pointer; const BufferSize: Cardinal): Boolean;

Deletes the Item associated with a key pointed to by Buffer. If the Key could be located and its Item deleted, DeleteByKeyBuf returns True, otherwise False.

If the number of undeleted Items in the hash container falls to below 1/3 of VectorCount as a result of calling DeleteByKeyBuf, the container is shrunk to roughly half its size.

See also: DeleteByKey.

function GetIndexOfKey(const AKey: AnsiString): Integer;

 

function GetIndexOfKeyBuf(const Buffer: Pointer; const BufferSize: Cardinal): Integer;

 

function GetIndexOfKeyBufEx(const Buffer: Pointer; const BufferSize: Cardinal; out Hash: Cardinal; out Previous: Integer): Integer;

 

function GetIndexOfKeyEx(const AKey: AnsiString; out Hash: Cardinal; out Previous: Integer): Integer;

 

function GetKeyAt(const Index: Integer): AnsiString;

 

function GetPItemAt(const Index: Integer): Pointer;

 

function GetPItemOfKey(const AKey: AnsiString): Pointer;

 

function GetPItemOfKeyBuf(const Buffer: Pointer; const BufferSize: Cardinal): Pointer;

 

function GetPItemOfKeyBufEx(const Buffer: Pointer; const BufferSize: Cardinal; out Hash: Cardinal; out Previous: Integer): Pointer;

 

function GetPItemOfKeyEx(const AKey: AnsiString; out Hash: Cardinal; out Previous: Integer): Pointer;

 

function InsertItemByKey(const AKey: AnsiString): Pointer;

Inserts a new Item and returns a pointer to it.

Duplicate Keys are not allowed in hash containers. If the Key already exists, no new Item will be added and InsertItemByKey will return nil.

function InsertItemByKeyBuf(const Buffer: Pointer; BufferSize: Cardinal): Pointer;

Inserts a new Item and returns a pointer to it. Key starts at Buffer and is BufferSize bytes long.

Duplicate Keys are not allowed in hash containers. If the Key already exists, no new Item will be added and InsertItemByKeyBuf will return nil.

procedure RebuildHash; override;

 

procedure SetItemSize(const NewItemSize: Integer); override;

See ItemSize.

Properties

Overview

IndexOfKey[const AKey: AnsiString]: Integer;
IndexOfKeyBuf[const Buffer: Pointer; const BufferSize: Cardinal]: Integer;
KeyAt[const Index: Integer]: AnsiString;
PItemAt[const Index: Integer]: Pointer;
PItemOfKey[const AKey: AnsiString]: Pointer;
PItemOfKeyBuf[const Buffer: Pointer; const BufferSize: Cardinal]: Pointer;

Description

IndexOfKey[const AKey: AnsiString]: Integer;

Returns the Index of the Item stored under a given Key. If the Key could not be found, returns a negative number.

IndexOfKeyBuf[const Buffer: Pointer; const BufferSize: Cardinal]: Integer;

Returns the Index of the Item stored under a given Key. If the Key could not be found, returns a negative number.

KeyAt[const Index: Integer]: AnsiString;

 

PItemAt[const Index: Integer]: Pointer;

Returns a pointer to the Item at the specified Index's position in the hash container.

Items may have been deleted in hash containers. It is advisable to Call IsDeleted before retrieving Items, unless it is known that no Items have yet been deleted.

Index must be in the range zero to VectorCount-1. An exception will be raised if Index is outside of this range and rjExContainer Library was compiled with the directive "RangeChecking" defined (default).

See also: Pack.

PItemOfKey[const AKey: AnsiString]: Pointer;

Returns a pointer to the Item stored under a given Key. If Key could not be found, returns nil.

PItemOfKeyBuf[const Buffer: Pointer; const BufferSize: Cardinal]: Pointer;

 


rjExContainer Library Version 0.2.
Copyright Ralf Junker 2000-2001.
http://www.zeitungsjunge.de/delphi/.