2004-07-29 06:33:18 +00:00
|
|
|
{
|
|
|
|
:: X2UtHashes contains a base class for hashes (also known as associative
|
|
|
|
:: arrays), as well as various default implementations.
|
|
|
|
::
|
2005-06-30 12:18:53 +00:00
|
|
|
:: The useable implementations have a naming convention of TX2<tt>Hash,
|
|
|
|
:: where <tt> are two characters representing the key and value types,
|
|
|
|
:: according to the following table:
|
|
|
|
::
|
|
|
|
:: P = Pointer
|
|
|
|
:: I = Integer
|
|
|
|
:: O = Object
|
|
|
|
:: S = String
|
|
|
|
::
|
|
|
|
:: For example; TX2SOHash indicates that it uses String keys to identify
|
|
|
|
:: Object values.
|
2004-07-29 06:33:18 +00:00
|
|
|
::
|
2005-12-28 19:15:17 +00:00
|
|
|
:: As of Delphi 2006, all default hashes support the for...in structure.
|
|
|
|
:: To enumerate all keys, use "for x in Hash". As of yet, there is no
|
|
|
|
:: direct support for value enumeration yet; you can use
|
|
|
|
:: First/Next/CurrentValue for that.
|
|
|
|
::
|
2004-07-29 06:33:18 +00:00
|
|
|
:: Last changed: $Date$
|
|
|
|
:: Revision: $Rev$
|
|
|
|
:: Author: $Author$
|
|
|
|
}
|
|
|
|
unit X2UtHashes;
|
|
|
|
|
2007-06-13 07:26:50 +00:00
|
|
|
{$I X2UtCompilerVersion.inc}
|
|
|
|
|
2004-07-29 06:33:18 +00:00
|
|
|
interface
|
|
|
|
uses
|
2005-06-30 12:18:53 +00:00
|
|
|
Classes,
|
|
|
|
SysUtils;
|
|
|
|
|
|
|
|
const
|
|
|
|
// Do NOT change these values unless you really know
|
|
|
|
// what you are doing!
|
|
|
|
LeafSize = 256;
|
|
|
|
BucketSize = 8;
|
2004-07-29 06:33:18 +00:00
|
|
|
|
|
|
|
type
|
2005-06-30 12:18:53 +00:00
|
|
|
//:$ Raised when the cursor is not available
|
|
|
|
EX2HashNoCursor = class(Exception);
|
|
|
|
|
2005-12-28 19:15:17 +00:00
|
|
|
// Forward declarations
|
|
|
|
TX2CustomHash = class;
|
|
|
|
|
2007-06-13 07:26:50 +00:00
|
|
|
|
2009-02-25 10:51:58 +00:00
|
|
|
{$IFDEF D2005PLUS}
|
2005-12-28 19:15:17 +00:00
|
|
|
{$REGION 'Internal hash structures'}
|
2007-06-13 07:26:50 +00:00
|
|
|
{$ENDIF}
|
2004-07-29 06:33:18 +00:00
|
|
|
{
|
2005-06-30 12:18:53 +00:00
|
|
|
:$ Internal representation of a hash item.
|
2004-07-29 06:33:18 +00:00
|
|
|
}
|
2010-03-12 12:27:49 +00:00
|
|
|
PX2HashCookie = Pointer;
|
|
|
|
|
2004-08-20 13:03:07 +00:00
|
|
|
PX2HashItem = ^TX2HashItem;
|
|
|
|
TX2HashItem = record
|
2005-06-30 12:18:53 +00:00
|
|
|
ID: Cardinal;
|
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
PX2HashBucket = ^TX2HashBucket;
|
|
|
|
TX2HashBucket = record
|
|
|
|
ID: Cardinal;
|
|
|
|
Level: Integer;
|
|
|
|
Count: Integer;
|
|
|
|
Items: array[0..Pred(LeafSize)] of PX2HashItem;
|
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
PX2HashValue = ^TX2HashValue;
|
|
|
|
TX2HashValue = record
|
|
|
|
ID: Cardinal;
|
|
|
|
Next: PX2HashValue;
|
2010-03-12 12:27:49 +00:00
|
|
|
Key: PX2HashCookie;
|
|
|
|
Value: PX2HashCookie;
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
TX2BucketPath = record
|
|
|
|
Bucket: PX2HashBucket;
|
|
|
|
Index: Integer;
|
2004-07-29 06:33:18 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
|
|
|
PX2HashStringCookie = ^TX2HashStringCookie;
|
|
|
|
TX2HashStringCookie = record
|
|
|
|
Length: Cardinal;
|
|
|
|
Value: PChar;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2004-07-29 13:48:35 +00:00
|
|
|
{
|
2005-06-30 12:18:53 +00:00
|
|
|
:$ Default cursor implementation.
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
:: Traverses the hash tree from top-to-bottom, left-to-right.
|
2004-07-29 13:48:35 +00:00
|
|
|
}
|
2005-06-30 12:18:53 +00:00
|
|
|
TX2HashCursor = class(TObject)
|
|
|
|
private
|
2010-03-12 12:27:49 +00:00
|
|
|
FBucketPath: array of TX2BucketPath;
|
|
|
|
FCurrent: PX2HashValue;
|
2005-06-30 12:18:53 +00:00
|
|
|
protected
|
2010-03-12 12:27:49 +00:00
|
|
|
function GetCurrent: PX2HashValue; virtual;
|
2005-06-30 12:18:53 +00:00
|
|
|
public
|
|
|
|
constructor Create(const ABucket: PX2HashBucket); virtual;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
procedure First; virtual;
|
|
|
|
function Next: Boolean; virtual;
|
2005-06-30 12:18:53 +00:00
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
property Current: PX2HashValue read GetCurrent;
|
2004-07-29 13:48:35 +00:00
|
|
|
end;
|
2009-02-25 10:51:58 +00:00
|
|
|
{$IFDEF D2005PLUS}
|
2005-12-28 19:15:17 +00:00
|
|
|
{$ENDREGION}
|
2004-08-20 13:03:07 +00:00
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-12-28 19:15:17 +00:00
|
|
|
{$REGION 'Internal value managers'}
|
2007-06-13 07:26:50 +00:00
|
|
|
{$ENDIF}
|
2004-07-29 06:33:18 +00:00
|
|
|
{
|
2005-06-30 12:18:53 +00:00
|
|
|
:$ Base value manager.
|
|
|
|
}
|
2010-03-12 12:27:49 +00:00
|
|
|
TX2CustomHashManager = class(TObject)
|
2005-12-28 19:15:17 +00:00
|
|
|
protected
|
2010-03-12 12:27:49 +00:00
|
|
|
procedure FreeCookie(var ACookie: PX2HashCookie); virtual;
|
2004-07-29 06:33:18 +00:00
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
function Hash(ACookie: PX2HashCookie): Cardinal; virtual; abstract;
|
|
|
|
function Compare(const ACookie1, ACookie2: PX2HashCookie): Boolean; virtual; abstract;
|
|
|
|
function Clone(const ACookie: PX2HashCookie): PX2HashCookie; virtual; abstract;
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
TX2HashPointerManager = class(TX2CustomHashManager)
|
2005-12-28 19:15:17 +00:00
|
|
|
protected
|
2010-03-12 12:27:49 +00:00
|
|
|
function CreateCookie(const AValue: Pointer): PX2HashCookie; overload;
|
|
|
|
function GetValue(const ACookie: PX2HashCookie): Pointer; overload;
|
|
|
|
|
|
|
|
function Hash(ACookie: PX2HashCookie): Cardinal; override;
|
|
|
|
function Compare(const ACookie1, ACookie2: PX2HashCookie): Boolean; override;
|
|
|
|
function Clone(const ACookie: PX2HashCookie): PX2HashCookie; override;
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
{
|
|
|
|
:$ Integer value class.
|
2004-07-29 06:33:18 +00:00
|
|
|
}
|
2005-06-30 12:18:53 +00:00
|
|
|
TX2HashIntegerManager = class(TX2CustomHashManager)
|
2005-12-28 19:15:17 +00:00
|
|
|
protected
|
2010-03-12 12:27:49 +00:00
|
|
|
function CreateCookie(const AValue: Integer): PX2HashCookie; overload;
|
|
|
|
function GetValue(const ACookie: PX2HashCookie): Integer; overload;
|
|
|
|
|
|
|
|
function Hash(ACookie: PX2HashCookie): Cardinal; override;
|
|
|
|
function Compare(const ACookie1, ACookie2: PX2HashCookie): Boolean; override;
|
|
|
|
function Clone(const ACookie: PX2HashCookie): PX2HashCookie; override;
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
{
|
|
|
|
:$ Object value class.
|
|
|
|
}
|
2010-03-12 12:27:49 +00:00
|
|
|
TX2HashObjectManager = class(TX2CustomHashManager)
|
2004-07-29 06:33:18 +00:00
|
|
|
private
|
2010-03-12 12:27:49 +00:00
|
|
|
FOwnsObjects: Boolean;
|
2005-12-28 19:15:17 +00:00
|
|
|
protected
|
2010-03-12 12:27:49 +00:00
|
|
|
procedure FreeCookie(var ACookie: PX2HashCookie); override;
|
|
|
|
|
|
|
|
function CreateCookie(const AValue: TObject): PX2HashCookie; overload;
|
|
|
|
function GetValue(const ACookie: PX2HashCookie): TObject; overload;
|
2004-07-29 06:33:18 +00:00
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
function Hash(ACookie: PX2HashCookie): Cardinal; override;
|
|
|
|
function Compare(const ACookie1, ACookie2: PX2HashCookie): Boolean; override;
|
|
|
|
function Clone(const ACookie: PX2HashCookie): PX2HashCookie; override;
|
2004-07-29 06:33:18 +00:00
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
property OwnsObjects: Boolean read FOwnsObjects write FOwnsObjects;
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
{
|
|
|
|
:$ String value class.
|
|
|
|
}
|
2010-03-12 12:27:49 +00:00
|
|
|
TX2HashStringManager = class(TX2CustomHashManager)
|
2005-12-28 19:15:17 +00:00
|
|
|
protected
|
2010-03-12 12:27:49 +00:00
|
|
|
procedure FreeCookie(var ACookie: PX2HashCookie); override;
|
2004-07-29 06:33:18 +00:00
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
function CreateCookie(const AValue: string): PX2HashCookie; overload;
|
|
|
|
function GetValue(const ACookie: PX2HashCookie): string; overload;
|
2004-07-29 06:33:18 +00:00
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
function Hash(ACookie: PX2HashCookie): Cardinal; override;
|
|
|
|
function Compare(const ACookie1, ACookie2: PX2HashCookie): Boolean; override;
|
|
|
|
function Clone(const ACookie: PX2HashCookie): PX2HashCookie; override;
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
2009-02-25 10:51:58 +00:00
|
|
|
{$IFDEF D2005PLUS}
|
2005-12-28 19:15:17 +00:00
|
|
|
{$ENDREGION}
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-12-28 19:15:17 +00:00
|
|
|
{$REGION 'Delphi 2006 enumerator support'}
|
2007-06-13 07:26:50 +00:00
|
|
|
{$ENDIF}
|
2005-12-28 19:15:17 +00:00
|
|
|
{
|
|
|
|
:$ Base enumerator class.
|
|
|
|
}
|
2010-03-12 12:27:49 +00:00
|
|
|
TX2HashEnumerator = class(TObject)
|
2005-12-28 19:15:17 +00:00
|
|
|
private
|
|
|
|
FCursor: TX2HashCursor;
|
|
|
|
FManager: TX2CustomHashManager;
|
|
|
|
FEnumKeys: Boolean;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
function GetCursor: PX2HashCookie;
|
2005-12-28 19:15:17 +00:00
|
|
|
protected
|
|
|
|
property Manager: TX2CustomHashManager read FManager;
|
2010-03-12 12:27:49 +00:00
|
|
|
property Cursor: PX2HashCookie read GetCursor;
|
2005-12-28 19:15:17 +00:00
|
|
|
public
|
|
|
|
constructor Create(const AHash: TX2CustomHash;
|
|
|
|
const AEnumKeys: Boolean);
|
2010-03-12 12:27:49 +00:00
|
|
|
destructor Destroy; override;
|
2005-12-28 19:15:17 +00:00
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
function MoveNext: Boolean;
|
2005-12-28 19:15:17 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-12-28 19:15:17 +00:00
|
|
|
{
|
|
|
|
:$ Enumerator for pointer values.
|
|
|
|
}
|
|
|
|
TX2HashPointerEnumerator = class(TX2HashEnumerator)
|
|
|
|
private
|
|
|
|
function GetCurrent: Pointer;
|
|
|
|
public
|
2010-03-12 12:27:49 +00:00
|
|
|
property Current: Pointer read GetCurrent;
|
2005-12-28 19:15:17 +00:00
|
|
|
end;
|
2004-07-29 06:33:18 +00:00
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-12-28 19:15:17 +00:00
|
|
|
{
|
|
|
|
:$ Enumerator for integer values.
|
|
|
|
}
|
|
|
|
TX2HashIntegerEnumerator = class(TX2HashEnumerator)
|
|
|
|
private
|
|
|
|
function GetCurrent: Integer;
|
|
|
|
public
|
2010-03-12 12:27:49 +00:00
|
|
|
property Current: Integer read GetCurrent;
|
2005-12-28 19:15:17 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-12-28 19:15:17 +00:00
|
|
|
{
|
|
|
|
:$ Enumerator for object values.
|
|
|
|
}
|
|
|
|
TX2HashObjectEnumerator = class(TX2HashEnumerator)
|
|
|
|
private
|
|
|
|
function GetCurrent: TObject;
|
|
|
|
public
|
2010-03-12 12:27:49 +00:00
|
|
|
property Current: TObject read GetCurrent;
|
2005-12-28 19:15:17 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-12-28 19:15:17 +00:00
|
|
|
{
|
|
|
|
:$ Enumerator for string values
|
|
|
|
}
|
|
|
|
TX2HashStringEnumerator = class(TX2HashEnumerator)
|
|
|
|
private
|
2010-03-12 12:27:49 +00:00
|
|
|
function GetCurrent: String;
|
2005-12-28 19:15:17 +00:00
|
|
|
public
|
2010-03-12 12:27:49 +00:00
|
|
|
property Current: String read GetCurrent;
|
2005-12-28 19:15:17 +00:00
|
|
|
end;
|
2009-02-25 10:51:58 +00:00
|
|
|
{$IFDEF D2005PLUS}
|
2005-12-28 19:15:17 +00:00
|
|
|
{$ENDREGION}
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-12-28 19:15:17 +00:00
|
|
|
{$REGION 'Abstract hash implementation'}
|
2007-06-13 07:26:50 +00:00
|
|
|
{$ENDIF}
|
2005-06-30 12:18:53 +00:00
|
|
|
{
|
|
|
|
:$ Hash implementation.
|
|
|
|
}
|
|
|
|
TX2CustomHash = class(TPersistent)
|
|
|
|
private
|
|
|
|
FRoot: PX2HashBucket;
|
|
|
|
FCount: Integer;
|
2004-07-29 06:33:18 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
FCursor: TX2HashCursor;
|
|
|
|
FKeyManager: TX2CustomHashManager;
|
|
|
|
FValueManager: TX2CustomHashManager;
|
|
|
|
protected
|
2010-03-12 12:27:49 +00:00
|
|
|
function CreateCursor: TX2HashCursor; virtual;
|
|
|
|
function CreateKeyManager: TX2CustomHashManager; virtual; abstract;
|
|
|
|
function CreateValueManager: TX2CustomHashManager; virtual; abstract;
|
|
|
|
procedure InvalidateCursor;
|
2005-06-30 12:18:53 +00:00
|
|
|
|
2005-08-26 10:25:39 +00:00
|
|
|
function CursorRequired(const ARaiseException: Boolean = True): Boolean;
|
2005-06-30 12:18:53 +00:00
|
|
|
|
|
|
|
function InternalFind(const ABucket: PX2HashBucket;
|
2010-03-12 12:27:49 +00:00
|
|
|
const AHash: Cardinal; const AKey: PX2HashCookie;
|
2005-06-30 12:18:53 +00:00
|
|
|
const AAllowCreate: Boolean;
|
|
|
|
const AExisting: PX2HashValue = nil): PX2HashValue;
|
|
|
|
function InternalDelete(const ABucket: PX2HashBucket;
|
2010-03-12 12:27:49 +00:00
|
|
|
const AHash: Cardinal; const AKey: PX2HashCookie): Boolean;
|
2005-06-30 12:18:53 +00:00
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
{ :$ AKey will be freed by these methods, so make sure to pass a Clone
|
|
|
|
:$ if you need it afterwards! }
|
|
|
|
function Find(const AKey: PX2HashCookie; const AAllowCreate: Boolean): PX2HashValue; overload;
|
|
|
|
function Exists(const AKey: PX2HashCookie): Boolean; overload;
|
|
|
|
function Delete(const AKey: PX2HashCookie): Boolean; overload;
|
2005-06-30 12:18:53 +00:00
|
|
|
|
|
|
|
procedure SetValue(const AValue: PX2HashValue; const AData: Pointer);
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
property Cursor: TX2HashCursor read FCursor;
|
|
|
|
property KeyManager: TX2CustomHashManager read FKeyManager;
|
|
|
|
property ValueManager: TX2CustomHashManager read FValueManager;
|
2004-07-29 06:33:18 +00:00
|
|
|
public
|
2010-03-12 12:27:49 +00:00
|
|
|
constructor Create; virtual;
|
|
|
|
destructor Destroy; override;
|
2004-07-29 13:48:35 +00:00
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
procedure Clear;
|
2005-07-01 11:43:59 +00:00
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
procedure First;
|
|
|
|
function Next: Boolean;
|
2004-07-29 06:33:18 +00:00
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
property Count: Integer read FCount;
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
2009-02-25 10:51:58 +00:00
|
|
|
{$IFDEF D2005PLUS}
|
2005-12-28 19:15:17 +00:00
|
|
|
{$ENDREGION}
|
2004-07-29 06:33:18 +00:00
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-12-28 19:15:17 +00:00
|
|
|
{$REGION 'Base hash classes'}
|
2007-06-13 07:26:50 +00:00
|
|
|
{$ENDIF}
|
2005-06-30 12:18:53 +00:00
|
|
|
{
|
|
|
|
:$ Base hash implementation for pointer keys.
|
|
|
|
}
|
|
|
|
TX2CustomPointerHash = class(TX2CustomHash)
|
|
|
|
private
|
2010-03-12 12:27:49 +00:00
|
|
|
function GetCurrentKey: Pointer;
|
|
|
|
function GetKeyManager: TX2HashPointerManager;
|
2005-06-30 12:18:53 +00:00
|
|
|
protected
|
2010-03-12 12:27:49 +00:00
|
|
|
function CreateKeyManager: TX2CustomHashManager; override;
|
|
|
|
function Find(const AKey: Pointer; const AAllowCreate: Boolean): PX2HashValue; overload;
|
|
|
|
|
|
|
|
property KeyManager: TX2HashPointerManager read GetKeyManager;
|
2005-06-30 12:18:53 +00:00
|
|
|
public
|
2010-03-12 12:27:49 +00:00
|
|
|
function GetEnumerator: TX2HashPointerEnumerator;
|
2005-12-28 19:15:17 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function Exists(const AKey: Pointer): Boolean; overload;
|
|
|
|
function Delete(const AKey: Pointer): Boolean; overload;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
property CurrentKey: Pointer read GetCurrentKey;
|
2004-07-29 06:33:18 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2004-07-29 06:33:18 +00:00
|
|
|
{
|
2005-06-30 12:18:53 +00:00
|
|
|
:$ Base hash implementation for integer keys.
|
2004-07-29 06:33:18 +00:00
|
|
|
}
|
2005-06-30 12:18:53 +00:00
|
|
|
TX2CustomIntegerHash = class(TX2CustomHash)
|
|
|
|
private
|
2010-03-12 12:27:49 +00:00
|
|
|
function GetCurrentKey: Integer;
|
|
|
|
function GetKeyManager: TX2HashIntegerManager;
|
2004-08-20 13:03:07 +00:00
|
|
|
protected
|
2010-03-12 12:27:49 +00:00
|
|
|
function CreateKeyManager: TX2CustomHashManager; override;
|
|
|
|
function Find(const AKey: Integer; const AAllowCreate: Boolean): PX2HashValue; overload;
|
|
|
|
|
|
|
|
property KeyManager: TX2HashIntegerManager read GetKeyManager;
|
2005-06-30 12:18:53 +00:00
|
|
|
public
|
2010-03-12 12:27:49 +00:00
|
|
|
function GetEnumerator: TX2HashIntegerEnumerator;
|
2005-12-28 19:15:17 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function Exists(const AKey: Integer): Boolean; overload;
|
|
|
|
function Delete(const AKey: Integer): Boolean; overload;
|
2004-07-29 06:33:18 +00:00
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
property CurrentKey: Integer read GetCurrentKey;
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
{
|
|
|
|
:$ Base hash implementation for object keys.
|
|
|
|
}
|
|
|
|
TX2CustomObjectHash = class(TX2CustomHash)
|
|
|
|
private
|
2010-03-12 12:27:49 +00:00
|
|
|
function GetCurrentKey: TObject;
|
|
|
|
function GetKeyManager: TX2HashObjectManager;
|
2005-06-30 12:18:53 +00:00
|
|
|
protected
|
2010-03-12 12:27:49 +00:00
|
|
|
function CreateKeyManager: TX2CustomHashManager; override;
|
|
|
|
function Find(const AKey: TObject; const AAllowCreate: Boolean): PX2HashValue; overload;
|
|
|
|
|
|
|
|
property KeyManager: TX2HashObjectManager read GetKeyManager;
|
2004-07-29 06:33:18 +00:00
|
|
|
public
|
2010-03-12 12:27:49 +00:00
|
|
|
function GetEnumerator: TX2HashObjectEnumerator;
|
2005-12-28 19:15:17 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function Exists(const AKey: TObject): Boolean; overload;
|
|
|
|
function Delete(const AKey: TObject): Boolean; overload;
|
2004-07-29 06:33:18 +00:00
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
property CurrentKey: TObject read GetCurrentKey;
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
2004-07-29 06:33:18 +00:00
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
{
|
|
|
|
:$ Base hash implementation for string keys.
|
|
|
|
}
|
|
|
|
TX2CustomStringHash = class(TX2CustomHash)
|
2005-08-26 10:25:39 +00:00
|
|
|
protected
|
2010-03-12 12:27:49 +00:00
|
|
|
function GetCurrentKey: String;
|
|
|
|
private
|
|
|
|
function GetKeyManager: TX2HashStringManager;
|
2005-06-30 12:18:53 +00:00
|
|
|
protected
|
2010-03-12 12:27:49 +00:00
|
|
|
function CreateKeyManager: TX2CustomHashManager; override;
|
|
|
|
function Find(const AKey: String; const AAllowCreate: Boolean): PX2HashValue; overload;
|
|
|
|
|
|
|
|
property KeyManager: TX2HashStringManager read GetKeyManager;
|
2005-06-30 12:18:53 +00:00
|
|
|
public
|
2010-03-12 12:27:49 +00:00
|
|
|
function GetEnumerator: TX2HashStringEnumerator;
|
2005-12-28 19:15:17 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function Exists(const AKey: String): Boolean; overload;
|
|
|
|
function Delete(const AKey: String): Boolean; overload;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
property CurrentKey: String read GetCurrentKey;
|
2004-07-29 06:33:18 +00:00
|
|
|
end;
|
2009-02-25 10:51:58 +00:00
|
|
|
{$IFDEF D2005PLUS}
|
2005-12-28 19:15:17 +00:00
|
|
|
{$ENDREGION}
|
2004-08-20 11:18:01 +00:00
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-12-28 19:15:17 +00:00
|
|
|
{$REGION 'Concrete hash classes'}
|
2007-06-13 07:26:50 +00:00
|
|
|
{$ENDIF}
|
2004-08-20 11:18:01 +00:00
|
|
|
{
|
2005-06-30 12:18:53 +00:00
|
|
|
:$ Pointer-to-Pointer hash.
|
2004-08-20 11:18:01 +00:00
|
|
|
}
|
2005-06-30 12:18:53 +00:00
|
|
|
TX2PPHash = class(TX2CustomPointerHash)
|
2005-08-26 10:25:39 +00:00
|
|
|
protected
|
2010-03-12 12:27:49 +00:00
|
|
|
function GetCurrentValue: Pointer;
|
2005-06-30 12:18:53 +00:00
|
|
|
function GetValue(Key: Pointer): Pointer;
|
|
|
|
procedure SetValue(Key: Pointer; const Value: Pointer);
|
2010-03-12 12:27:49 +00:00
|
|
|
private
|
|
|
|
function GetValueManager: TX2HashPointerManager;
|
2004-08-20 13:03:07 +00:00
|
|
|
protected
|
2010-03-12 12:27:49 +00:00
|
|
|
function CreateValueManager: TX2CustomHashManager; override;
|
|
|
|
|
|
|
|
property ValueManager: TX2HashPointerManager read GetValueManager;
|
2005-06-30 12:18:53 +00:00
|
|
|
public
|
2010-03-12 12:27:49 +00:00
|
|
|
property CurrentValue: Pointer read GetCurrentValue;
|
|
|
|
property Values[Key: Pointer]: Pointer read GetValue write SetValue; default;
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
2004-08-20 11:18:01 +00:00
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
{
|
|
|
|
:$ Pointer-to-Integer hash.
|
|
|
|
}
|
|
|
|
TX2PIHash = class(TX2CustomPointerHash)
|
2005-08-26 10:25:39 +00:00
|
|
|
protected
|
2010-03-12 12:27:49 +00:00
|
|
|
function GetCurrentValue: Integer;
|
2005-06-30 12:18:53 +00:00
|
|
|
function GetValue(Key: Pointer): Integer;
|
|
|
|
procedure SetValue(Key: Pointer; const Value: Integer);
|
2010-03-12 12:27:49 +00:00
|
|
|
private
|
|
|
|
function GetValueManager: TX2HashIntegerManager;
|
2005-06-30 12:18:53 +00:00
|
|
|
protected
|
2010-03-12 12:27:49 +00:00
|
|
|
function CreateValueManager: TX2CustomHashManager; override;
|
|
|
|
|
|
|
|
property ValueManager: TX2HashIntegerManager read GetValueManager;
|
2004-08-20 11:18:01 +00:00
|
|
|
public
|
2010-03-12 12:27:49 +00:00
|
|
|
property CurrentValue: Integer read GetCurrentValue;
|
|
|
|
property Values[Key: Pointer]: Integer read GetValue write SetValue; default;
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
2004-08-20 11:18:01 +00:00
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
{
|
|
|
|
:$ Pointer-to-Object hash.
|
|
|
|
}
|
|
|
|
TX2POHash = class(TX2CustomPointerHash)
|
2005-08-26 10:25:39 +00:00
|
|
|
protected
|
2010-03-12 12:27:49 +00:00
|
|
|
function GetCurrentValue: TObject;
|
|
|
|
function GetOwnsObjects: Boolean;
|
2005-06-30 12:18:53 +00:00
|
|
|
procedure SetOwnsObjects(const Value: Boolean);
|
|
|
|
function GetValue(Key: Pointer): TObject;
|
|
|
|
procedure SetValue(Key: Pointer; const Value: TObject);
|
2010-03-12 12:27:49 +00:00
|
|
|
private
|
|
|
|
function GetValueManager: TX2HashObjectManager;
|
2005-06-30 12:18:53 +00:00
|
|
|
protected
|
2010-03-12 12:27:49 +00:00
|
|
|
function CreateValueManager: TX2CustomHashManager; override;
|
|
|
|
|
|
|
|
property ValueManager: TX2HashObjectManager read GetValueManager;
|
2005-06-30 12:18:53 +00:00
|
|
|
public
|
|
|
|
constructor Create(const AOwnsObjects: Boolean = False); reintroduce;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
property CurrentValue: TObject read GetCurrentValue;
|
|
|
|
property OwnsObjects: Boolean read GetOwnsObjects write SetOwnsObjects;
|
|
|
|
property Values[Key: Pointer]: TObject read GetValue write SetValue; default;
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
{
|
|
|
|
:$ Pointer-to-String hash.
|
|
|
|
}
|
|
|
|
TX2PSHash = class(TX2CustomPointerHash)
|
2005-08-26 10:25:39 +00:00
|
|
|
protected
|
2010-03-12 12:27:49 +00:00
|
|
|
function GetCurrentValue: String;
|
2005-06-30 12:18:53 +00:00
|
|
|
function GetValue(Key: Pointer): String;
|
|
|
|
procedure SetValue(Key: Pointer; const Value: String);
|
2010-03-12 12:27:49 +00:00
|
|
|
private
|
|
|
|
function GetValueManager: TX2HashStringManager;
|
2005-06-30 12:18:53 +00:00
|
|
|
protected
|
2010-03-12 12:27:49 +00:00
|
|
|
function CreateValueManager: TX2CustomHashManager; override;
|
|
|
|
|
|
|
|
property ValueManager: TX2HashStringManager read GetValueManager;
|
2005-06-30 12:18:53 +00:00
|
|
|
public
|
2010-03-12 12:27:49 +00:00
|
|
|
property CurrentValue: String read GetCurrentValue;
|
|
|
|
property Values[Key: Pointer]: String read GetValue write SetValue; default;
|
2004-08-20 11:18:01 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
{
|
|
|
|
:$ Integer-to-Pointer hash.
|
|
|
|
}
|
|
|
|
TX2IPHash = class(TX2CustomIntegerHash)
|
2005-08-26 10:25:39 +00:00
|
|
|
protected
|
2010-03-12 12:27:49 +00:00
|
|
|
function GetCurrentValue: Pointer;
|
2005-06-30 12:18:53 +00:00
|
|
|
function GetValue(Key: Integer): Pointer;
|
|
|
|
procedure SetValue(Key: Integer; const Value: Pointer);
|
2010-03-12 12:27:49 +00:00
|
|
|
private
|
|
|
|
function GetValueManager: TX2HashPointerManager;
|
2005-06-30 12:18:53 +00:00
|
|
|
protected
|
2010-03-12 12:27:49 +00:00
|
|
|
function CreateValueManager: TX2CustomHashManager; override;
|
|
|
|
|
|
|
|
property ValueManager: TX2HashPointerManager read GetValueManager;
|
2005-06-30 12:18:53 +00:00
|
|
|
public
|
2010-03-12 12:27:49 +00:00
|
|
|
property CurrentValue: Pointer read GetCurrentValue;
|
|
|
|
property Values[Key: Integer]: Pointer read GetValue write SetValue; default;
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
{
|
|
|
|
:$ Integer-to-Integer hash.
|
|
|
|
}
|
|
|
|
TX2IIHash = class(TX2CustomIntegerHash)
|
2005-08-26 10:25:39 +00:00
|
|
|
protected
|
2010-03-12 12:27:49 +00:00
|
|
|
function GetCurrentValue: Integer;
|
2005-06-30 12:18:53 +00:00
|
|
|
function GetValue(Key: Integer): Integer;
|
|
|
|
procedure SetValue(Key: Integer; const Value: Integer);
|
2010-03-12 12:27:49 +00:00
|
|
|
private
|
|
|
|
function GetValueManager: TX2HashIntegerManager;
|
2005-06-30 12:18:53 +00:00
|
|
|
protected
|
2010-03-12 12:27:49 +00:00
|
|
|
function CreateValueManager: TX2CustomHashManager; override;
|
|
|
|
|
|
|
|
property ValueManager: TX2HashIntegerManager read GetValueManager;
|
2005-06-30 12:18:53 +00:00
|
|
|
public
|
2010-03-12 12:27:49 +00:00
|
|
|
property CurrentValue: Integer read GetCurrentValue;
|
|
|
|
property Values[Key: Integer]: Integer read GetValue write SetValue; default;
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
2004-07-29 06:33:18 +00:00
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2004-07-29 06:33:18 +00:00
|
|
|
{
|
2005-06-30 12:18:53 +00:00
|
|
|
:$ Integer-to-Object hash.
|
2004-07-29 06:33:18 +00:00
|
|
|
}
|
2005-06-30 12:18:53 +00:00
|
|
|
TX2IOHash = class(TX2CustomIntegerHash)
|
2010-03-12 12:27:49 +00:00
|
|
|
private
|
|
|
|
function GetValueManager: TX2HashObjectManager;
|
2005-08-26 10:25:39 +00:00
|
|
|
protected
|
2010-03-12 12:27:49 +00:00
|
|
|
function GetCurrentValue: TObject;
|
|
|
|
function GetOwnsObjects: Boolean;
|
2005-06-30 12:18:53 +00:00
|
|
|
procedure SetOwnsObjects(const Value: Boolean);
|
|
|
|
function GetValue(Key: Integer): TObject;
|
|
|
|
procedure SetValue(Key: Integer; const Value: TObject);
|
2004-08-20 13:03:07 +00:00
|
|
|
protected
|
2010-03-12 12:27:49 +00:00
|
|
|
function CreateValueManager: TX2CustomHashManager; override;
|
|
|
|
|
|
|
|
property ValueManager: TX2HashObjectManager read GetValueManager;
|
2005-06-30 12:18:53 +00:00
|
|
|
public
|
|
|
|
constructor Create(const AOwnsObjects: Boolean = False); reintroduce;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
property CurrentValue: TObject read GetCurrentValue;
|
|
|
|
property OwnsObjects: Boolean read GetOwnsObjects write SetOwnsObjects;
|
|
|
|
property Values[Key: Integer]: TObject read GetValue write SetValue; default;
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
2004-07-29 06:33:18 +00:00
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
{
|
|
|
|
:$ Integer-to-String hash.
|
|
|
|
}
|
|
|
|
TX2ISHash = class(TX2CustomIntegerHash)
|
2010-03-12 12:27:49 +00:00
|
|
|
private
|
|
|
|
function GetValueManager: TX2HashStringManager;
|
2005-08-26 10:25:39 +00:00
|
|
|
protected
|
2010-03-12 12:27:49 +00:00
|
|
|
function GetCurrentValue: String;
|
2005-06-30 12:18:53 +00:00
|
|
|
function GetValue(Key: Integer): String;
|
|
|
|
procedure SetValue(Key: Integer; const Value: String);
|
2004-07-29 06:33:18 +00:00
|
|
|
protected
|
2010-03-12 12:27:49 +00:00
|
|
|
function CreateValueManager: TX2CustomHashManager; override;
|
|
|
|
|
|
|
|
property ValueManager: TX2HashStringManager read GetValueManager;
|
2004-07-29 06:33:18 +00:00
|
|
|
public
|
2010-03-12 12:27:49 +00:00
|
|
|
property CurrentValue: String read GetCurrentValue;
|
|
|
|
property Values[Key: Integer]: String read GetValue write SetValue; default;
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
2004-07-29 06:33:18 +00:00
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
{
|
|
|
|
:$ Object-to-Pointer hash.
|
|
|
|
}
|
|
|
|
TX2OPHash = class(TX2CustomObjectHash)
|
2010-03-12 12:27:49 +00:00
|
|
|
private
|
|
|
|
function GetValueManager: TX2HashPointerManager;
|
2005-08-26 10:25:39 +00:00
|
|
|
protected
|
2010-03-12 12:27:49 +00:00
|
|
|
function GetCurrentValue: Pointer;
|
2005-06-30 12:18:53 +00:00
|
|
|
function GetValue(Key: TObject): Pointer;
|
|
|
|
procedure SetValue(Key: TObject; const Value: Pointer);
|
|
|
|
protected
|
2010-03-12 12:27:49 +00:00
|
|
|
function CreateValueManager: TX2CustomHashManager; override;
|
|
|
|
|
|
|
|
property ValueManager: TX2HashPointerManager read GetValueManager;
|
2005-06-30 12:18:53 +00:00
|
|
|
public
|
2010-03-12 12:27:49 +00:00
|
|
|
property CurrentValue: Pointer read GetCurrentValue;
|
|
|
|
property Values[Key: TObject]: Pointer read GetValue write SetValue; default;
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
2004-07-29 06:33:18 +00:00
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
{
|
|
|
|
:$ Object-to-Integer hash.
|
|
|
|
}
|
|
|
|
TX2OIHash = class(TX2CustomObjectHash)
|
2010-03-12 12:27:49 +00:00
|
|
|
private
|
|
|
|
function GetValueManager: TX2HashIntegerManager;
|
2005-08-26 10:25:39 +00:00
|
|
|
protected
|
2010-03-12 12:27:49 +00:00
|
|
|
function GetCurrentValue: Integer;
|
2005-06-30 12:18:53 +00:00
|
|
|
function GetValue(Key: TObject): Integer;
|
|
|
|
procedure SetValue(Key: TObject; const Value: Integer);
|
|
|
|
protected
|
2010-03-12 12:27:49 +00:00
|
|
|
function CreateValueManager: TX2CustomHashManager; override;
|
|
|
|
|
|
|
|
property ValueManager: TX2HashIntegerManager read GetValueManager;
|
2005-06-30 12:18:53 +00:00
|
|
|
public
|
2010-03-12 12:27:49 +00:00
|
|
|
property CurrentValue: Integer read GetCurrentValue;
|
|
|
|
property Values[Key: TObject]: Integer read GetValue write SetValue; default;
|
2004-07-29 06:33:18 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2004-08-20 13:03:07 +00:00
|
|
|
{
|
2005-06-30 12:18:53 +00:00
|
|
|
:$ Object-to-Object hash.
|
2004-08-20 13:03:07 +00:00
|
|
|
}
|
2005-06-30 12:18:53 +00:00
|
|
|
TX2OOHash = class(TX2CustomObjectHash)
|
2010-03-12 12:27:49 +00:00
|
|
|
private
|
|
|
|
function GetValueManager: TX2HashObjectManager;
|
2005-08-26 10:25:39 +00:00
|
|
|
protected
|
2010-03-12 12:27:49 +00:00
|
|
|
function GetCurrentValue: TObject;
|
|
|
|
function GetOwnsObjects: Boolean;
|
2005-06-30 12:18:53 +00:00
|
|
|
procedure SetOwnsObjects(const Value: Boolean);
|
|
|
|
function GetValue(Key: TObject): TObject;
|
|
|
|
procedure SetValue(Key: TObject; const Value: TObject);
|
2004-08-20 13:03:07 +00:00
|
|
|
protected
|
2010-03-12 12:27:49 +00:00
|
|
|
function CreateValueManager: TX2CustomHashManager; override;
|
|
|
|
|
|
|
|
property ValueManager: TX2HashObjectManager read GetValueManager;
|
2005-06-30 12:18:53 +00:00
|
|
|
public
|
|
|
|
constructor Create(const AOwnsObjects: Boolean = False); reintroduce;
|
2004-08-20 13:03:07 +00:00
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
property CurrentValue: TObject read GetCurrentValue;
|
|
|
|
property OwnsObjects: Boolean read GetOwnsObjects write SetOwnsObjects;
|
|
|
|
property Values[Key: TObject]: TObject read GetValue write SetValue; default;
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
{
|
|
|
|
:$ Object-to-String hash.
|
|
|
|
}
|
|
|
|
TX2OSHash = class(TX2CustomObjectHash)
|
2010-03-12 12:27:49 +00:00
|
|
|
private
|
|
|
|
function GetValueManager: TX2HashStringManager;
|
2005-08-26 10:25:39 +00:00
|
|
|
protected
|
2010-03-12 12:27:49 +00:00
|
|
|
function GetCurrentValue: String;
|
2005-06-30 12:18:53 +00:00
|
|
|
function GetValue(Key: TObject): String;
|
|
|
|
procedure SetValue(Key: TObject; const Value: String);
|
|
|
|
protected
|
2010-03-12 12:27:49 +00:00
|
|
|
function CreateValueManager: TX2CustomHashManager; override;
|
|
|
|
|
|
|
|
property ValueManager: TX2HashStringManager read GetValueManager;
|
2005-06-30 12:18:53 +00:00
|
|
|
public
|
2010-03-12 12:27:49 +00:00
|
|
|
property CurrentValue: String read GetCurrentValue;
|
|
|
|
property Values[Key: TObject]: String read GetValue write SetValue; default;
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
{
|
|
|
|
:$ String-to-Pointer hash.
|
|
|
|
}
|
|
|
|
TX2SPHash = class(TX2CustomStringHash)
|
2010-03-12 12:27:49 +00:00
|
|
|
private
|
|
|
|
function GetValueManager: TX2HashPointerManager;
|
2005-08-26 10:25:39 +00:00
|
|
|
protected
|
2010-03-12 12:27:49 +00:00
|
|
|
function GetCurrentValue: Pointer;
|
2005-06-30 12:18:53 +00:00
|
|
|
function GetValue(Key: String): Pointer;
|
|
|
|
procedure SetValue(Key: String; const Value: Pointer);
|
|
|
|
protected
|
2010-03-12 12:27:49 +00:00
|
|
|
function CreateValueManager: TX2CustomHashManager; override;
|
|
|
|
|
|
|
|
property ValueManager: TX2HashPointerManager read GetValueManager;
|
2005-06-30 12:18:53 +00:00
|
|
|
public
|
2010-03-12 12:27:49 +00:00
|
|
|
property CurrentValue: Pointer read GetCurrentValue;
|
|
|
|
property Values[Key: String]: Pointer read GetValue write SetValue; default;
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
{
|
|
|
|
:$ String-to-Integer hash.
|
|
|
|
}
|
|
|
|
TX2SIHash = class(TX2CustomStringHash)
|
2010-03-12 12:27:49 +00:00
|
|
|
private
|
|
|
|
function GetValueManager: TX2HashIntegerManager;
|
2005-08-26 10:25:39 +00:00
|
|
|
protected
|
2010-03-12 12:27:49 +00:00
|
|
|
function GetCurrentValue: Integer;
|
2005-06-30 12:18:53 +00:00
|
|
|
function GetValue(Key: String): Integer;
|
|
|
|
procedure SetValue(Key: String; const Value: Integer);
|
|
|
|
protected
|
2010-03-12 12:27:49 +00:00
|
|
|
function CreateValueManager: TX2CustomHashManager; override;
|
|
|
|
|
|
|
|
property ValueManager: TX2HashIntegerManager read GetValueManager;
|
2005-06-30 12:18:53 +00:00
|
|
|
public
|
2010-03-12 12:27:49 +00:00
|
|
|
property CurrentValue: Integer read GetCurrentValue;
|
|
|
|
property Values[Key: String]: Integer read GetValue write SetValue; default;
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
{
|
|
|
|
:$ String-to-Object hash.
|
|
|
|
}
|
|
|
|
TX2SOHash = class(TX2CustomStringHash)
|
2010-03-12 12:27:49 +00:00
|
|
|
private
|
|
|
|
function GetValueManager: TX2HashObjectManager;
|
2005-08-26 10:25:39 +00:00
|
|
|
protected
|
2010-03-12 12:27:49 +00:00
|
|
|
function GetCurrentValue: TObject;
|
|
|
|
function GetOwnsObjects: Boolean;
|
2005-06-30 12:18:53 +00:00
|
|
|
procedure SetOwnsObjects(const Value: Boolean);
|
|
|
|
function GetValue(Key: String): TObject;
|
|
|
|
procedure SetValue(Key: String; const Value: TObject);
|
|
|
|
protected
|
2010-03-12 12:27:49 +00:00
|
|
|
function CreateValueManager: TX2CustomHashManager; override;
|
|
|
|
|
|
|
|
property ValueManager: TX2HashObjectManager read GetValueManager;
|
2005-06-30 12:18:53 +00:00
|
|
|
public
|
|
|
|
constructor Create(const AOwnsObjects: Boolean = False); reintroduce;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
property CurrentValue: TObject read GetCurrentValue;
|
|
|
|
property OwnsObjects: Boolean read GetOwnsObjects write SetOwnsObjects;
|
|
|
|
property Values[Key: String]: TObject read GetValue write SetValue; default;
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
{
|
|
|
|
:$ String-to-String hash.
|
|
|
|
}
|
|
|
|
TX2SSHash = class(TX2CustomStringHash)
|
2010-03-12 12:27:49 +00:00
|
|
|
private
|
|
|
|
function GetValueManager: TX2HashStringManager;
|
2005-08-26 10:25:39 +00:00
|
|
|
protected
|
2010-03-12 12:27:49 +00:00
|
|
|
function GetCurrentValue: String;
|
2005-06-30 12:18:53 +00:00
|
|
|
function GetValue(Key: String): String;
|
|
|
|
procedure SetValue(Key: String; const Value: String);
|
2004-08-20 13:03:07 +00:00
|
|
|
protected
|
2010-03-12 12:27:49 +00:00
|
|
|
function CreateValueManager: TX2CustomHashManager; override;
|
|
|
|
|
|
|
|
property ValueManager: TX2HashStringManager read GetValueManager;
|
2004-08-20 13:03:07 +00:00
|
|
|
public
|
2010-03-12 12:27:49 +00:00
|
|
|
property CurrentValue: String read GetCurrentValue;
|
|
|
|
property Values[Key: String]: String read GetValue write SetValue; default;
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
2009-02-25 10:51:58 +00:00
|
|
|
{$IFDEF D2005PLUS}
|
2005-12-28 19:15:17 +00:00
|
|
|
{$ENDREGION}
|
2007-06-13 07:26:50 +00:00
|
|
|
{$ENDIF}
|
2005-06-30 12:18:53 +00:00
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
implementation
|
|
|
|
const
|
|
|
|
HIDBucket = 1;
|
|
|
|
HIDValue = 2;
|
|
|
|
|
|
|
|
CRC32Poly = $edb88320;
|
|
|
|
|
|
|
|
var
|
|
|
|
CRC32Table: array[Byte] of Cardinal;
|
|
|
|
|
|
|
|
|
|
|
|
{========================================
|
|
|
|
CRC32
|
|
|
|
========================================}
|
2010-03-12 12:27:49 +00:00
|
|
|
procedure CRC32Init;
|
2005-06-30 12:18:53 +00:00
|
|
|
var
|
|
|
|
iItem: Integer;
|
|
|
|
iPoly: Integer;
|
|
|
|
iValue: Cardinal;
|
|
|
|
|
|
|
|
begin
|
|
|
|
for iItem := 255 downto 0 do
|
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
iValue := iItem;
|
2005-06-30 12:18:53 +00:00
|
|
|
|
|
|
|
for iPoly := 8 downto 1 do
|
|
|
|
if (iValue and $1) <> 0 then
|
2010-03-12 12:27:49 +00:00
|
|
|
iValue := (iValue shr $1) xor CRC32Poly
|
2005-06-30 12:18:53 +00:00
|
|
|
else
|
2010-03-12 12:27:49 +00:00
|
|
|
iValue := iValue shr $1;
|
2005-06-30 12:18:53 +00:00
|
|
|
|
|
|
|
CRC32Table[iItem] := iValue;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2013-12-30 09:31:32 +00:00
|
|
|
function CRC32(const AKey: Pointer; const ASize: Cardinal): Cardinal; overload;
|
2005-06-30 12:18:53 +00:00
|
|
|
var
|
|
|
|
iByte: Integer;
|
|
|
|
pByte: ^Byte;
|
|
|
|
|
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := $FFFFFFFF;
|
|
|
|
pByte := AKey;
|
2005-06-30 12:18:53 +00:00
|
|
|
|
|
|
|
for iByte := Pred(ASize) downto 0 do
|
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := (((Result shr 8) and $00FFFFFF) xor
|
2005-06-30 12:18:53 +00:00
|
|
|
(CRC32Table[(Result xor pByte^) and $FF]));
|
|
|
|
Inc(pByte);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2013-12-30 09:31:32 +00:00
|
|
|
function CRC32(const AKey: string): Cardinal; overload;
|
|
|
|
begin
|
|
|
|
Result := CRC32(PChar(AKey), Length(AKey) * SizeOf(Char));
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2009-02-25 10:51:58 +00:00
|
|
|
{$IFDEF D2005PLUS}
|
2005-12-28 19:15:17 +00:00
|
|
|
{$REGION 'Internal hash structures'}
|
2007-06-13 07:26:50 +00:00
|
|
|
{$ENDIF}
|
2005-06-30 12:18:53 +00:00
|
|
|
{========================================
|
|
|
|
TX2HashCursor
|
|
|
|
========================================}
|
|
|
|
constructor TX2HashCursor.Create(const ABucket: PX2HashBucket);
|
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
inherited Create;
|
2005-06-30 12:18:53 +00:00
|
|
|
|
|
|
|
SetLength(FBucketPath, 1);
|
|
|
|
with FBucketPath[0] do
|
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Bucket := ABucket;
|
|
|
|
Index := 0;
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
FCurrent := nil;
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
|
|
|
function TX2HashCursor.GetCurrent: PX2HashValue;
|
2005-06-30 12:18:53 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := FCurrent;
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
procedure TX2HashCursor.First;
|
2005-06-30 12:18:53 +00:00
|
|
|
begin
|
|
|
|
if Length(FBucketPath) > 1 then
|
|
|
|
SetLength(FBucketPath, 1);
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
FBucketPath[0].Index := 0;
|
|
|
|
FCurrent := nil;
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
|
|
|
function TX2HashCursor.Next: Boolean;
|
2005-06-30 12:18:53 +00:00
|
|
|
var
|
|
|
|
bFound: Boolean;
|
|
|
|
iIndex: Integer;
|
|
|
|
pBucket: PX2HashBucket;
|
|
|
|
pItem: PX2HashItem;
|
|
|
|
|
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := False;
|
|
|
|
iIndex := High(FBucketPath);
|
2005-06-30 12:18:53 +00:00
|
|
|
if iIndex = -1 then
|
|
|
|
exit;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
if Assigned(FCurrent) and Assigned(FCurrent^.Next) then
|
2005-06-30 12:18:53 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
FCurrent := FCurrent^.Next;
|
|
|
|
Result := True;
|
2005-06-30 12:18:53 +00:00
|
|
|
exit;
|
|
|
|
end;
|
|
|
|
|
|
|
|
repeat
|
|
|
|
pBucket := FBucketPath[iIndex].Bucket;
|
2010-03-12 12:27:49 +00:00
|
|
|
bFound := False;
|
2005-06-30 12:18:53 +00:00
|
|
|
|
|
|
|
while FBucketPath[iIndex].Index < LeafSize do
|
|
|
|
begin
|
|
|
|
pItem := pBucket^.Items[FBucketPath[iIndex].Index];
|
|
|
|
|
|
|
|
if pItem = nil then
|
|
|
|
Inc(FBucketPath[iIndex].Index)
|
|
|
|
else
|
|
|
|
case pItem^.ID of
|
|
|
|
HIDBucket:
|
|
|
|
begin
|
|
|
|
// Bucket, continue down the path
|
|
|
|
Inc(iIndex);
|
|
|
|
SetLength(FBucketPath, iIndex + 1);
|
|
|
|
with FBucketPath[iIndex] do
|
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Bucket := PX2HashBucket(pItem);
|
|
|
|
Index := 0;
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
2010-03-12 12:27:49 +00:00
|
|
|
bFound := True;
|
2005-06-30 12:18:53 +00:00
|
|
|
break;
|
|
|
|
end;
|
|
|
|
HIDValue:
|
|
|
|
begin
|
|
|
|
// Got a value
|
2010-03-12 12:27:49 +00:00
|
|
|
FCurrent := PX2HashValue(pItem);
|
|
|
|
Result := True;
|
2005-06-30 12:18:53 +00:00
|
|
|
Inc(FBucketPath[iIndex].Index);
|
|
|
|
exit;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
if not bFound then
|
|
|
|
// Nothing found
|
|
|
|
if iIndex > 0 then
|
|
|
|
begin
|
|
|
|
// Go up in the bucket path
|
|
|
|
SetLength(FBucketPath, iIndex);
|
|
|
|
Dec(iIndex);
|
|
|
|
Inc(FBucketPath[iIndex].Index);
|
|
|
|
end else
|
|
|
|
// No more items
|
|
|
|
break;
|
|
|
|
until False;
|
|
|
|
end;
|
2009-02-25 10:51:58 +00:00
|
|
|
{$IFDEF D2005PLUS}
|
2005-12-28 19:15:17 +00:00
|
|
|
{$ENDREGION}
|
2005-06-30 12:18:53 +00:00
|
|
|
|
|
|
|
|
2005-12-28 19:15:17 +00:00
|
|
|
{$REGION 'Internal value managers'}
|
2007-06-13 07:26:50 +00:00
|
|
|
{$ENDIF}
|
2005-06-30 12:18:53 +00:00
|
|
|
{========================================
|
|
|
|
TX2CustomHashManager
|
|
|
|
========================================}
|
2010-03-12 12:27:49 +00:00
|
|
|
procedure TX2CustomHashManager.FreeCookie(var ACookie: Pointer);
|
2005-06-30 12:18:53 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
ACookie := nil;
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
{========================================
|
|
|
|
TX2HashPointerManager
|
|
|
|
========================================}
|
|
|
|
function TX2HashPointerManager.CreateCookie(const AValue: Pointer): PX2HashCookie;
|
2005-06-30 12:18:53 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := AValue;
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
|
|
|
function TX2HashPointerManager.GetValue(const ACookie: PX2HashCookie): Pointer;
|
2005-06-30 12:18:53 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := ACookie;
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
|
|
|
function TX2HashPointerManager.Hash(ACookie: PX2HashCookie): Cardinal;
|
|
|
|
var
|
|
|
|
value: Pointer;
|
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
value := GetValue(ACookie);
|
|
|
|
Result := CRC32(@value, SizeOf(Pointer));
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
|
|
|
function TX2HashPointerManager.Compare(const ACookie1, ACookie2: PX2HashCookie): Boolean;
|
2005-06-30 12:18:53 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := (GetValue(ACookie1) = GetValue(ACookie2));
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
|
|
|
function TX2HashPointerManager.Clone(const ACookie: PX2HashCookie): PX2HashCookie;
|
2005-06-30 12:18:53 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := ACookie;
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
{========================================
|
2010-03-12 12:27:49 +00:00
|
|
|
TX2HashIntegerManager
|
2005-06-30 12:18:53 +00:00
|
|
|
========================================}
|
2010-03-12 12:27:49 +00:00
|
|
|
function TX2HashIntegerManager.CreateCookie(const AValue: Integer): PX2HashCookie;
|
|
|
|
begin
|
|
|
|
Result := PX2HashCookie(AValue);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TX2HashIntegerManager.GetValue(const ACookie: PX2HashCookie): Integer;
|
2005-06-30 12:18:53 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := Integer(ACookie);
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
|
|
|
function TX2HashIntegerManager.Hash(ACookie: PX2HashCookie): Cardinal;
|
|
|
|
var
|
|
|
|
value: Integer;
|
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
value := GetValue(ACookie);
|
|
|
|
Result := CRC32(@value, SizeOf(Integer));
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
function TX2HashIntegerManager.Compare(const ACookie1, ACookie2: PX2HashCookie): Boolean;
|
2005-06-30 12:18:53 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := (GetValue(ACookie1) = GetValue(ACookie2));
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
|
|
|
function TX2HashIntegerManager.Clone(const ACookie: PX2HashCookie): PX2HashCookie;
|
2005-06-30 12:18:53 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := ACookie;
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
{========================================
|
|
|
|
TX2HashObjectManager
|
|
|
|
========================================}
|
2010-03-12 12:27:49 +00:00
|
|
|
procedure TX2HashObjectManager.FreeCookie(var ACookie: PX2HashCookie);
|
2005-06-30 12:18:53 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
if Assigned(ACookie) and (FOwnsObjects) then
|
|
|
|
GetValue(ACookie).Free;
|
2005-06-30 12:18:53 +00:00
|
|
|
|
|
|
|
inherited;
|
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
|
|
|
function TX2HashObjectManager.CreateCookie(const AValue: TObject): PX2HashCookie;
|
2005-06-30 12:18:53 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := PX2HashCookie(AValue);
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
|
|
|
function TX2HashObjectManager.GetValue(const ACookie: PX2HashCookie): TObject;
|
2005-06-30 12:18:53 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := TObject(ACookie);
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
function TX2HashObjectManager.Hash(ACookie: PX2HashCookie): Cardinal;
|
|
|
|
var
|
|
|
|
value: TObject;
|
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
value := GetValue(ACookie);
|
|
|
|
Result := CRC32(@value, SizeOf(TObject));
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
|
|
|
function TX2HashObjectManager.Compare(const ACookie1, ACookie2: PX2HashCookie): Boolean;
|
2005-06-30 12:18:53 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := (GetValue(ACookie1) = GetValue(ACookie2));
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
|
|
|
function TX2HashObjectManager.Clone(const ACookie: PX2HashCookie): PX2HashCookie;
|
2005-06-30 12:18:53 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := ACookie;
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
|
|
|
{========================================
|
|
|
|
TX2HashStringManager
|
|
|
|
========================================}
|
|
|
|
procedure TX2HashStringManager.FreeCookie(var ACookie: PX2HashCookie);
|
2005-06-30 12:18:53 +00:00
|
|
|
var
|
2010-03-12 12:27:49 +00:00
|
|
|
stringCookie: PX2HashStringCookie;
|
2005-06-30 12:18:53 +00:00
|
|
|
|
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
if Assigned(ACookie) then
|
|
|
|
begin
|
|
|
|
stringCookie := ACookie;
|
|
|
|
|
|
|
|
if stringCookie^.Length > 0 then
|
|
|
|
FreeMem(stringCookie^.Value, Succ(stringCookie^.Length));
|
|
|
|
|
|
|
|
Dispose(stringCookie);
|
|
|
|
end;
|
|
|
|
|
|
|
|
inherited;
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
|
|
|
function TX2HashStringManager.CreateCookie(const AValue: string): PX2HashCookie;
|
2005-06-30 12:18:53 +00:00
|
|
|
var
|
2010-03-12 12:27:49 +00:00
|
|
|
stringCookie: PX2HashStringCookie;
|
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
New(stringCookie);
|
|
|
|
stringCookie^.Length := Length(AValue);
|
2005-06-30 12:18:53 +00:00
|
|
|
|
2013-12-30 09:31:32 +00:00
|
|
|
GetMem(stringCookie^.Value, Succ(Length(AValue)) * SizeOf(Char));
|
2010-03-12 12:27:49 +00:00
|
|
|
StrPCopy(stringCookie^.Value, AValue);
|
|
|
|
|
|
|
|
Result := stringCookie;
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
|
|
|
function TX2HashStringManager.GetValue(const ACookie: PX2HashCookie): string;
|
|
|
|
var
|
|
|
|
stringCookie: PX2HashStringCookie;
|
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := '';
|
|
|
|
if Assigned(ACookie) then
|
|
|
|
begin
|
|
|
|
stringCookie := ACookie;
|
|
|
|
if stringCookie^.Length > 0 then
|
|
|
|
begin
|
|
|
|
SetLength(Result, stringCookie^.Length);
|
2013-12-30 09:31:32 +00:00
|
|
|
Move(stringCookie^.Value^, Result[1], stringCookie^.Length * SizeOf(Char));
|
2010-03-12 12:27:49 +00:00
|
|
|
end;
|
|
|
|
end;
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
function TX2HashStringManager.Hash(ACookie: PX2HashCookie): Cardinal;
|
|
|
|
var
|
|
|
|
stringCookie: PX2HashStringCookie;
|
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := 0;
|
|
|
|
if Assigned(ACookie) then
|
|
|
|
begin
|
|
|
|
stringCookie := ACookie;
|
2013-12-30 09:31:32 +00:00
|
|
|
Result := CRC32(stringCookie^.Value);
|
2010-03-12 12:27:49 +00:00
|
|
|
end;
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
function TX2HashStringManager.Compare(const ACookie1, ACookie2: PX2HashCookie): Boolean;
|
2005-06-30 12:18:53 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := (GetValue(ACookie1) = GetValue(ACookie2));
|
|
|
|
end;
|
2005-06-30 12:18:53 +00:00
|
|
|
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
function TX2HashStringManager.Clone(const ACookie: PX2HashCookie): PX2HashCookie;
|
|
|
|
begin
|
|
|
|
Result := CreateCookie(GetValue(ACookie));
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
2009-02-25 10:51:58 +00:00
|
|
|
{$IFDEF D2005PLUS}
|
2005-12-28 19:15:17 +00:00
|
|
|
{$ENDREGION}
|
2005-06-30 12:18:53 +00:00
|
|
|
|
|
|
|
|
2005-12-28 19:15:17 +00:00
|
|
|
{$REGION 'Abstract hash implementation'}
|
2007-06-13 07:26:50 +00:00
|
|
|
{$ENDIF}
|
2005-06-30 12:18:53 +00:00
|
|
|
{========================== TX2CustomHash
|
|
|
|
Initialization
|
|
|
|
========================================}
|
2010-03-12 12:27:49 +00:00
|
|
|
constructor TX2CustomHash.Create;
|
2005-06-30 12:18:53 +00:00
|
|
|
begin
|
|
|
|
inherited;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
FKeyManager := CreateKeyManager;
|
|
|
|
FValueManager := CreateValueManager;
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
|
|
|
destructor TX2CustomHash.Destroy;
|
2005-06-30 12:18:53 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Clear;
|
2005-06-30 12:18:53 +00:00
|
|
|
FreeAndNil(FValueManager);
|
|
|
|
FreeAndNil(FKeyManager);
|
|
|
|
FreeAndNil(FCursor);
|
|
|
|
|
|
|
|
inherited;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
function TX2CustomHash.CreateCursor: TX2HashCursor;
|
2005-06-30 12:18:53 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := nil;
|
2005-12-28 19:15:17 +00:00
|
|
|
if Assigned(FRoot) then
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := TX2HashCursor.Create(FRoot);
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
|
|
|
procedure TX2CustomHash.InvalidateCursor;
|
2005-06-30 12:18:53 +00:00
|
|
|
begin
|
|
|
|
FreeAndNil(FCursor);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
{========================== TX2CustomHash
|
|
|
|
Item Management
|
|
|
|
========================================}
|
|
|
|
function ROR(const AValue: Cardinal; const AShift: Byte = 8): Cardinal;
|
|
|
|
asm
|
|
|
|
MOV cl, dl
|
|
|
|
ROR eax, cl
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2005-08-26 10:25:39 +00:00
|
|
|
function TX2CustomHash.CursorRequired(const ARaiseException: Boolean): Boolean;
|
2005-06-30 12:18:53 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := True;
|
2005-06-30 12:18:53 +00:00
|
|
|
if not Assigned(FCursor) then
|
|
|
|
if Assigned(FRoot) then
|
2010-03-12 12:27:49 +00:00
|
|
|
FCursor := CreateCursor
|
2005-06-30 12:18:53 +00:00
|
|
|
else
|
2005-08-26 10:25:39 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := False;
|
2005-08-26 10:25:39 +00:00
|
|
|
if ARaiseException then
|
|
|
|
raise EX2HashNoCursor.Create('Cursor not available!');
|
|
|
|
end;
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TX2CustomHash.InternalFind(const ABucket: PX2HashBucket;
|
2010-03-12 12:27:49 +00:00
|
|
|
const AHash: Cardinal; const AKey: PX2HashCookie;
|
2005-06-30 12:18:53 +00:00
|
|
|
const AAllowCreate: Boolean;
|
|
|
|
const AExisting: PX2HashValue): PX2HashValue;
|
2010-03-12 12:27:49 +00:00
|
|
|
function CreateValue: PX2HashValue;
|
2005-06-30 12:18:53 +00:00
|
|
|
begin
|
|
|
|
if AExisting = nil then
|
|
|
|
begin
|
|
|
|
GetMem(Result, SizeOf(TX2HashValue));
|
|
|
|
FillChar(Result^, SizeOf(TX2HashValue), #0);
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
Result^.ID := HIDValue;
|
|
|
|
Result^.Key := KeyManager.Clone(AKey);
|
2005-06-30 12:18:53 +00:00
|
|
|
Inc(FCount);
|
|
|
|
end else
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := AExisting;
|
2005-06-30 12:18:53 +00:00
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
InvalidateCursor;
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
var
|
2010-03-12 12:27:49 +00:00
|
|
|
bucketCount: Integer;
|
|
|
|
bucketIndex: Integer;
|
|
|
|
bucket: PX2HashBucket;
|
|
|
|
key: Pointer;
|
|
|
|
nextValue: PX2HashValue;
|
|
|
|
value: PX2HashValue;
|
2005-06-30 12:18:53 +00:00
|
|
|
|
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := nil;
|
|
|
|
bucketIndex := (AHash and $FF);
|
2005-06-30 12:18:53 +00:00
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
if ABucket^.Items[bucketIndex] = nil then
|
2005-06-30 12:18:53 +00:00
|
|
|
begin
|
|
|
|
if AAllowCreate then
|
|
|
|
begin
|
|
|
|
// New value
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := CreateValue;
|
|
|
|
ABucket^.Items[bucketIndex] := PX2HashItem(Result);
|
2005-06-30 12:18:53 +00:00
|
|
|
Inc(ABucket^.Count);
|
|
|
|
end;
|
|
|
|
end else
|
2010-03-12 12:27:49 +00:00
|
|
|
case ABucket^.Items[bucketIndex]^.ID of
|
2005-06-30 12:18:53 +00:00
|
|
|
HIDBucket:
|
|
|
|
// Bucket, continue down
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := InternalFind(PX2HashBucket(ABucket^.Items[bucketIndex]),
|
|
|
|
ROR(AHash), AKey, AAllowCreate);
|
2005-06-30 12:18:53 +00:00
|
|
|
HIDValue:
|
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
bucketCount := 0;
|
|
|
|
value := PX2HashValue(ABucket^.Items[bucketIndex]);
|
|
|
|
while Assigned(value) do
|
2005-06-30 12:18:53 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
if KeyManager.Compare(value^.Key, AKey) then
|
2005-06-30 12:18:53 +00:00
|
|
|
begin
|
|
|
|
// Found existing key
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := value;
|
2005-06-30 12:18:53 +00:00
|
|
|
exit;
|
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
value := value^.Next;
|
|
|
|
Inc(bucketCount);
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
if AAllowCreate then
|
2010-03-12 12:27:49 +00:00
|
|
|
if (bucketCount >= BucketSize) then
|
2005-06-30 12:18:53 +00:00
|
|
|
begin
|
|
|
|
// Bucket full
|
2010-03-12 12:27:49 +00:00
|
|
|
GetMem(bucket, SizeOf(TX2HashBucket));
|
|
|
|
FillChar(bucket^, SizeOf(TX2HashBucket), #0);
|
|
|
|
bucket^.ID := HIDBucket;
|
|
|
|
bucket^.Level := ABucket^.Level + 1;
|
2005-06-30 12:18:53 +00:00
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
value := PX2HashValue(ABucket^.Items[bucketIndex]);
|
|
|
|
while Assigned(value) do
|
2005-06-30 12:18:53 +00:00
|
|
|
begin
|
|
|
|
// Transfer item
|
2010-03-12 12:27:49 +00:00
|
|
|
key := KeyManager.Clone(value^.Key);
|
|
|
|
nextValue := value^.Next;
|
|
|
|
value^.Next := nil;
|
2005-06-30 12:18:53 +00:00
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
InternalFind(bucket, ROR(KeyManager.Hash(key), bucket^.Level * 8),
|
|
|
|
key, True, value);
|
2005-06-30 12:18:53 +00:00
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
value := nextValue;
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := InternalFind(bucket, ROR(AHash), AKey, True);
|
|
|
|
ABucket^.Items[bucketIndex] := PX2HashItem(bucket);
|
2005-06-30 12:18:53 +00:00
|
|
|
end else
|
|
|
|
begin
|
|
|
|
// New value
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := CreateValue;
|
|
|
|
Result^.Next := PX2HashValue(ABucket^.Items[bucketIndex]);
|
|
|
|
ABucket^.Items[bucketIndex] := PX2HashItem(Result);
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function TX2CustomHash.InternalDelete(const ABucket: PX2HashBucket;
|
|
|
|
const AHash: Cardinal;
|
2010-03-12 12:27:49 +00:00
|
|
|
const AKey: PX2HashCookie): Boolean;
|
2005-06-30 12:18:53 +00:00
|
|
|
var
|
|
|
|
iIndex: Integer;
|
|
|
|
pBucket: PX2HashBucket;
|
|
|
|
pPrev: PX2HashValue;
|
|
|
|
pValue: PX2HashValue;
|
|
|
|
|
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := False;
|
|
|
|
iIndex := (AHash and $FF);
|
2005-06-30 12:18:53 +00:00
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
if Assigned(ABucket^.Items[iIndex]) then
|
2005-06-30 12:18:53 +00:00
|
|
|
case ABucket^.Items[iIndex]^.ID of
|
|
|
|
HIDBucket:
|
|
|
|
begin
|
|
|
|
// Bucket, continue down
|
|
|
|
pBucket := PX2HashBucket(ABucket^.Items[iIndex]);
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := InternalDelete(pBucket, ROR(AHash), AKey);
|
2005-06-30 12:18:53 +00:00
|
|
|
|
|
|
|
if pBucket^.Count = 0 then
|
|
|
|
begin
|
|
|
|
FreeMem(pBucket, SizeOf(TX2HashBucket));
|
2010-03-12 12:27:49 +00:00
|
|
|
ABucket^.Items[iIndex] := nil;
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
HIDValue:
|
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
pPrev := nil;
|
|
|
|
pValue := PX2HashValue(ABucket^.Items[iIndex]);
|
|
|
|
while Assigned(pValue) do
|
2005-06-30 12:18:53 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
if KeyManager.Compare(pValue^.Key, AKey) then
|
2005-06-30 12:18:53 +00:00
|
|
|
begin
|
|
|
|
// Found key
|
|
|
|
if pPrev = nil then
|
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
ABucket^.Items[iIndex] := PX2HashItem(pValue^.Next);
|
2005-06-30 12:18:53 +00:00
|
|
|
if ABucket^.Items[iIndex] = nil then
|
|
|
|
Dec(ABucket^.Count);
|
|
|
|
end else
|
|
|
|
pPrev^.Next := pValue^.Next;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
KeyManager.FreeCookie(pValue^.Key);
|
|
|
|
ValueManager.FreeCookie(pValue^.Value);
|
2005-06-30 12:18:53 +00:00
|
|
|
FreeMem(pValue, SizeOf(TX2HashValue));
|
|
|
|
Dec(FCount);
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := True;
|
2005-06-30 12:18:53 +00:00
|
|
|
exit;
|
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
pPrev := pValue;
|
|
|
|
pValue := pValue^.Next;
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
function TX2CustomHash.Find(const AKey: PX2HashCookie; const AAllowCreate: Boolean): PX2HashValue;
|
|
|
|
var
|
|
|
|
cookie: PX2HashCookie;
|
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := nil;
|
|
|
|
try
|
|
|
|
if not Assigned(FRoot) then
|
|
|
|
if AAllowCreate then
|
|
|
|
begin
|
|
|
|
// Create root bucket
|
|
|
|
GetMem(FRoot, SizeOf(TX2HashBucket));
|
|
|
|
FillChar(FRoot^, SizeOf(TX2HashBucket), #0);
|
|
|
|
FRoot^.ID := HIDBucket;
|
|
|
|
end else
|
|
|
|
exit;
|
2005-06-30 12:18:53 +00:00
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := InternalFind(FRoot, KeyManager.Hash(AKey), AKey, AAllowCreate);
|
|
|
|
finally
|
|
|
|
cookie := AKey;
|
|
|
|
KeyManager.FreeCookie(cookie);
|
|
|
|
end;
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
|
|
|
|
2005-07-01 11:43:59 +00:00
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
procedure TX2CustomHash.Clear;
|
2005-07-01 11:43:59 +00:00
|
|
|
procedure DestroyBucket(const ABucket: PX2HashBucket);
|
|
|
|
var
|
|
|
|
iItem: Integer;
|
|
|
|
pNext: PX2HashValue;
|
|
|
|
pValue: PX2HashValue;
|
|
|
|
|
|
|
|
begin
|
|
|
|
for iItem := Pred(LeafSize) downto 0 do
|
2010-03-12 12:27:49 +00:00
|
|
|
if Assigned(ABucket^.Items[iItem]) then
|
2005-07-01 11:43:59 +00:00
|
|
|
case ABucket^.Items[iItem].ID of
|
|
|
|
HIDBucket:
|
|
|
|
DestroyBucket(PX2HashBucket(ABucket^.Items[iItem]));
|
|
|
|
HIDValue:
|
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
pValue := PX2HashValue(ABucket^.Items[iItem]);
|
2005-07-01 11:43:59 +00:00
|
|
|
repeat
|
2010-03-12 12:27:49 +00:00
|
|
|
KeyManager.FreeCookie(pValue^.Key);
|
|
|
|
ValueManager.FreeCookie(pValue^.Value);
|
2005-07-01 11:43:59 +00:00
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
pNext := pValue^.Next;
|
2005-07-01 11:43:59 +00:00
|
|
|
FreeMem(pValue, SizeOf(TX2HashValue));
|
2010-03-12 12:27:49 +00:00
|
|
|
pValue := pNext;
|
2005-07-01 11:43:59 +00:00
|
|
|
until pValue = nil;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
FreeMem(ABucket, SizeOf(TX2HashBucket));
|
|
|
|
end;
|
|
|
|
|
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
if Assigned(FRoot) then
|
2005-07-01 11:43:59 +00:00
|
|
|
begin
|
|
|
|
DestroyBucket(FRoot);
|
2010-07-27 13:32:39 +00:00
|
|
|
InvalidateCursor;
|
2010-03-12 12:27:49 +00:00
|
|
|
FCount := 0;
|
|
|
|
FRoot := nil;
|
2005-07-01 11:43:59 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
function TX2CustomHash.Exists(const AKey: PX2HashCookie): Boolean;
|
2005-06-30 12:18:53 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := Assigned(Find(AKey, False));
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
|
|
|
function TX2CustomHash.Delete(const AKey: PX2HashCookie): Boolean;
|
|
|
|
var
|
|
|
|
cookie: PX2HashCookie;
|
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
try
|
|
|
|
Result := False;
|
|
|
|
if not Assigned(FRoot) then
|
|
|
|
exit;
|
2005-06-30 12:18:53 +00:00
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := InternalDelete(FRoot, KeyManager.Hash(AKey), AKey);
|
|
|
|
if Result then
|
|
|
|
InvalidateCursor;
|
|
|
|
finally
|
|
|
|
cookie := AKey;
|
|
|
|
KeyManager.FreeCookie(cookie);
|
|
|
|
end;
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TX2CustomHash.SetValue(const AValue: PX2HashValue;
|
|
|
|
const AData: Pointer);
|
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
ValueManager.FreeCookie(AValue^.Value);
|
2005-06-30 12:18:53 +00:00
|
|
|
AValue^.Value := AData;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
procedure TX2CustomHash.First;
|
2005-06-30 12:18:53 +00:00
|
|
|
begin
|
2005-08-26 10:25:39 +00:00
|
|
|
if not CursorRequired(False) then
|
|
|
|
exit;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
Cursor.First;
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
|
|
|
function TX2CustomHash.Next: Boolean;
|
2005-06-30 12:18:53 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := False;
|
2005-08-26 10:25:39 +00:00
|
|
|
if not CursorRequired(False) then
|
|
|
|
exit;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := Cursor.Next;
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
2009-02-25 10:51:58 +00:00
|
|
|
{$IFDEF D2005PLUS}
|
2005-12-28 19:15:17 +00:00
|
|
|
{$ENDREGION}
|
|
|
|
|
|
|
|
|
|
|
|
{$REGION 'Delphi 2006 enumerator support'}
|
2007-06-13 07:26:50 +00:00
|
|
|
{$ENDIF}
|
2005-12-28 19:15:17 +00:00
|
|
|
{========================================
|
|
|
|
TX2HashEnumerator
|
|
|
|
========================================}
|
|
|
|
constructor TX2HashEnumerator.Create(const AHash: TX2CustomHash;
|
|
|
|
const AEnumKeys: Boolean);
|
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
inherited Create;
|
2005-12-28 19:15:17 +00:00
|
|
|
|
|
|
|
FEnumKeys := AEnumKeys;
|
|
|
|
if AEnumKeys then
|
2010-03-12 12:27:49 +00:00
|
|
|
FManager := AHash.KeyManager
|
2005-12-28 19:15:17 +00:00
|
|
|
else
|
2010-03-12 12:27:49 +00:00
|
|
|
FManager := AHash.ValueManager;
|
2005-12-28 19:15:17 +00:00
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
FCursor := AHash.CreateCursor;
|
2005-12-28 19:15:17 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
|
|
|
destructor TX2HashEnumerator.Destroy;
|
2005-12-28 19:15:17 +00:00
|
|
|
begin
|
|
|
|
FreeAndNil(FCursor);
|
|
|
|
|
|
|
|
inherited;
|
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
|
|
|
function TX2HashEnumerator.GetCursor: PX2HashCookie;
|
2005-12-28 19:15:17 +00:00
|
|
|
begin
|
|
|
|
if FEnumKeys then
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := FCursor.Current^.Key
|
2005-12-28 19:15:17 +00:00
|
|
|
else
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := FCursor.Current^.Value;
|
2005-12-28 19:15:17 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
|
|
|
function TX2HashEnumerator.MoveNext: Boolean;
|
2005-12-28 19:15:17 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := False;
|
2005-12-28 19:15:17 +00:00
|
|
|
if Assigned(FCursor) then
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := FCursor.Next;
|
2005-12-28 19:15:17 +00:00
|
|
|
end;
|
2004-09-01 18:19:31 +00:00
|
|
|
|
2004-08-20 13:03:07 +00:00
|
|
|
|
2005-12-28 19:15:17 +00:00
|
|
|
{ TX2HashPointerEnumerator }
|
2010-03-12 12:27:49 +00:00
|
|
|
function TX2HashPointerEnumerator.GetCurrent: Pointer;
|
2005-12-28 19:15:17 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := TX2HashPointerManager(Manager).GetValue(Cursor);
|
2005-12-28 19:15:17 +00:00
|
|
|
end;
|
2004-09-01 18:19:31 +00:00
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-12-28 19:15:17 +00:00
|
|
|
{ TX2HashIntegerEnumerator }
|
2010-03-12 12:27:49 +00:00
|
|
|
function TX2HashIntegerEnumerator.GetCurrent: Integer;
|
2005-12-28 19:15:17 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := TX2HashIntegerManager(Manager).GetValue(Cursor);
|
2005-12-28 19:15:17 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-12-28 19:15:17 +00:00
|
|
|
{ TX2HashObjectEnumerator }
|
2010-03-12 12:27:49 +00:00
|
|
|
function TX2HashObjectEnumerator.GetCurrent: TObject;
|
2005-12-28 19:15:17 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := TX2HashObjectManager(Manager).GetValue(Cursor);
|
2005-12-28 19:15:17 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-12-28 19:15:17 +00:00
|
|
|
{ TX2HashStringEnumerator }
|
2010-03-12 12:27:49 +00:00
|
|
|
function TX2HashStringEnumerator.GetCurrent: String;
|
2005-12-28 19:15:17 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := TX2HashStringManager(Manager).GetValue(Cursor);
|
2005-12-28 19:15:17 +00:00
|
|
|
end;
|
2009-02-25 10:51:58 +00:00
|
|
|
{$IFDEF D2005PLUS}
|
2005-12-28 19:15:17 +00:00
|
|
|
{$ENDREGION}
|
|
|
|
|
|
|
|
|
|
|
|
{$REGION 'Base hash classes'}
|
2007-06-13 07:26:50 +00:00
|
|
|
{$ENDIF}
|
2005-06-30 12:18:53 +00:00
|
|
|
{========================================
|
|
|
|
TX2CustomPointerHash
|
|
|
|
========================================}
|
2010-03-12 12:27:49 +00:00
|
|
|
function TX2CustomPointerHash.CreateKeyManager: TX2CustomHashManager;
|
2005-06-30 12:18:53 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := TX2HashPointerManager.Create;
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
2004-08-20 13:03:07 +00:00
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
|
|
|
function TX2CustomPointerHash.GetCurrentKey: Pointer;
|
2005-06-30 12:18:53 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
CursorRequired;
|
|
|
|
Result := KeyManager.GetValue(Cursor.Current^.Key);
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
2004-07-29 13:48:35 +00:00
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
|
|
|
function TX2CustomPointerHash.GetEnumerator: TX2HashPointerEnumerator;
|
2005-12-28 19:15:17 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := TX2HashPointerEnumerator.Create(Self, True);
|
2005-12-28 19:15:17 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function TX2CustomPointerHash.Find(const AKey: Pointer;
|
|
|
|
const AAllowCreate: Boolean): PX2HashValue;
|
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := inherited Find(KeyManager.CreateCookie(AKey), AAllowCreate);
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
2004-07-29 13:48:35 +00:00
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function TX2CustomPointerHash.Exists(const AKey: Pointer): Boolean;
|
2004-07-29 13:48:35 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := inherited Exists(KeyManager.CreateCookie(AKey));
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
2004-07-29 13:48:35 +00:00
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function TX2CustomPointerHash.Delete(const AKey: Pointer): Boolean;
|
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := inherited Delete(KeyManager.CreateCookie(AKey));
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TX2CustomPointerHash.GetKeyManager: TX2HashPointerManager;
|
|
|
|
begin
|
|
|
|
Result := TX2HashPointerManager(inherited KeyManager);
|
2004-07-29 13:48:35 +00:00
|
|
|
end;
|
|
|
|
|
2004-07-29 06:33:18 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
{========================================
|
|
|
|
TX2CustomIntegerHash
|
2004-07-29 06:33:18 +00:00
|
|
|
========================================}
|
2010-03-12 12:27:49 +00:00
|
|
|
function TX2CustomIntegerHash.CreateKeyManager: TX2CustomHashManager;
|
2004-07-29 15:49:42 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := TX2HashIntegerManager.Create;
|
2004-07-29 13:48:35 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
|
|
|
function TX2CustomIntegerHash.GetCurrentKey: Integer;
|
2005-06-30 12:18:53 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
CursorRequired;
|
|
|
|
Result := KeyManager.GetValue(Cursor.Current^.Key);
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
2004-07-29 15:49:42 +00:00
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
|
|
|
function TX2CustomIntegerHash.GetEnumerator: TX2HashIntegerEnumerator;
|
2005-12-28 19:15:17 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := TX2HashIntegerEnumerator.Create(Self, True);
|
2005-12-28 19:15:17 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function TX2CustomIntegerHash.Find(const AKey: Integer;
|
|
|
|
const AAllowCreate: Boolean): PX2HashValue;
|
2004-07-29 06:33:18 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := inherited Find(KeyManager.CreateCookie(AKey), AAllowCreate);
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
2004-07-29 13:48:35 +00:00
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function TX2CustomIntegerHash.Exists(const AKey: Integer): Boolean;
|
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := inherited Exists(KeyManager.CreateCookie(AKey));
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
2004-07-29 15:49:42 +00:00
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function TX2CustomIntegerHash.Delete(const AKey: Integer): Boolean;
|
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := inherited Delete(KeyManager.CreateCookie(AKey));
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TX2CustomIntegerHash.GetKeyManager: TX2HashIntegerManager;
|
|
|
|
begin
|
|
|
|
Result := TX2HashIntegerManager(inherited KeyManager);
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
2004-07-29 15:49:42 +00:00
|
|
|
|
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
{========================================
|
|
|
|
TX2CustomObjectHash
|
|
|
|
========================================}
|
2010-03-12 12:27:49 +00:00
|
|
|
function TX2CustomObjectHash.CreateKeyManager: TX2CustomHashManager;
|
2005-06-30 12:18:53 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := TX2HashObjectManager.Create;
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
2004-07-29 15:49:42 +00:00
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
|
|
|
function TX2CustomObjectHash.GetCurrentKey: TObject;
|
2005-06-30 12:18:53 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
CursorRequired;
|
|
|
|
Result := KeyManager.GetValue(Cursor.Current^.Key);
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
|
|
|
function TX2CustomObjectHash.GetEnumerator: TX2HashObjectEnumerator;
|
2005-12-28 19:15:17 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := TX2HashObjectEnumerator.Create(Self, True);
|
2005-12-28 19:15:17 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function TX2CustomObjectHash.Find(const AKey: TObject;
|
|
|
|
const AAllowCreate: Boolean): PX2HashValue;
|
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := inherited Find(KeyManager.CreateCookie(AKey), AAllowCreate);
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
2004-07-29 15:49:42 +00:00
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function TX2CustomObjectHash.Exists(const AKey: TObject): Boolean;
|
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := inherited Exists(KeyManager.CreateCookie(AKey));
|
2004-07-29 06:33:18 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function TX2CustomObjectHash.Delete(const AKey: TObject): Boolean;
|
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := inherited Delete(KeyManager.CreateCookie(AKey));
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TX2CustomObjectHash.GetKeyManager: TX2HashObjectManager;
|
|
|
|
begin
|
|
|
|
Result := TX2HashObjectManager(inherited KeyManager);
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
2004-07-29 06:33:18 +00:00
|
|
|
|
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
{========================================
|
|
|
|
TX2CustomStringHash
|
2004-07-29 06:33:18 +00:00
|
|
|
========================================}
|
2010-03-12 12:27:49 +00:00
|
|
|
function TX2CustomStringHash.CreateKeyManager: TX2CustomHashManager;
|
2004-07-29 06:33:18 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := TX2HashStringManager.Create;
|
2004-07-29 06:33:18 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
|
|
|
function TX2CustomStringHash.GetCurrentKey: String;
|
2004-07-29 06:33:18 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
CursorRequired;
|
|
|
|
Result := TX2HashStringManager(KeyManager).GetValue(Cursor.Current^.Key);
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
2004-07-29 06:33:18 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
function TX2CustomStringHash.GetEnumerator: TX2HashStringEnumerator;
|
2005-12-28 19:15:17 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := TX2HashStringEnumerator.Create(Self, True);
|
2005-12-28 19:15:17 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function TX2CustomStringHash.Find(const AKey: String;
|
|
|
|
const AAllowCreate: Boolean): PX2HashValue;
|
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := inherited Find(KeyManager.CreateCookie(AKey), AAllowCreate);
|
2004-07-29 06:33:18 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function TX2CustomStringHash.Exists(const AKey: String): Boolean;
|
2004-07-29 06:33:18 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := inherited Exists(KeyManager.CreateCookie(AKey));
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
2004-07-29 06:33:18 +00:00
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function TX2CustomStringHash.Delete(const AKey: String): Boolean;
|
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := inherited Delete(KeyManager.CreateCookie(AKey));
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TX2CustomStringHash.GetKeyManager: TX2HashStringManager;
|
|
|
|
begin
|
|
|
|
Result := TX2HashStringManager(inherited KeyManager);
|
2004-07-29 06:33:18 +00:00
|
|
|
end;
|
2009-02-25 10:51:58 +00:00
|
|
|
{$IFDEF D2005PLUS}
|
2005-12-28 19:15:17 +00:00
|
|
|
{$ENDREGION}
|
2004-07-29 06:33:18 +00:00
|
|
|
|
|
|
|
|
2005-12-28 19:15:17 +00:00
|
|
|
{$REGION 'Concrete hash classes'}
|
2007-06-13 07:26:50 +00:00
|
|
|
{$ENDIF}
|
2005-06-30 12:18:53 +00:00
|
|
|
{========================================
|
|
|
|
TX2PPHash
|
2004-07-29 06:33:18 +00:00
|
|
|
========================================}
|
2010-03-12 12:27:49 +00:00
|
|
|
function TX2PPHash.CreateValueManager: TX2CustomHashManager;
|
2004-07-29 13:48:35 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := TX2HashPointerManager.Create;
|
2004-07-29 13:48:35 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
|
|
|
function TX2PPHash.GetCurrentValue: Pointer;
|
2005-06-30 12:18:53 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
CursorRequired;
|
|
|
|
Result := ValueManager.GetValue(Cursor.Current^.Value);
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function TX2PPHash.GetValue(Key: Pointer): Pointer;
|
2004-07-29 06:33:18 +00:00
|
|
|
var
|
2010-03-12 12:27:49 +00:00
|
|
|
item: PX2HashValue;
|
2004-07-29 06:33:18 +00:00
|
|
|
|
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := nil;
|
|
|
|
item := Find(Key, False);
|
|
|
|
if Assigned(item) then
|
|
|
|
Result := ValueManager.GetValue(item^.Value);
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
2004-07-29 13:48:35 +00:00
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
procedure TX2PPHash.SetValue(Key: Pointer; const Value: Pointer);
|
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
inherited SetValue(Find(Key, True), ValueManager.CreateCookie(Value));
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
2004-07-29 13:48:35 +00:00
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
|
|
|
function TX2PPHash.GetValueManager: TX2HashPointerManager;
|
|
|
|
begin
|
|
|
|
Result := TX2HashPointerManager(inherited ValueManager);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
{========================================
|
|
|
|
TX2PIHash
|
|
|
|
========================================}
|
2010-03-12 12:27:49 +00:00
|
|
|
function TX2PIHash.CreateValueManager: TX2CustomHashManager;
|
2005-06-30 12:18:53 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := TX2HashIntegerManager.Create;
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
2004-07-29 13:48:35 +00:00
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
|
|
|
function TX2PIHash.GetCurrentValue: Integer;
|
2005-06-30 12:18:53 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
CursorRequired;
|
|
|
|
Result := ValueManager.GetValue(Cursor.Current^.Value);
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
2004-07-29 13:48:35 +00:00
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function TX2PIHash.GetValue(Key: Pointer): Integer;
|
|
|
|
var
|
2010-03-12 12:27:49 +00:00
|
|
|
item: PX2HashValue;
|
2004-07-29 13:48:35 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := 0;
|
|
|
|
item := Find(Key, False);
|
|
|
|
if Assigned(item) then
|
|
|
|
Result := ValueManager.GetValue(item^.Value);
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
2004-07-29 13:48:35 +00:00
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
procedure TX2PIHash.SetValue(Key: Pointer; const Value: Integer);
|
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
inherited SetValue(Find(Key, True), ValueManager.CreateCookie(Value));
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TX2PIHash.GetValueManager: TX2HashIntegerManager;
|
|
|
|
begin
|
|
|
|
Result := TX2HashIntegerManager(inherited ValueManager);
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
2004-07-29 13:48:35 +00:00
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
{========================================
|
|
|
|
TX2POHash
|
|
|
|
========================================}
|
|
|
|
constructor TX2POHash.Create(const AOwnsObjects: Boolean);
|
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
inherited Create;
|
2005-06-30 12:18:53 +00:00
|
|
|
OwnsObjects := AOwnsObjects;
|
|
|
|
end;
|
2004-07-29 13:48:35 +00:00
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
|
|
|
function TX2POHash.CreateValueManager: TX2CustomHashManager;
|
2005-06-30 12:18:53 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := TX2HashObjectManager.Create;
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
2004-07-29 13:48:35 +00:00
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
|
|
|
function TX2POHash.GetCurrentValue: TObject;
|
2005-06-30 12:18:53 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := ValueManager.GetValue(Cursor.Current^.Value);
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
2004-07-29 13:48:35 +00:00
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
|
|
|
function TX2POHash.GetOwnsObjects: Boolean;
|
2005-06-30 12:18:53 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := ValueManager.OwnsObjects;
|
2004-07-29 06:33:18 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
procedure TX2POHash.SetOwnsObjects(const Value: Boolean);
|
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
ValueManager.OwnsObjects := Value;
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
2004-07-29 06:33:18 +00:00
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function TX2POHash.GetValue(Key: Pointer): TObject;
|
2004-07-29 13:48:35 +00:00
|
|
|
var
|
2010-03-12 12:27:49 +00:00
|
|
|
item: PX2HashValue;
|
2004-07-29 13:48:35 +00:00
|
|
|
|
2004-07-29 06:33:18 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := nil;
|
|
|
|
item := Find(Key, False);
|
|
|
|
if Assigned(item) then
|
|
|
|
Result := ValueManager.GetValue(item^.Value);
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
2004-07-29 13:48:35 +00:00
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
procedure TX2POHash.SetValue(Key: Pointer; const Value: TObject);
|
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
inherited SetValue(Find(Key, True), ValueManager.CreateCookie(Value));
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TX2POHash.GetValueManager: TX2HashObjectManager;
|
|
|
|
begin
|
|
|
|
Result := TX2HashObjectManager(inherited ValueManager);
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
2004-07-29 13:48:35 +00:00
|
|
|
|
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
{========================================
|
|
|
|
TX2PSHash
|
|
|
|
========================================}
|
2010-03-12 12:27:49 +00:00
|
|
|
function TX2PSHash.CreateValueManager: TX2CustomHashManager;
|
2005-06-30 12:18:53 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := TX2HashStringManager.Create;
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
2004-07-29 13:48:35 +00:00
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
|
|
|
function TX2PSHash.GetCurrentValue: String;
|
2005-06-30 12:18:53 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := ValueManager.GetValue(Cursor.Current^.Value);
|
2004-07-29 06:33:18 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function TX2PSHash.GetValue(Key: Pointer): String;
|
2004-09-05 13:48:19 +00:00
|
|
|
var
|
2010-03-12 12:27:49 +00:00
|
|
|
item: PX2HashValue;
|
2004-09-05 13:48:19 +00:00
|
|
|
|
2004-07-29 06:33:18 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := '';
|
|
|
|
item := Find(Key, False);
|
|
|
|
if Assigned(item) then
|
|
|
|
Result := ValueManager.GetValue(item^.Value);
|
2004-07-29 06:33:18 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
procedure TX2PSHash.SetValue(Key: Pointer; const Value: String);
|
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
inherited SetValue(Find(Key, True), ValueManager.CreateCookie(Value));
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
2004-07-29 06:33:18 +00:00
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
|
|
|
function TX2PSHash.GetValueManager: TX2HashStringManager;
|
|
|
|
begin
|
|
|
|
Result := TX2HashStringManager(inherited ValueManager);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
{========================================
|
|
|
|
TX2IPHash
|
|
|
|
========================================}
|
2010-03-12 12:27:49 +00:00
|
|
|
function TX2IPHash.CreateValueManager: TX2CustomHashManager;
|
2004-07-29 06:33:18 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := TX2HashPointerManager.Create;
|
2004-07-29 06:33:18 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
|
|
|
function TX2IPHash.GetCurrentValue: Pointer;
|
2005-06-30 12:18:53 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
CursorRequired;
|
|
|
|
Result := ValueManager.GetValue(Cursor.Current^.Value);
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
2004-07-29 06:33:18 +00:00
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function TX2IPHash.GetValue(Key: Integer): Pointer;
|
2004-07-29 06:33:18 +00:00
|
|
|
var
|
2010-03-12 12:27:49 +00:00
|
|
|
item: PX2HashValue;
|
2004-07-29 06:33:18 +00:00
|
|
|
|
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := nil;
|
|
|
|
item := Find(Key, False);
|
|
|
|
if Assigned(item) then
|
|
|
|
Result := ValueManager.GetValue(item^.Value);
|
2004-07-29 06:33:18 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
procedure TX2IPHash.SetValue(Key: Integer; const Value: Pointer);
|
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
inherited SetValue(Find(Key, True), ValueManager.CreateCookie(Value));
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TX2IPHash.GetValueManager: TX2HashPointerManager;
|
|
|
|
begin
|
|
|
|
Result := TX2HashPointerManager(inherited ValueManager);
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
2004-07-29 06:33:18 +00:00
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
{========================================
|
|
|
|
TX2IIHash
|
|
|
|
========================================}
|
2010-03-12 12:27:49 +00:00
|
|
|
function TX2IIHash.CreateValueManager: TX2CustomHashManager;
|
2004-07-29 06:33:18 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := TX2HashIntegerManager.Create;
|
2004-07-29 13:48:35 +00:00
|
|
|
end;
|
2004-07-29 06:33:18 +00:00
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
|
|
|
function TX2IIHash.GetCurrentValue: Integer;
|
2004-07-29 13:48:35 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
CursorRequired;
|
|
|
|
Result := ValueManager.GetValue(Cursor.Current^.Value);
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
2004-07-29 13:48:35 +00:00
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function TX2IIHash.GetValue(Key: Integer): Integer;
|
|
|
|
var
|
2010-03-12 12:27:49 +00:00
|
|
|
item: PX2HashValue;
|
2004-07-29 13:48:35 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := 0;
|
|
|
|
item := Find(Key, False);
|
|
|
|
if Assigned(item) then
|
|
|
|
Result := ValueManager.GetValue(item^.Value);
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
2004-07-29 13:48:35 +00:00
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
procedure TX2IIHash.SetValue(Key: Integer; const Value: Integer);
|
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
inherited SetValue(Find(Key, True), ValueManager.CreateCookie(Value));
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TX2IIHash.GetValueManager: TX2HashIntegerManager;
|
|
|
|
begin
|
|
|
|
Result := TX2HashIntegerManager(inherited ValueManager);
|
2004-07-29 13:48:35 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
{========================================
|
|
|
|
TX2IOHash
|
|
|
|
========================================}
|
|
|
|
constructor TX2IOHash.Create(const AOwnsObjects: Boolean);
|
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
inherited Create;
|
2005-06-30 12:18:53 +00:00
|
|
|
OwnsObjects := AOwnsObjects;
|
|
|
|
end;
|
2004-07-29 13:48:35 +00:00
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
|
|
|
function TX2IOHash.CreateValueManager: TX2CustomHashManager;
|
2004-07-29 13:48:35 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := TX2HashObjectManager.Create;
|
2004-07-29 06:33:18 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
function TX2IOHash.GetCurrentValue: TObject;
|
2005-06-30 12:18:53 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := ValueManager.GetValue(Cursor.Current^.Value);
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
2004-07-29 06:33:18 +00:00
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
|
|
|
function TX2IOHash.GetOwnsObjects: Boolean;
|
2004-07-29 06:33:18 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := ValueManager.OwnsObjects;
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
2004-07-29 06:33:18 +00:00
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
procedure TX2IOHash.SetOwnsObjects(const Value: Boolean);
|
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
ValueManager.OwnsObjects := Value;
|
2004-07-29 06:33:18 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function TX2IOHash.GetValue(Key: Integer): TObject;
|
2004-07-29 06:33:18 +00:00
|
|
|
var
|
2010-03-12 12:27:49 +00:00
|
|
|
item: PX2HashValue;
|
2004-07-29 06:33:18 +00:00
|
|
|
|
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := nil;
|
|
|
|
item := Find(Key, False);
|
|
|
|
if Assigned(item) then
|
|
|
|
Result := ValueManager.GetValue(item^.Value);
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
procedure TX2IOHash.SetValue(Key: Integer; const Value: TObject);
|
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
inherited SetValue(Find(Key, True), ValueManager.CreateCookie(Value));
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TX2IOHash.GetValueManager: TX2HashObjectManager;
|
|
|
|
begin
|
|
|
|
Result := TX2HashObjectManager(inherited ValueManager);
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
{========================================
|
|
|
|
TX2ISHash
|
|
|
|
========================================}
|
2010-03-12 12:27:49 +00:00
|
|
|
function TX2ISHash.CreateValueManager: TX2CustomHashManager;
|
2005-06-30 12:18:53 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := TX2HashStringManager.Create;
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
|
|
|
function TX2ISHash.GetCurrentValue: String;
|
2005-06-30 12:18:53 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := TX2HashStringManager(ValueManager).GetValue(Cursor.Current^.Value);
|
2004-07-29 06:33:18 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function TX2ISHash.GetValue(Key: Integer): String;
|
2004-07-29 06:33:18 +00:00
|
|
|
var
|
2010-03-12 12:27:49 +00:00
|
|
|
item: PX2HashValue;
|
2004-07-29 06:33:18 +00:00
|
|
|
|
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := '';
|
|
|
|
item := Find(Key, False);
|
|
|
|
if Assigned(item) then
|
|
|
|
Result := ValueManager.GetValue(item^.Value);
|
2004-07-29 06:33:18 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
procedure TX2ISHash.SetValue(Key: Integer; const Value: String);
|
2004-07-29 06:33:18 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
inherited SetValue(Find(Key, True), ValueManager.CreateCookie(Value));
|
2004-08-20 11:18:01 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
|
|
|
function TX2ISHash.GetValueManager: TX2HashStringManager;
|
|
|
|
begin
|
|
|
|
Result := TX2HashStringManager(inherited ValueManager);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
{========================================
|
|
|
|
TX2OPHash
|
2004-08-20 11:18:01 +00:00
|
|
|
========================================}
|
2010-03-12 12:27:49 +00:00
|
|
|
function TX2OPHash.CreateValueManager: TX2CustomHashManager;
|
2004-08-20 11:18:01 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := TX2HashPointerManager.Create;
|
2004-08-20 11:18:01 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
|
|
|
function TX2OPHash.GetCurrentValue: Pointer;
|
2004-08-20 11:18:01 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
CursorRequired;
|
|
|
|
Result := ValueManager.GetValue(Cursor.Current^.Value);
|
2004-08-20 11:18:01 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function TX2OPHash.GetValue(Key: TObject): Pointer;
|
|
|
|
var
|
2010-03-12 12:27:49 +00:00
|
|
|
item: PX2HashValue;
|
2005-06-30 12:18:53 +00:00
|
|
|
|
2004-08-20 11:18:01 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := nil;
|
|
|
|
item := Find(Key, False);
|
|
|
|
if Assigned(item) then
|
|
|
|
Result := ValueManager.GetValue(item^.Value);
|
2004-07-29 06:33:18 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
procedure TX2OPHash.SetValue(Key: TObject; const Value: Pointer);
|
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
inherited SetValue(Find(Key, True), ValueManager.CreateCookie(Value));
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TX2OPHash.GetValueManager: TX2HashPointerManager;
|
|
|
|
begin
|
|
|
|
Result := TX2HashPointerManager(inherited ValueManager);
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
2004-07-29 06:33:18 +00:00
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
{========================================
|
|
|
|
TX2OIHash
|
2004-07-29 06:33:18 +00:00
|
|
|
========================================}
|
2010-03-12 12:27:49 +00:00
|
|
|
function TX2OIHash.CreateValueManager: TX2CustomHashManager;
|
2004-07-29 06:33:18 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := TX2HashIntegerManager.Create;
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
2004-07-29 06:33:18 +00:00
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
|
|
|
function TX2OIHash.GetCurrentValue: Integer;
|
2005-06-30 12:18:53 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
CursorRequired;
|
|
|
|
Result := ValueManager.GetValue(Cursor.Current^.Value);
|
2004-07-29 06:33:18 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function TX2OIHash.GetValue(Key: TObject): Integer;
|
2004-07-29 06:33:18 +00:00
|
|
|
var
|
2010-03-12 12:27:49 +00:00
|
|
|
item: PX2HashValue;
|
2004-07-29 06:33:18 +00:00
|
|
|
|
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := 0;
|
|
|
|
item := Find(Key, False);
|
|
|
|
if Assigned(item) then
|
|
|
|
Result := ValueManager.GetValue(item^.Value);
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
procedure TX2OIHash.SetValue(Key: TObject; const Value: Integer);
|
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
inherited SetValue(Find(Key, True), ValueManager.CreateCookie(Value));
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TX2OIHash.GetValueManager: TX2HashIntegerManager;
|
|
|
|
begin
|
|
|
|
Result := TX2HashIntegerManager(inherited ValueManager);
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
{========================================
|
|
|
|
TX2OOHash
|
|
|
|
========================================}
|
|
|
|
constructor TX2OOHash.Create(const AOwnsObjects: Boolean);
|
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
inherited Create;
|
2005-06-30 12:18:53 +00:00
|
|
|
OwnsObjects := AOwnsObjects;
|
2004-07-29 06:33:18 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
|
|
|
function TX2OOHash.CreateValueManager: TX2CustomHashManager;
|
2005-06-30 12:18:53 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := TX2HashObjectManager.Create;
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
|
|
|
function TX2OOHash.GetCurrentValue: TObject;
|
2005-06-30 12:18:53 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := ValueManager.GetValue(Cursor.Current^.Value);
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
|
|
|
function TX2OOHash.GetOwnsObjects: Boolean;
|
2005-06-30 12:18:53 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := ValueManager.OwnsObjects;
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
procedure TX2OOHash.SetOwnsObjects(const Value: Boolean);
|
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
TX2HashObjectManager(ValueManager).OwnsObjects := Value;
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function TX2OOHash.GetValue(Key: TObject): TObject;
|
2004-07-29 06:33:18 +00:00
|
|
|
var
|
2010-03-12 12:27:49 +00:00
|
|
|
item: PX2HashValue;
|
2004-07-29 06:33:18 +00:00
|
|
|
|
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := nil;
|
|
|
|
item := Find(Key, False);
|
|
|
|
if Assigned(item) then
|
|
|
|
Result := ValueManager.GetValue(item^.Value);
|
2004-07-29 06:33:18 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
procedure TX2OOHash.SetValue(Key: TObject; const Value: TObject);
|
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
inherited SetValue(Find(Key, True), ValueManager.CreateCookie(Value));
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TX2OOHash.GetValueManager: TX2HashObjectManager;
|
|
|
|
begin
|
|
|
|
Result := TX2HashObjectManager(inherited ValueManager);
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
2004-07-29 06:33:18 +00:00
|
|
|
|
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
{========================================
|
|
|
|
TX2OSHash
|
|
|
|
========================================}
|
2010-03-12 12:27:49 +00:00
|
|
|
function TX2OSHash.CreateValueManager: TX2CustomHashManager;
|
2004-07-29 06:33:18 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := TX2HashStringManager.Create;
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
2004-07-29 06:33:18 +00:00
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
|
|
|
function TX2OSHash.GetCurrentValue: String;
|
2005-06-30 12:18:53 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := ValueManager.GetValue(Cursor.Current^.Value);
|
2004-07-29 06:33:18 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function TX2OSHash.GetValue(Key: TObject): String;
|
2004-07-29 06:33:18 +00:00
|
|
|
var
|
2010-03-12 12:27:49 +00:00
|
|
|
item: PX2HashValue;
|
2004-07-29 06:33:18 +00:00
|
|
|
|
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := '';
|
|
|
|
item := Find(Key, False);
|
|
|
|
if Assigned(item) then
|
|
|
|
Result := ValueManager.GetValue(item^.Value);
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
2004-07-29 06:33:18 +00:00
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
procedure TX2OSHash.SetValue(Key: TObject; const Value: String);
|
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
inherited SetValue(Find(Key, True), ValueManager.CreateCookie(Value));
|
2004-07-29 06:33:18 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
|
|
|
function TX2OSHash.GetValueManager: TX2HashStringManager;
|
|
|
|
begin
|
|
|
|
Result := TX2HashStringManager(inherited ValueManager);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
{========================================
|
|
|
|
TX2SPHash
|
|
|
|
========================================}
|
2010-03-12 12:27:49 +00:00
|
|
|
function TX2SPHash.CreateValueManager: TX2CustomHashManager;
|
2005-06-30 12:18:53 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := TX2HashPointerManager.Create;
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
2004-07-29 06:33:18 +00:00
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
|
|
|
function TX2SPHash.GetCurrentValue: Pointer;
|
2004-07-29 06:33:18 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
CursorRequired;
|
|
|
|
Result := ValueManager.GetValue(Cursor.Current^.Value);
|
2004-07-29 06:33:18 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function TX2SPHash.GetValue(Key: String): Pointer;
|
|
|
|
var
|
2010-03-12 12:27:49 +00:00
|
|
|
item: PX2HashValue;
|
2004-08-20 13:03:07 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := nil;
|
|
|
|
item := Find(Key, False);
|
|
|
|
if Assigned(item) then
|
|
|
|
Result := ValueManager.GetValue(item^.Value);
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
procedure TX2SPHash.SetValue(Key: String; const Value: Pointer);
|
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
inherited SetValue(Find(Key, True), ValueManager.CreateCookie(Value));
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TX2SPHash.GetValueManager: TX2HashPointerManager;
|
|
|
|
begin
|
|
|
|
Result := TX2HashPointerManager(inherited ValueManager);
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
{========================================
|
|
|
|
TX2SIHash
|
2004-08-20 13:03:07 +00:00
|
|
|
========================================}
|
2010-03-12 12:27:49 +00:00
|
|
|
function TX2SIHash.CreateValueManager: TX2CustomHashManager;
|
2004-09-01 18:19:31 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := TX2HashIntegerManager.Create;
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
2004-09-01 18:19:31 +00:00
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
|
|
|
function TX2SIHash.GetCurrentValue: Integer;
|
2005-06-30 12:18:53 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
CursorRequired;
|
|
|
|
Result := ValueManager.GetValue(Cursor.Current^.Value);
|
2004-09-01 18:19:31 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function TX2SIHash.GetValue(Key: String): Integer;
|
|
|
|
var
|
2010-03-12 12:27:49 +00:00
|
|
|
item: PX2HashValue;
|
2005-06-30 12:18:53 +00:00
|
|
|
|
2004-09-01 18:19:31 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := 0;
|
|
|
|
item := Find(Key, False);
|
|
|
|
if Assigned(item) then
|
|
|
|
Result := ValueManager.GetValue(item^.Value);
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
procedure TX2SIHash.SetValue(Key: String; const Value: Integer);
|
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
inherited SetValue(Find(Key, True), ValueManager.CreateCookie(Value));
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TX2SIHash.GetValueManager: TX2HashIntegerManager;
|
|
|
|
begin
|
|
|
|
Result := TX2HashIntegerManager(inherited ValueManager);
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
2004-09-01 18:19:31 +00:00
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
{========================================
|
|
|
|
TX2SOHash
|
|
|
|
========================================}
|
|
|
|
constructor TX2SOHash.Create(const AOwnsObjects: Boolean);
|
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
inherited Create;
|
2005-06-30 12:18:53 +00:00
|
|
|
OwnsObjects := AOwnsObjects;
|
2004-09-01 18:19:31 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
|
|
|
function TX2SOHash.CreateValueManager: TX2CustomHashManager;
|
2005-06-30 12:18:53 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := TX2HashObjectManager.Create;
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
2004-09-01 18:19:31 +00:00
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
|
|
|
function TX2SOHash.GetCurrentValue: TObject;
|
2004-08-20 13:03:07 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := ValueManager.GetValue(Cursor.Current^.Value);
|
2004-08-20 13:03:07 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
|
|
|
function TX2SOHash.GetOwnsObjects: Boolean;
|
2004-08-20 13:03:07 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := ValueManager.OwnsObjects;
|
2004-08-20 13:03:07 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
procedure TX2SOHash.SetOwnsObjects(const Value: Boolean);
|
2004-08-20 13:03:07 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
TX2HashObjectManager(ValueManager).OwnsObjects := Value;
|
2004-08-20 13:03:07 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function TX2SOHash.GetValue(Key: String): TObject;
|
2004-08-20 13:03:07 +00:00
|
|
|
var
|
2010-03-12 12:27:49 +00:00
|
|
|
item: PX2HashValue;
|
2004-08-20 13:03:07 +00:00
|
|
|
|
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := nil;
|
|
|
|
item := Find(Key, False);
|
|
|
|
if Assigned(item) then
|
|
|
|
Result := ValueManager.GetValue(item^.Value);
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
2004-08-20 13:03:07 +00:00
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
procedure TX2SOHash.SetValue(Key: String; const Value: TObject);
|
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
inherited SetValue(Find(Key, True), ValueManager.CreateCookie(Value));
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TX2SOHash.GetValueManager: TX2HashObjectManager;
|
|
|
|
begin
|
|
|
|
Result := TX2HashObjectManager(inherited ValueManager);
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
2004-08-20 13:03:07 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
|
|
|
|
{========================================
|
|
|
|
TX2SSHash
|
|
|
|
========================================}
|
2010-03-12 12:27:49 +00:00
|
|
|
function TX2SSHash.CreateValueManager: TX2CustomHashManager;
|
2005-06-30 12:18:53 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := TX2HashStringManager.Create;
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
|
|
|
function TX2SSHash.GetCurrentValue: String;
|
2005-06-30 12:18:53 +00:00
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := ValueManager.GetValue(Cursor.Current^.Value);
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function TX2SSHash.GetValue(Key: String): String;
|
|
|
|
var
|
2010-03-12 12:27:49 +00:00
|
|
|
item: PX2HashValue;
|
2005-06-30 12:18:53 +00:00
|
|
|
|
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
Result := '';
|
|
|
|
item := Find(Key, False);
|
|
|
|
if Assigned(item) then
|
|
|
|
Result := ValueManager.GetValue(item^.Value);
|
2004-08-20 13:03:07 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-12 12:27:49 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
procedure TX2SSHash.SetValue(Key: String; const Value: String);
|
|
|
|
begin
|
2010-03-12 12:27:49 +00:00
|
|
|
inherited SetValue(Find(Key, True), ValueManager.CreateCookie(Value));
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TX2SSHash.GetValueManager: TX2HashStringManager;
|
|
|
|
begin
|
|
|
|
Result := TX2HashStringManager(inherited ValueManager);
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
2009-02-25 10:51:58 +00:00
|
|
|
{$IFDEF D2005PLUS}
|
2005-12-28 19:15:17 +00:00
|
|
|
{$ENDREGION}
|
2007-06-13 07:26:50 +00:00
|
|
|
{$ENDIF}
|
2005-12-28 19:15:17 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
|
|
|
|
initialization
|
2010-03-12 12:27:49 +00:00
|
|
|
CRC32Init;
|
2005-06-30 12:18:53 +00:00
|
|
|
|
2004-07-29 06:33:18 +00:00
|
|
|
end.
|
2010-03-12 12:27:49 +00:00
|
|
|
|