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
|
|
|
}
|
2004-08-20 13:03:07 +00:00
|
|
|
PX2HashItem = ^TX2HashItem;
|
|
|
|
TX2HashItem = record
|
2005-06-30 12:18:53 +00:00
|
|
|
ID: Cardinal;
|
|
|
|
end;
|
|
|
|
|
|
|
|
PX2HashBucket = ^TX2HashBucket;
|
|
|
|
TX2HashBucket = record
|
|
|
|
ID: Cardinal;
|
|
|
|
Level: Integer;
|
|
|
|
Count: Integer;
|
|
|
|
Items: array[0..Pred(LeafSize)] of PX2HashItem;
|
|
|
|
end;
|
|
|
|
|
|
|
|
PX2HashValue = ^TX2HashValue;
|
|
|
|
TX2HashValue = record
|
|
|
|
ID: Cardinal;
|
|
|
|
Next: PX2HashValue;
|
|
|
|
Key: Pointer;
|
|
|
|
Value: Pointer;
|
|
|
|
end;
|
|
|
|
|
|
|
|
TX2BucketPath = record
|
|
|
|
Bucket: PX2HashBucket;
|
|
|
|
Index: Integer;
|
2004-07-29 06:33:18 +00:00
|
|
|
end;
|
|
|
|
|
2004-07-29 13:48:35 +00:00
|
|
|
{
|
2005-06-30 12:18:53 +00:00
|
|
|
:$ Default cursor implementation.
|
|
|
|
|
|
|
|
:: Traverses the hash trie 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
|
|
|
|
FBucketPath: array of TX2BucketPath;
|
|
|
|
FCurrent: PX2HashValue;
|
|
|
|
protected
|
|
|
|
function GetCurrent(): PX2HashValue; virtual;
|
|
|
|
public
|
|
|
|
constructor Create(const ABucket: PX2HashBucket); virtual;
|
|
|
|
|
|
|
|
procedure First(); virtual;
|
|
|
|
function Next(): Boolean; virtual;
|
|
|
|
|
|
|
|
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
|
|
|
|
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.
|
|
|
|
}
|
|
|
|
TX2CustomHashManager = class(TObject)
|
2005-12-28 19:15:17 +00:00
|
|
|
protected
|
2005-06-30 12:18:53 +00:00
|
|
|
procedure Initialize(var AData: Pointer); virtual;
|
|
|
|
procedure Finalize(var AData: Pointer); virtual;
|
2004-07-29 06:33:18 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function DataSize(const AData: Pointer): Cardinal; virtual;
|
|
|
|
function DataPointer(const AData: Pointer): Pointer; virtual;
|
|
|
|
|
|
|
|
function ToPointer(const AValue: Pointer; const ASize: Cardinal): Pointer; overload; virtual;
|
|
|
|
function ToValue(const AData: Pointer; var AValue): Cardinal; overload; virtual;
|
|
|
|
|
|
|
|
function Compare(const AData: Pointer; const AValue: Pointer;
|
|
|
|
const ASize: Cardinal): Boolean; virtual;
|
|
|
|
end;
|
|
|
|
|
|
|
|
TX2HashPointerManager = class(TX2CustomHashManager)
|
2005-12-28 19:15:17 +00:00
|
|
|
protected
|
2005-06-30 12:18:53 +00:00
|
|
|
function ToPointer(const AValue: Pointer): Pointer; overload;
|
|
|
|
function ToValue(const AData: Pointer): Pointer; overload;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{
|
|
|
|
:$ 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
|
2005-06-30 12:18:53 +00:00
|
|
|
function ToPointer(const AValue: Integer): Pointer; overload;
|
|
|
|
function ToValue(const AData: Pointer): Integer; overload;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{
|
|
|
|
:$ Object value class.
|
|
|
|
}
|
|
|
|
TX2HashObjectManager = class(TX2CustomHashManager)
|
2004-07-29 06:33:18 +00:00
|
|
|
private
|
2005-06-30 12:18:53 +00:00
|
|
|
FOwnsObjects: Boolean;
|
2005-12-28 19:15:17 +00:00
|
|
|
protected
|
2005-06-30 12:18:53 +00:00
|
|
|
procedure Finalize(var AData: Pointer); override;
|
2004-07-29 06:33:18 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function ToPointer(const AValue: TObject): Pointer; overload;
|
|
|
|
function ToValue(const AData: Pointer): TObject; overload;
|
2004-07-29 06:33:18 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
property OwnsObjects: Boolean read FOwnsObjects write FOwnsObjects;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{
|
|
|
|
:$ String value class.
|
|
|
|
}
|
|
|
|
TX2HashStringManager = class(TX2CustomHashManager)
|
2005-12-28 19:15:17 +00:00
|
|
|
protected
|
2005-06-30 12:18:53 +00:00
|
|
|
procedure Finalize(var AData: Pointer); override;
|
2004-07-29 06:33:18 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function DataSize(const AData: Pointer): Cardinal; override;
|
|
|
|
function DataPointer(const AData: Pointer): Pointer; override;
|
2004-07-29 06:33:18 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function ToPointer(const AValue: Pointer; const ASize: Cardinal): Pointer; override;
|
|
|
|
function ToValue(const AData: Pointer; var AValue): Cardinal; override;
|
|
|
|
function ToPointer(const AValue: String): Pointer; overload;
|
|
|
|
function ToValue(const AData: Pointer): String; overload;
|
2004-07-29 06:33:18 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function Compare(const AData: Pointer; const AValue: Pointer;
|
|
|
|
const ASize: Cardinal): Boolean; override;
|
|
|
|
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
|
|
|
{
|
|
|
|
:$ Base enumerator class.
|
|
|
|
}
|
|
|
|
TX2HashEnumerator = class(TObject)
|
|
|
|
private
|
|
|
|
FCursor: TX2HashCursor;
|
|
|
|
FManager: TX2CustomHashManager;
|
|
|
|
FEnumKeys: Boolean;
|
|
|
|
|
|
|
|
function GetCursor(): Pointer;
|
|
|
|
protected
|
|
|
|
property Manager: TX2CustomHashManager read FManager;
|
|
|
|
property Cursor: Pointer read GetCursor;
|
|
|
|
public
|
|
|
|
constructor Create(const AHash: TX2CustomHash;
|
|
|
|
const AEnumKeys: Boolean);
|
|
|
|
destructor Destroy(); override;
|
|
|
|
|
|
|
|
function MoveNext(): Boolean;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{
|
|
|
|
:$ Enumerator for pointer values.
|
|
|
|
}
|
|
|
|
TX2HashPointerEnumerator = class(TX2HashEnumerator)
|
|
|
|
private
|
|
|
|
function GetCurrent: Pointer;
|
|
|
|
public
|
|
|
|
property Current: Pointer read GetCurrent;
|
|
|
|
end;
|
2004-07-29 06:33:18 +00:00
|
|
|
|
2005-12-28 19:15:17 +00:00
|
|
|
{
|
|
|
|
:$ Enumerator for integer values.
|
|
|
|
}
|
|
|
|
TX2HashIntegerEnumerator = class(TX2HashEnumerator)
|
|
|
|
private
|
|
|
|
function GetCurrent: Integer;
|
|
|
|
public
|
|
|
|
property Current: Integer read GetCurrent;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{
|
|
|
|
:$ Enumerator for object values.
|
|
|
|
}
|
|
|
|
TX2HashObjectEnumerator = class(TX2HashEnumerator)
|
|
|
|
private
|
|
|
|
function GetCurrent: TObject;
|
|
|
|
public
|
|
|
|
property Current: TObject read GetCurrent;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{
|
|
|
|
:$ Enumerator for string values
|
|
|
|
}
|
|
|
|
TX2HashStringEnumerator = class(TX2HashEnumerator)
|
|
|
|
private
|
|
|
|
function GetCurrent(): String;
|
|
|
|
public
|
|
|
|
property Current: String read GetCurrent;
|
|
|
|
end;
|
2009-02-25 10:51:58 +00:00
|
|
|
{$IFDEF D2005PLUS}
|
2005-12-28 19:15:17 +00:00
|
|
|
{$ENDREGION}
|
|
|
|
|
|
|
|
{$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
|
|
|
|
function CreateCursor(): TX2HashCursor; virtual;
|
|
|
|
function CreateKeyManager(): TX2CustomHashManager; virtual; abstract;
|
|
|
|
function CreateValueManager(): TX2CustomHashManager; virtual; abstract;
|
|
|
|
procedure InvalidateCursor();
|
|
|
|
|
|
|
|
function Hash(const AKey: Pointer; const ASize: Cardinal): Cardinal; virtual;
|
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;
|
|
|
|
const AHash: Cardinal; const AKey: Pointer;
|
|
|
|
const ASize: Cardinal;
|
|
|
|
const AAllowCreate: Boolean;
|
|
|
|
const AExisting: PX2HashValue = nil): PX2HashValue;
|
|
|
|
function InternalDelete(const ABucket: PX2HashBucket;
|
|
|
|
const AHash: Cardinal; const AKey: Pointer;
|
|
|
|
const ASize: Cardinal): Boolean;
|
|
|
|
|
|
|
|
function Find(const AKey: Pointer; const ASize: Cardinal;
|
|
|
|
const AAllowCreate: Boolean): PX2HashValue; overload;
|
|
|
|
function Exists(const AKey: Pointer; const ASize: Cardinal): Boolean; overload;
|
|
|
|
function Delete(const AKey: Pointer; const ASize: Cardinal): Boolean; overload;
|
|
|
|
|
|
|
|
procedure SetValue(const AValue: PX2HashValue; const AData: Pointer);
|
|
|
|
|
|
|
|
property Cursor: TX2HashCursor read FCursor;
|
|
|
|
property KeyManager: TX2CustomHashManager read FKeyManager;
|
|
|
|
property ValueManager: TX2CustomHashManager read FValueManager;
|
2004-07-29 06:33:18 +00:00
|
|
|
public
|
2005-06-30 12:18:53 +00:00
|
|
|
constructor Create(); virtual;
|
|
|
|
destructor Destroy(); override;
|
2004-07-29 13:48:35 +00:00
|
|
|
|
2005-07-01 11:43:59 +00:00
|
|
|
procedure Clear();
|
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
procedure First();
|
|
|
|
function Next(): Boolean;
|
2004-07-29 06:33:18 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
property Count: Integer read FCount;
|
|
|
|
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 '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
|
|
|
|
function GetCurrentKey(): Pointer;
|
|
|
|
protected
|
|
|
|
function CreateKeyManager(): TX2CustomHashManager; override;
|
|
|
|
function Find(const AKey: Pointer;
|
|
|
|
const AAllowCreate: Boolean): PX2HashValue; overload;
|
|
|
|
public
|
2005-12-28 19:15:17 +00:00
|
|
|
function GetEnumerator(): TX2HashPointerEnumerator;
|
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function Exists(const AKey: Pointer): Boolean; overload;
|
|
|
|
function Delete(const AKey: Pointer): Boolean; overload;
|
|
|
|
|
|
|
|
property CurrentKey: Pointer read GetCurrentKey;
|
2004-07-29 06:33:18 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
{
|
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
|
|
|
|
function GetCurrentKey(): Integer;
|
2004-08-20 13:03:07 +00:00
|
|
|
protected
|
2005-06-30 12:18:53 +00:00
|
|
|
function CreateKeyManager(): TX2CustomHashManager; override;
|
|
|
|
function Find(const AKey: Integer;
|
|
|
|
const AAllowCreate: Boolean): PX2HashValue; overload;
|
|
|
|
public
|
2005-12-28 19:15:17 +00:00
|
|
|
function GetEnumerator(): TX2HashIntegerEnumerator;
|
|
|
|
|
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
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
property CurrentKey: Integer read GetCurrentKey;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{
|
|
|
|
:$ Base hash implementation for object keys.
|
|
|
|
}
|
|
|
|
TX2CustomObjectHash = class(TX2CustomHash)
|
|
|
|
private
|
|
|
|
function GetCurrentKey(): TObject;
|
|
|
|
protected
|
|
|
|
function CreateKeyManager(): TX2CustomHashManager; override;
|
|
|
|
function Find(const AKey: TObject;
|
|
|
|
const AAllowCreate: Boolean): PX2HashValue; overload;
|
2004-07-29 06:33:18 +00:00
|
|
|
public
|
2005-12-28 19:15:17 +00:00
|
|
|
function GetEnumerator(): TX2HashObjectEnumerator;
|
|
|
|
|
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
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
property CurrentKey: TObject read GetCurrentKey;
|
|
|
|
end;
|
2004-07-29 06:33:18 +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
|
2005-06-30 12:18:53 +00:00
|
|
|
function GetCurrentKey(): String;
|
|
|
|
protected
|
|
|
|
function CreateKeyManager(): TX2CustomHashManager; override;
|
|
|
|
function Find(const AKey: String;
|
|
|
|
const AAllowCreate: Boolean): PX2HashValue; overload;
|
|
|
|
public
|
2005-12-28 19:15:17 +00:00
|
|
|
function GetEnumerator(): TX2HashStringEnumerator;
|
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function Exists(const AKey: String): Boolean; overload;
|
|
|
|
function Delete(const AKey: String): Boolean; overload;
|
|
|
|
|
|
|
|
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
|
|
|
|
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
|
2005-06-30 12:18:53 +00:00
|
|
|
function GetCurrentValue(): Pointer;
|
|
|
|
function GetValue(Key: Pointer): Pointer;
|
|
|
|
procedure SetValue(Key: Pointer; const Value: Pointer);
|
2004-08-20 13:03:07 +00:00
|
|
|
protected
|
2005-06-30 12:18:53 +00:00
|
|
|
function CreateValueManager(): TX2CustomHashManager; override;
|
|
|
|
public
|
|
|
|
property CurrentValue: Pointer read GetCurrentValue;
|
|
|
|
property Values[Key: Pointer]: Pointer read GetValue write SetValue; default;
|
|
|
|
end;
|
2004-08-20 11:18:01 +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
|
2004-08-20 11:18:01 +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);
|
|
|
|
protected
|
|
|
|
function CreateValueManager(): TX2CustomHashManager; override;
|
2004-08-20 11:18:01 +00:00
|
|
|
public
|
2005-06-30 12:18:53 +00:00
|
|
|
property CurrentValue: Integer read GetCurrentValue;
|
|
|
|
property Values[Key: Pointer]: Integer read GetValue write SetValue; default;
|
|
|
|
end;
|
2004-08-20 11:18:01 +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
|
2005-06-30 12:18:53 +00:00
|
|
|
function GetCurrentValue(): TObject;
|
|
|
|
function GetOwnsObjects(): Boolean;
|
|
|
|
procedure SetOwnsObjects(const Value: Boolean);
|
|
|
|
function GetValue(Key: Pointer): TObject;
|
|
|
|
procedure SetValue(Key: Pointer; const Value: TObject);
|
|
|
|
protected
|
|
|
|
function CreateValueManager(): TX2CustomHashManager; override;
|
|
|
|
public
|
|
|
|
constructor Create(const AOwnsObjects: Boolean = False); reintroduce;
|
|
|
|
|
|
|
|
property CurrentValue: TObject read GetCurrentValue;
|
|
|
|
property OwnsObjects: Boolean read GetOwnsObjects write SetOwnsObjects;
|
|
|
|
property Values[Key: Pointer]: TObject read GetValue write SetValue; default;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{
|
|
|
|
:$ Pointer-to-String hash.
|
|
|
|
}
|
|
|
|
TX2PSHash = class(TX2CustomPointerHash)
|
2005-08-26 10:25:39 +00:00
|
|
|
protected
|
2005-06-30 12:18:53 +00:00
|
|
|
function GetCurrentValue(): String;
|
|
|
|
function GetValue(Key: Pointer): String;
|
|
|
|
procedure SetValue(Key: Pointer; const Value: String);
|
|
|
|
protected
|
|
|
|
function CreateValueManager(): TX2CustomHashManager; override;
|
|
|
|
public
|
|
|
|
property CurrentValue: String read GetCurrentValue;
|
|
|
|
property Values[Key: Pointer]: String read GetValue write SetValue; default;
|
2004-08-20 11:18:01 +00:00
|
|
|
end;
|
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
{
|
|
|
|
:$ Integer-to-Pointer hash.
|
|
|
|
}
|
|
|
|
TX2IPHash = class(TX2CustomIntegerHash)
|
2005-08-26 10:25:39 +00:00
|
|
|
protected
|
2005-06-30 12:18:53 +00:00
|
|
|
function GetCurrentValue(): Pointer;
|
|
|
|
function GetValue(Key: Integer): Pointer;
|
|
|
|
procedure SetValue(Key: Integer; const Value: Pointer);
|
|
|
|
protected
|
|
|
|
function CreateValueManager(): TX2CustomHashManager; override;
|
|
|
|
public
|
|
|
|
property CurrentValue: Pointer read GetCurrentValue;
|
|
|
|
property Values[Key: Integer]: Pointer read GetValue write SetValue; default;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{
|
|
|
|
:$ Integer-to-Integer hash.
|
|
|
|
}
|
|
|
|
TX2IIHash = class(TX2CustomIntegerHash)
|
2005-08-26 10:25:39 +00:00
|
|
|
protected
|
2005-06-30 12:18:53 +00:00
|
|
|
function GetCurrentValue(): Integer;
|
|
|
|
function GetValue(Key: Integer): Integer;
|
|
|
|
procedure SetValue(Key: Integer; const Value: Integer);
|
|
|
|
protected
|
|
|
|
function CreateValueManager(): TX2CustomHashManager; override;
|
|
|
|
public
|
|
|
|
property CurrentValue: Integer read GetCurrentValue;
|
|
|
|
property Values[Key: Integer]: Integer read GetValue write SetValue; default;
|
|
|
|
end;
|
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)
|
2005-08-26 10:25:39 +00:00
|
|
|
protected
|
2005-06-30 12:18:53 +00:00
|
|
|
function GetCurrentValue(): TObject;
|
|
|
|
function GetOwnsObjects(): Boolean;
|
|
|
|
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
|
2005-06-30 12:18:53 +00:00
|
|
|
function CreateValueManager(): TX2CustomHashManager; override;
|
|
|
|
public
|
|
|
|
constructor Create(const AOwnsObjects: Boolean = False); reintroduce;
|
|
|
|
|
|
|
|
property CurrentValue: TObject read GetCurrentValue;
|
|
|
|
property OwnsObjects: Boolean read GetOwnsObjects write SetOwnsObjects;
|
|
|
|
property Values[Key: Integer]: TObject read GetValue write SetValue; default;
|
|
|
|
end;
|
2004-07-29 06:33:18 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
{
|
|
|
|
:$ Integer-to-String hash.
|
|
|
|
}
|
|
|
|
TX2ISHash = class(TX2CustomIntegerHash)
|
2005-08-26 10:25:39 +00:00
|
|
|
protected
|
2004-07-29 06:33:18 +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
|
2005-06-30 12:18:53 +00:00
|
|
|
function CreateValueManager(): TX2CustomHashManager; override;
|
2004-07-29 06:33:18 +00:00
|
|
|
public
|
2005-06-30 12:18:53 +00:00
|
|
|
property CurrentValue: String read GetCurrentValue;
|
|
|
|
property Values[Key: Integer]: String read GetValue write SetValue; default;
|
|
|
|
end;
|
2004-07-29 06:33:18 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
{
|
|
|
|
:$ Object-to-Pointer hash.
|
|
|
|
}
|
|
|
|
TX2OPHash = class(TX2CustomObjectHash)
|
2005-08-26 10:25:39 +00:00
|
|
|
protected
|
2005-06-30 12:18:53 +00:00
|
|
|
function GetCurrentValue(): Pointer;
|
|
|
|
function GetValue(Key: TObject): Pointer;
|
|
|
|
procedure SetValue(Key: TObject; const Value: Pointer);
|
|
|
|
protected
|
|
|
|
function CreateValueManager(): TX2CustomHashManager; override;
|
|
|
|
public
|
|
|
|
property CurrentValue: Pointer read GetCurrentValue;
|
|
|
|
property Values[Key: TObject]: Pointer read GetValue write SetValue; default;
|
|
|
|
end;
|
2004-07-29 06:33:18 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
{
|
|
|
|
:$ Object-to-Integer hash.
|
|
|
|
}
|
|
|
|
TX2OIHash = class(TX2CustomObjectHash)
|
2005-08-26 10:25:39 +00:00
|
|
|
protected
|
2005-06-30 12:18:53 +00:00
|
|
|
function GetCurrentValue(): Integer;
|
|
|
|
function GetValue(Key: TObject): Integer;
|
|
|
|
procedure SetValue(Key: TObject; const Value: Integer);
|
|
|
|
protected
|
|
|
|
function CreateValueManager(): TX2CustomHashManager; override;
|
|
|
|
public
|
|
|
|
property CurrentValue: Integer read GetCurrentValue;
|
|
|
|
property Values[Key: TObject]: Integer read GetValue write SetValue; default;
|
2004-07-29 06:33:18 +00:00
|
|
|
end;
|
|
|
|
|
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)
|
2005-08-26 10:25:39 +00:00
|
|
|
protected
|
2005-06-30 12:18:53 +00:00
|
|
|
function GetCurrentValue(): TObject;
|
|
|
|
function GetOwnsObjects(): Boolean;
|
|
|
|
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
|
2005-06-30 12:18:53 +00:00
|
|
|
function CreateValueManager(): TX2CustomHashManager; override;
|
|
|
|
public
|
|
|
|
constructor Create(const AOwnsObjects: Boolean = False); reintroduce;
|
2004-08-20 13:03:07 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
property CurrentValue: TObject read GetCurrentValue;
|
|
|
|
property OwnsObjects: Boolean read GetOwnsObjects write SetOwnsObjects;
|
|
|
|
property Values[Key: TObject]: TObject read GetValue write SetValue; default;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{
|
|
|
|
:$ Object-to-String hash.
|
|
|
|
}
|
|
|
|
TX2OSHash = class(TX2CustomObjectHash)
|
2005-08-26 10:25:39 +00:00
|
|
|
protected
|
2005-06-30 12:18:53 +00:00
|
|
|
function GetCurrentValue(): String;
|
|
|
|
function GetValue(Key: TObject): String;
|
|
|
|
procedure SetValue(Key: TObject; const Value: String);
|
|
|
|
protected
|
|
|
|
function CreateValueManager(): TX2CustomHashManager; override;
|
|
|
|
public
|
|
|
|
property CurrentValue: String read GetCurrentValue;
|
|
|
|
property Values[Key: TObject]: String read GetValue write SetValue; default;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{
|
|
|
|
:$ String-to-Pointer hash.
|
|
|
|
}
|
|
|
|
TX2SPHash = class(TX2CustomStringHash)
|
2005-08-26 10:25:39 +00:00
|
|
|
protected
|
2005-06-30 12:18:53 +00:00
|
|
|
function GetCurrentValue(): Pointer;
|
|
|
|
function GetValue(Key: String): Pointer;
|
|
|
|
procedure SetValue(Key: String; const Value: Pointer);
|
|
|
|
protected
|
|
|
|
function CreateValueManager(): TX2CustomHashManager; override;
|
|
|
|
public
|
|
|
|
property CurrentValue: Pointer read GetCurrentValue;
|
|
|
|
property Values[Key: String]: Pointer read GetValue write SetValue; default;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{
|
|
|
|
:$ String-to-Integer hash.
|
|
|
|
}
|
|
|
|
TX2SIHash = class(TX2CustomStringHash)
|
2005-08-26 10:25:39 +00:00
|
|
|
protected
|
2005-06-30 12:18:53 +00:00
|
|
|
function GetCurrentValue(): Integer;
|
|
|
|
function GetValue(Key: String): Integer;
|
|
|
|
procedure SetValue(Key: String; const Value: Integer);
|
|
|
|
protected
|
|
|
|
function CreateValueManager(): TX2CustomHashManager; override;
|
|
|
|
public
|
|
|
|
property CurrentValue: Integer read GetCurrentValue;
|
|
|
|
property Values[Key: String]: Integer read GetValue write SetValue; default;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{
|
|
|
|
:$ String-to-Object hash.
|
|
|
|
}
|
|
|
|
TX2SOHash = class(TX2CustomStringHash)
|
2005-08-26 10:25:39 +00:00
|
|
|
protected
|
2004-08-20 13:03:07 +00:00
|
|
|
function GetCurrentValue(): TObject;
|
2005-06-30 12:18:53 +00:00
|
|
|
function GetOwnsObjects(): Boolean;
|
|
|
|
procedure SetOwnsObjects(const Value: Boolean);
|
|
|
|
function GetValue(Key: String): TObject;
|
|
|
|
procedure SetValue(Key: String; const Value: TObject);
|
|
|
|
protected
|
|
|
|
function CreateValueManager(): TX2CustomHashManager; override;
|
|
|
|
public
|
|
|
|
constructor Create(const AOwnsObjects: Boolean = False); reintroduce;
|
|
|
|
|
|
|
|
property CurrentValue: TObject read GetCurrentValue;
|
|
|
|
property OwnsObjects: Boolean read GetOwnsObjects write SetOwnsObjects;
|
|
|
|
property Values[Key: String]: TObject read GetValue write SetValue; default;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{
|
|
|
|
:$ String-to-String hash.
|
|
|
|
}
|
|
|
|
TX2SSHash = class(TX2CustomStringHash)
|
2005-08-26 10:25:39 +00:00
|
|
|
protected
|
2005-06-30 12:18:53 +00:00
|
|
|
function GetCurrentValue(): String;
|
|
|
|
function GetValue(Key: String): String;
|
|
|
|
procedure SetValue(Key: String; const Value: String);
|
2004-08-20 13:03:07 +00:00
|
|
|
protected
|
2005-06-30 12:18:53 +00:00
|
|
|
function CreateValueManager(): TX2CustomHashManager; override;
|
2004-08-20 13:03:07 +00:00
|
|
|
public
|
2005-06-30 12:18:53 +00:00
|
|
|
property CurrentValue: String read GetCurrentValue;
|
|
|
|
property Values[Key: String]: String read GetValue write SetValue; default;
|
|
|
|
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
|
|
|
|
|
|
|
implementation
|
|
|
|
const
|
|
|
|
HIDBucket = 1;
|
|
|
|
HIDValue = 2;
|
|
|
|
|
|
|
|
CRC32Poly = $edb88320;
|
|
|
|
|
|
|
|
var
|
|
|
|
CRC32Table: array[Byte] of Cardinal;
|
|
|
|
|
|
|
|
|
|
|
|
{========================================
|
|
|
|
CRC32
|
|
|
|
========================================}
|
|
|
|
procedure CRC32Init();
|
|
|
|
var
|
|
|
|
iItem: Integer;
|
|
|
|
iPoly: Integer;
|
|
|
|
iValue: Cardinal;
|
|
|
|
|
|
|
|
begin
|
|
|
|
for iItem := 255 downto 0 do
|
|
|
|
begin
|
|
|
|
iValue := iItem;
|
|
|
|
|
|
|
|
for iPoly := 8 downto 1 do
|
|
|
|
if (iValue and $1) <> 0 then
|
|
|
|
iValue := (iValue shr $1) xor CRC32Poly
|
|
|
|
else
|
|
|
|
iValue := iValue shr $1;
|
|
|
|
|
|
|
|
CRC32Table[iItem] := iValue;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function CRC32(const AKey: Pointer; const ASize: Cardinal): Cardinal;
|
|
|
|
var
|
|
|
|
iByte: Integer;
|
|
|
|
pByte: ^Byte;
|
|
|
|
|
|
|
|
begin
|
|
|
|
Result := $FFFFFFFF;
|
|
|
|
pByte := AKey;
|
|
|
|
|
|
|
|
for iByte := Pred(ASize) downto 0 do
|
|
|
|
begin
|
|
|
|
Result := (((Result shr 8) and $00FFFFFF) xor
|
|
|
|
(CRC32Table[(Result xor pByte^) and $FF]));
|
|
|
|
Inc(pByte);
|
|
|
|
end;
|
|
|
|
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
|
|
|
|
inherited Create();
|
|
|
|
|
|
|
|
SetLength(FBucketPath, 1);
|
|
|
|
with FBucketPath[0] do
|
|
|
|
begin
|
|
|
|
Bucket := ABucket;
|
|
|
|
Index := 0;
|
|
|
|
end;
|
|
|
|
|
|
|
|
FCurrent := nil;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TX2HashCursor.GetCurrent(): PX2HashValue;
|
|
|
|
begin
|
|
|
|
Result := FCurrent;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TX2HashCursor.First();
|
|
|
|
begin
|
|
|
|
if Length(FBucketPath) > 1 then
|
|
|
|
SetLength(FBucketPath, 1);
|
|
|
|
|
2005-10-14 09:16:53 +00:00
|
|
|
FBucketPath[0].Index := 0;
|
|
|
|
FCurrent := nil;
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TX2HashCursor.Next(): Boolean;
|
|
|
|
var
|
|
|
|
bFound: Boolean;
|
|
|
|
iIndex: Integer;
|
|
|
|
pBucket: PX2HashBucket;
|
|
|
|
pItem: PX2HashItem;
|
|
|
|
|
|
|
|
begin
|
|
|
|
Result := False;
|
|
|
|
iIndex := High(FBucketPath);
|
|
|
|
if iIndex = -1 then
|
|
|
|
exit;
|
|
|
|
|
|
|
|
if (FCurrent <> nil) and (FCurrent^.Next <> nil) then
|
|
|
|
begin
|
|
|
|
FCurrent := FCurrent^.Next;
|
|
|
|
Result := True;
|
|
|
|
exit;
|
|
|
|
end;
|
|
|
|
|
|
|
|
repeat
|
|
|
|
pBucket := FBucketPath[iIndex].Bucket;
|
|
|
|
bFound := False;
|
|
|
|
|
|
|
|
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
|
|
|
|
Bucket := PX2HashBucket(pItem);
|
|
|
|
Index := 0;
|
|
|
|
end;
|
|
|
|
bFound := True;
|
|
|
|
break;
|
|
|
|
end;
|
|
|
|
HIDValue:
|
|
|
|
begin
|
|
|
|
// Got a value
|
|
|
|
FCurrent := PX2HashValue(pItem);
|
|
|
|
Result := True;
|
|
|
|
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
|
|
|
|
========================================}
|
|
|
|
procedure TX2CustomHashManager.Initialize(var AData: Pointer);
|
|
|
|
begin
|
|
|
|
AData := nil;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TX2CustomHashManager.Finalize(var AData: Pointer);
|
|
|
|
begin
|
|
|
|
AData := nil;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TX2CustomHashManager.DataSize(const AData: Pointer): Cardinal;
|
|
|
|
begin
|
|
|
|
Result := SizeOf(Pointer);
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TX2CustomHashManager.DataPointer(const AData: Pointer): Pointer;
|
|
|
|
begin
|
|
|
|
Result := AData;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TX2CustomHashManager.ToPointer(const AValue: Pointer;
|
|
|
|
const ASize: Cardinal): Pointer;
|
|
|
|
begin
|
2005-07-01 11:43:59 +00:00
|
|
|
Result := Pointer(AValue^);
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TX2CustomHashManager.ToValue(const AData: Pointer;
|
|
|
|
var AValue): Cardinal;
|
|
|
|
begin
|
|
|
|
Result := DataSize(AData);
|
|
|
|
Pointer(AValue) := AData;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TX2CustomHashManager.Compare(const AData: Pointer; const AValue: Pointer;
|
|
|
|
const ASize: Cardinal): Boolean;
|
|
|
|
begin
|
2005-07-01 11:43:59 +00:00
|
|
|
Result := (Pointer(AValue^) = AData);
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
{========================================
|
|
|
|
TX2HashPointerManager
|
|
|
|
========================================}
|
|
|
|
function TX2HashPointerManager.ToPointer(const AValue: Pointer): Pointer;
|
|
|
|
begin
|
2005-07-01 11:43:59 +00:00
|
|
|
Result := ToPointer(@AValue, SizeOf(Pointer));
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TX2HashPointerManager.ToValue(const AData: Pointer): Pointer;
|
|
|
|
begin
|
|
|
|
ToValue(AData, Result);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
{========================================
|
|
|
|
TX2HashIntegerManager
|
|
|
|
========================================}
|
|
|
|
function TX2HashIntegerManager.ToPointer(const AValue: Integer): Pointer;
|
|
|
|
begin
|
2005-07-01 11:43:59 +00:00
|
|
|
Result := ToPointer(@AValue, SizeOf(Integer));
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TX2HashIntegerManager.ToValue(const AData: Pointer): Integer;
|
|
|
|
begin
|
|
|
|
ToValue(AData, Result);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
{========================================
|
|
|
|
TX2HashObjectManager
|
|
|
|
========================================}
|
|
|
|
procedure TX2HashObjectManager.Finalize(var AData: Pointer);
|
|
|
|
begin
|
|
|
|
if (AData <> nil) and (FOwnsObjects) then
|
|
|
|
TObject(AData).Free();
|
|
|
|
|
|
|
|
inherited;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TX2HashObjectManager.ToPointer(const AValue: TObject): Pointer;
|
|
|
|
begin
|
2005-07-01 11:43:59 +00:00
|
|
|
Result := ToPointer(@AValue, SizeOf(Integer));
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TX2HashObjectManager.ToValue(const AData: Pointer): TObject;
|
|
|
|
begin
|
|
|
|
ToValue(AData, Result);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
{========================================
|
|
|
|
TX2HashStringManager
|
|
|
|
========================================}
|
|
|
|
procedure TX2HashStringManager.Finalize(var AData: Pointer);
|
|
|
|
begin
|
|
|
|
if AData <> nil then
|
|
|
|
FreeMem(AData, PCardinal(AData)^ + SizeOf(Cardinal));
|
|
|
|
|
|
|
|
inherited;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TX2HashStringManager.DataSize(const AData: Pointer): Cardinal;
|
|
|
|
begin
|
|
|
|
Result := PCardinal(AData)^;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TX2HashStringManager.DataPointer(const AData: Pointer): Pointer;
|
|
|
|
begin
|
|
|
|
Result := AData;
|
|
|
|
Inc(PCardinal(Result));
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TX2HashStringManager.ToPointer(const AValue: Pointer;
|
|
|
|
const ASize: Cardinal): Pointer;
|
|
|
|
var
|
|
|
|
pData: Pointer;
|
|
|
|
|
|
|
|
begin
|
|
|
|
// Add a 4-byte Length to the start, emulating AnsiStrings
|
|
|
|
// (except for the reference counting)
|
|
|
|
GetMem(Result, ASize + SizeOf(Cardinal));
|
|
|
|
PCardinal(Result)^ := ASize;
|
|
|
|
pData := Result;
|
|
|
|
Inc(PCardinal(pData));
|
|
|
|
Move(AValue^, pData^, ASize);
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TX2HashStringManager.ToValue(const AData: Pointer;
|
|
|
|
var AValue): Cardinal;
|
|
|
|
var
|
|
|
|
pData: Pointer;
|
|
|
|
|
|
|
|
begin
|
|
|
|
Result := DataSize(AData);
|
|
|
|
pData := DataPointer(AData);
|
|
|
|
|
|
|
|
SetLength(String(AValue), Result);
|
|
|
|
if Result > 0 then
|
|
|
|
Move(pData^, PChar(String(AValue))^, Result);
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TX2HashStringManager.ToPointer(const AValue: String): Pointer;
|
|
|
|
begin
|
|
|
|
Result := ToPointer(PChar(AValue), Length(AValue));
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TX2HashStringManager.ToValue(const AData: Pointer): String;
|
|
|
|
begin
|
|
|
|
ToValue(AData, Result);
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TX2HashStringManager.Compare(const AData: Pointer; const AValue: Pointer;
|
|
|
|
const ASize: Cardinal): Boolean;
|
|
|
|
var
|
|
|
|
pSource: PChar;
|
|
|
|
|
|
|
|
begin
|
|
|
|
Result := False;
|
|
|
|
if ASize <> PCardinal(AData)^ then
|
|
|
|
exit;
|
|
|
|
|
|
|
|
pSource := AData;
|
|
|
|
Inc(PCardinal(pSource));
|
|
|
|
|
|
|
|
Result := CompareMem(pSource, AValue, ASize);
|
|
|
|
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
|
|
|
|
========================================}
|
|
|
|
constructor TX2CustomHash.Create();
|
|
|
|
begin
|
|
|
|
inherited;
|
|
|
|
|
|
|
|
FKeyManager := CreateKeyManager();
|
|
|
|
FValueManager := CreateValueManager();
|
|
|
|
end;
|
|
|
|
|
|
|
|
destructor TX2CustomHash.Destroy();
|
|
|
|
begin
|
2005-07-01 11:43:59 +00:00
|
|
|
Clear();
|
2005-06-30 12:18:53 +00:00
|
|
|
FreeAndNil(FValueManager);
|
|
|
|
FreeAndNil(FKeyManager);
|
|
|
|
FreeAndNil(FCursor);
|
|
|
|
|
|
|
|
inherited;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TX2CustomHash.CreateCursor(): TX2HashCursor;
|
|
|
|
begin
|
2005-12-28 19:15:17 +00:00
|
|
|
Result := nil;
|
|
|
|
if Assigned(FRoot) then
|
|
|
|
Result := TX2HashCursor.Create(FRoot);
|
2005-06-30 12:18:53 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TX2CustomHash.InvalidateCursor();
|
|
|
|
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;
|
|
|
|
|
|
|
|
function TX2CustomHash.Hash(const AKey: Pointer; const ASize: Cardinal): Cardinal;
|
|
|
|
begin
|
|
|
|
Result := CRC32(AKey, ASize);
|
|
|
|
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
|
2005-08-26 10:25:39 +00:00
|
|
|
Result := True;
|
2005-06-30 12:18:53 +00:00
|
|
|
if not Assigned(FCursor) then
|
|
|
|
if Assigned(FRoot) then
|
|
|
|
FCursor := CreateCursor()
|
|
|
|
else
|
2005-08-26 10:25:39 +00:00
|
|
|
begin
|
|
|
|
Result := False;
|
|
|
|
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;
|
|
|
|
const AHash: Cardinal; const AKey: Pointer;
|
|
|
|
const ASize: Cardinal;
|
|
|
|
const AAllowCreate: Boolean;
|
|
|
|
const AExisting: PX2HashValue): PX2HashValue;
|
|
|
|
function CreateValue(): PX2HashValue;
|
|
|
|
begin
|
|
|
|
if AExisting = nil then
|
|
|
|
begin
|
|
|
|
GetMem(Result, SizeOf(TX2HashValue));
|
|
|
|
FillChar(Result^, SizeOf(TX2HashValue), #0);
|
|
|
|
|
|
|
|
Result^.ID := HIDValue;
|
|
|
|
Result^.Key := FKeyManager.ToPointer(AKey, ASize);
|
|
|
|
Inc(FCount);
|
|
|
|
end else
|
|
|
|
Result := AExisting;
|
|
|
|
|
|
|
|
InvalidateCursor();
|
|
|
|
end;
|
|
|
|
|
|
|
|
var
|
|
|
|
iCount: Integer;
|
|
|
|
iIndex: Integer;
|
|
|
|
iKey: Integer;
|
|
|
|
pBucket: PX2HashBucket;
|
|
|
|
pKey: Pointer;
|
|
|
|
pNext: PX2HashValue;
|
|
|
|
pValue: PX2HashValue;
|
|
|
|
|
|
|
|
begin
|
|
|
|
Result := nil;
|
|
|
|
iIndex := (AHash and $FF);
|
|
|
|
|
|
|
|
if ABucket^.Items[iIndex] = nil then
|
|
|
|
begin
|
|
|
|
if AAllowCreate then
|
|
|
|
begin
|
|
|
|
// New value
|
|
|
|
Result := CreateValue();
|
|
|
|
ABucket^.Items[iIndex] := PX2HashItem(Result);
|
|
|
|
Inc(ABucket^.Count);
|
|
|
|
end;
|
|
|
|
end else
|
|
|
|
case ABucket^.Items[iIndex]^.ID of
|
|
|
|
HIDBucket:
|
|
|
|
// Bucket, continue down
|
|
|
|
Result := InternalFind(PX2HashBucket(ABucket^.Items[iIndex]),
|
|
|
|
ROR(AHash), AKey, ASize, AAllowCreate);
|
|
|
|
HIDValue:
|
|
|
|
begin
|
|
|
|
iCount := 0;
|
|
|
|
pValue := PX2HashValue(ABucket^.Items[iIndex]);
|
|
|
|
while pValue <> nil do
|
|
|
|
begin
|
|
|
|
if FKeyManager.Compare(pValue^.Key, AKey, ASize) then
|
|
|
|
begin
|
|
|
|
// Found existing key
|
|
|
|
Result := pValue;
|
|
|
|
exit;
|
|
|
|
end;
|
|
|
|
|
|
|
|
pValue := pValue^.Next;
|
|
|
|
Inc(iCount);
|
|
|
|
end;
|
|
|
|
|
|
|
|
if AAllowCreate then
|
|
|
|
if (iCount >= BucketSize) then
|
|
|
|
begin
|
|
|
|
// Bucket full
|
|
|
|
GetMem(pBucket, SizeOf(TX2HashBucket));
|
|
|
|
FillChar(pBucket^, SizeOf(TX2HashBucket), #0);
|
|
|
|
pBucket^.ID := HIDBucket;
|
|
|
|
pBucket^.Level := ABucket^.Level + 1;
|
|
|
|
|
|
|
|
pValue := PX2HashValue(ABucket^.Items[iIndex]);
|
|
|
|
while pValue <> nil do
|
|
|
|
begin
|
|
|
|
// Transfer item
|
|
|
|
iKey := FKeyManager.DataSize(pValue^.Key);
|
|
|
|
pKey := FKeyManager.DataPointer(pValue^.Key);
|
|
|
|
pNext := pValue^.Next;
|
|
|
|
pValue^.Next := nil;
|
|
|
|
|
|
|
|
InternalFind(pBucket, ROR(Hash(pKey, iKey), pBucket^.Level * 8),
|
|
|
|
pKey, iKey, True, pValue);
|
|
|
|
|
|
|
|
|
|
|
|
pValue := pNext;
|
|
|
|
end;
|
|
|
|
|
|
|
|
Result := InternalFind(pBucket, ROR(AHash), AKey, ASize, True);
|
|
|
|
ABucket^.Items[iIndex] := PX2HashItem(pBucket);
|
|
|
|
end else
|
|
|
|
begin
|
|
|
|
// New value
|
|
|
|
Result := CreateValue();
|
|
|
|
Result^.Next := PX2HashValue(ABucket^.Items[iIndex]);
|
|
|
|
ABucket^.Items[iIndex] := PX2HashItem(Result);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TX2CustomHash.InternalDelete(const ABucket: PX2HashBucket;
|
|
|
|
const AHash: Cardinal;
|
|
|
|
const AKey: Pointer;
|
|
|
|
const ASize: Cardinal): Boolean;
|
|
|
|
var
|
|
|
|
iIndex: Integer;
|
|
|
|
pBucket: PX2HashBucket;
|
|
|
|
pPrev: PX2HashValue;
|
|
|
|
pValue: PX2HashValue;
|
|
|
|
|
|
|
|
begin
|
|
|
|
Result := False;
|
|
|
|
iIndex := (AHash and $FF);
|
|
|
|
|
|
|
|
if ABucket^.Items[iIndex] <> nil then
|
|
|
|
case ABucket^.Items[iIndex]^.ID of
|
|
|
|
HIDBucket:
|
|
|
|
begin
|
|
|
|
// Bucket, continue down
|
|
|
|
pBucket := PX2HashBucket(ABucket^.Items[iIndex]);
|
|
|
|
Result := InternalDelete(pBucket, ROR(AHash), AKey, ASize);
|
|
|
|
|
|
|
|
if pBucket^.Count = 0 then
|
|
|
|
begin
|
|
|
|
FreeMem(pBucket, SizeOf(TX2HashBucket));
|
|
|
|
ABucket^.Items[iIndex] := nil;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
HIDValue:
|
|
|
|
begin
|
|
|
|
pPrev := nil;
|
|
|
|
pValue := PX2HashValue(ABucket^.Items[iIndex]);
|
|
|
|
while pValue <> nil do
|
|
|
|
begin
|
|
|
|
if FKeyManager.Compare(pValue^.Key, AKey, ASize) then
|
|
|
|
begin
|
|
|
|
// Found key
|
|
|
|
if pPrev = nil then
|
|
|
|
begin
|
|
|
|
ABucket^.Items[iIndex] := PX2HashItem(pValue^.Next);
|
|
|
|
if ABucket^.Items[iIndex] = nil then
|
|
|
|
Dec(ABucket^.Count);
|
|
|
|
end else
|
|
|
|
pPrev^.Next := pValue^.Next;
|
|
|
|
|
|
|
|
FKeyManager.Finalize(pValue^.Key);
|
|
|
|
FValueManager.Finalize(pValue^.Value);
|
|
|
|
FreeMem(pValue, SizeOf(TX2HashValue));
|
|
|
|
Dec(FCount);
|
|
|
|
|
|
|
|
Result := True;
|
|
|
|
exit;
|
|
|
|
end;
|
|
|
|
|
|
|
|
pPrev := pValue;
|
|
|
|
pValue := pValue^.Next;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TX2CustomHash.Find(const AKey: Pointer; const ASize: Cardinal;
|
|
|
|
const AAllowCreate: Boolean): PX2HashValue;
|
|
|
|
begin
|
|
|
|
Result := nil;
|
|
|
|
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;
|
|
|
|
|
|
|
|
Result := InternalFind(FRoot, Hash(AKey, ASize), AKey, ASize,
|
|
|
|
AAllowCreate);
|
|
|
|
end;
|
|
|
|
|
2005-07-01 11:43:59 +00:00
|
|
|
|
|
|
|
procedure TX2CustomHash.Clear();
|
|
|
|
procedure DestroyBucket(const ABucket: PX2HashBucket);
|
|
|
|
var
|
|
|
|
iItem: Integer;
|
|
|
|
pNext: PX2HashValue;
|
|
|
|
pValue: PX2HashValue;
|
|
|
|
|
|
|
|
begin
|
|
|
|
for iItem := Pred(LeafSize) downto 0 do
|
|
|
|
if ABucket^.Items[iItem] <> nil then
|
|
|
|
case ABucket^.Items[iItem].ID of
|
|
|
|
HIDBucket:
|
|
|
|
DestroyBucket(PX2HashBucket(ABucket^.Items[iItem]));
|
|
|
|
HIDValue:
|
|
|
|
begin
|
|
|
|
pValue := PX2HashValue(ABucket^.Items[iItem]);
|
|
|
|
repeat
|
|
|
|
FKeyManager.Finalize(pValue^.Key);
|
|
|
|
FValueManager.Finalize(pValue^.Value);
|
|
|
|
|
|
|
|
pNext := pValue^.Next;
|
|
|
|
FreeMem(pValue, SizeOf(TX2HashValue));
|
|
|
|
pValue := pNext;
|
|
|
|
until pValue = nil;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
FreeMem(ABucket, SizeOf(TX2HashBucket));
|
|
|
|
end;
|
|
|
|
|
|
|
|
begin
|
|
|
|
if FRoot <> nil then
|
|
|
|
begin
|
|
|
|
DestroyBucket(FRoot);
|
|
|
|
FCount := 0;
|
|
|
|
FRoot := nil;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function TX2CustomHash.Exists(const AKey: Pointer;
|
|
|
|
const ASize: Cardinal): Boolean;
|
|
|
|
begin
|
|
|
|
Result := (Assigned(FRoot) and (Find(AKey, ASize, False) <> nil));
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TX2CustomHash.Delete(const AKey: Pointer;
|
|
|
|
const ASize: Cardinal): Boolean;
|
|
|
|
begin
|
|
|
|
Result := False;
|
|
|
|
if not Assigned(FRoot) then
|
|
|
|
exit;
|
|
|
|
|
|
|
|
Result := InternalDelete(FRoot, Hash(AKey, ASize), AKey, ASize);
|
|
|
|
if Result then
|
|
|
|
InvalidateCursor();
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TX2CustomHash.SetValue(const AValue: PX2HashValue;
|
|
|
|
const AData: Pointer);
|
|
|
|
begin
|
|
|
|
ValueManager.Finalize(AValue^.Value);
|
|
|
|
AValue^.Value := AData;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
procedure TX2CustomHash.First();
|
|
|
|
begin
|
2005-08-26 10:25:39 +00:00
|
|
|
if not CursorRequired(False) then
|
|
|
|
exit;
|
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
Cursor.First();
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TX2CustomHash.Next(): Boolean;
|
|
|
|
begin
|
2005-08-26 10:25:39 +00:00
|
|
|
Result := False;
|
|
|
|
if not CursorRequired(False) then
|
|
|
|
exit;
|
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
Result := Cursor.Next();
|
|
|
|
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
|
|
|
|
inherited Create();
|
|
|
|
|
|
|
|
FEnumKeys := AEnumKeys;
|
|
|
|
if AEnumKeys then
|
|
|
|
FManager := AHash.KeyManager
|
|
|
|
else
|
|
|
|
FManager := AHash.ValueManager;
|
|
|
|
|
|
|
|
FCursor := AHash.CreateCursor();
|
|
|
|
end;
|
|
|
|
|
|
|
|
destructor TX2HashEnumerator.Destroy();
|
|
|
|
begin
|
|
|
|
FreeAndNil(FCursor);
|
|
|
|
|
|
|
|
inherited;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TX2HashEnumerator.GetCursor(): Pointer;
|
|
|
|
begin
|
|
|
|
if FEnumKeys then
|
|
|
|
Result := FCursor.Current^.Key
|
|
|
|
else
|
|
|
|
Result := FCursor.Current^.Value;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TX2HashEnumerator.MoveNext(): Boolean;
|
|
|
|
begin
|
|
|
|
Result := False;
|
|
|
|
if Assigned(FCursor) then
|
|
|
|
Result := FCursor.Next();
|
|
|
|
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 }
|
|
|
|
function TX2HashPointerEnumerator.GetCurrent(): Pointer;
|
|
|
|
begin
|
|
|
|
Result := TX2HashPointerManager(Manager).ToValue(Cursor);
|
|
|
|
end;
|
2004-09-01 18:19:31 +00:00
|
|
|
|
2005-12-28 19:15:17 +00:00
|
|
|
{ TX2HashIntegerEnumerator }
|
|
|
|
function TX2HashIntegerEnumerator.GetCurrent(): Integer;
|
|
|
|
begin
|
|
|
|
Result := TX2HashIntegerManager(Manager).ToValue(Cursor);
|
|
|
|
end;
|
|
|
|
|
|
|
|
{ TX2HashObjectEnumerator }
|
|
|
|
function TX2HashObjectEnumerator.GetCurrent(): TObject;
|
|
|
|
begin
|
|
|
|
Result := TX2HashObjectManager(Manager).ToValue(Cursor);
|
|
|
|
end;
|
|
|
|
|
|
|
|
{ TX2HashStringEnumerator }
|
|
|
|
function TX2HashStringEnumerator.GetCurrent(): String;
|
|
|
|
begin
|
|
|
|
Result := TX2HashStringManager(Manager).ToValue(Cursor);
|
|
|
|
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
|
|
|
|
========================================}
|
|
|
|
function TX2CustomPointerHash.CreateKeyManager(): TX2CustomHashManager;
|
|
|
|
begin
|
|
|
|
Result := TX2HashPointerManager.Create();
|
|
|
|
end;
|
2004-08-20 13:03:07 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function TX2CustomPointerHash.GetCurrentKey(): Pointer;
|
|
|
|
begin
|
|
|
|
CursorRequired();
|
|
|
|
Result := TX2HashPointerManager(KeyManager).ToValue(Cursor.Current^.Key);
|
|
|
|
end;
|
2004-07-29 13:48:35 +00:00
|
|
|
|
2005-12-28 19:15:17 +00:00
|
|
|
function TX2CustomPointerHash.GetEnumerator(): TX2HashPointerEnumerator;
|
|
|
|
begin
|
|
|
|
Result := TX2HashPointerEnumerator.Create(Self, True);
|
|
|
|
end;
|
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function TX2CustomPointerHash.Find(const AKey: Pointer;
|
|
|
|
const AAllowCreate: Boolean): PX2HashValue;
|
|
|
|
begin
|
|
|
|
Result := inherited Find(@AKey, SizeOf(Pointer), AAllowCreate);
|
|
|
|
end;
|
2004-07-29 13:48:35 +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
|
2005-06-30 12:18:53 +00:00
|
|
|
Result := inherited Exists(@AKey, SizeOf(Pointer));
|
|
|
|
end;
|
2004-07-29 13:48:35 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function TX2CustomPointerHash.Delete(const AKey: Pointer): Boolean;
|
|
|
|
begin
|
|
|
|
Result := inherited Delete(@AKey, SizeOf(Pointer));
|
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
|
|
|
========================================}
|
2005-06-30 12:18:53 +00:00
|
|
|
function TX2CustomIntegerHash.CreateKeyManager(): TX2CustomHashManager;
|
2004-07-29 15:49:42 +00:00
|
|
|
begin
|
2005-06-30 12:18:53 +00:00
|
|
|
Result := TX2HashIntegerManager.Create();
|
2004-07-29 13:48:35 +00:00
|
|
|
end;
|
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function TX2CustomIntegerHash.GetCurrentKey(): Integer;
|
|
|
|
begin
|
|
|
|
CursorRequired();
|
|
|
|
Result := TX2HashIntegerManager(KeyManager).ToValue(Cursor.Current^.Key);
|
|
|
|
end;
|
2004-07-29 15:49:42 +00:00
|
|
|
|
2005-12-28 19:15:17 +00:00
|
|
|
function TX2CustomIntegerHash.GetEnumerator(): TX2HashIntegerEnumerator;
|
|
|
|
begin
|
|
|
|
Result := TX2HashIntegerEnumerator.Create(Self, True);
|
|
|
|
end;
|
|
|
|
|
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
|
2005-06-30 12:18:53 +00:00
|
|
|
Result := inherited Find(@AKey, SizeOf(Pointer), AAllowCreate);
|
|
|
|
end;
|
2004-07-29 13:48:35 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function TX2CustomIntegerHash.Exists(const AKey: Integer): Boolean;
|
|
|
|
begin
|
|
|
|
Result := inherited Exists(@AKey, SizeOf(Pointer));
|
|
|
|
end;
|
2004-07-29 15:49:42 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function TX2CustomIntegerHash.Delete(const AKey: Integer): Boolean;
|
|
|
|
begin
|
|
|
|
Result := inherited Delete(@AKey, SizeOf(Pointer));
|
|
|
|
end;
|
2004-07-29 15:49:42 +00:00
|
|
|
|
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
{========================================
|
|
|
|
TX2CustomObjectHash
|
|
|
|
========================================}
|
|
|
|
function TX2CustomObjectHash.CreateKeyManager(): TX2CustomHashManager;
|
|
|
|
begin
|
|
|
|
Result := TX2HashObjectManager.Create();
|
|
|
|
end;
|
2004-07-29 15:49:42 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function TX2CustomObjectHash.GetCurrentKey(): TObject;
|
|
|
|
begin
|
|
|
|
CursorRequired();
|
|
|
|
Result := TX2HashObjectManager(KeyManager).ToValue(Cursor.Current^.Key);
|
|
|
|
end;
|
|
|
|
|
2005-12-28 19:15:17 +00:00
|
|
|
function TX2CustomObjectHash.GetEnumerator(): TX2HashObjectEnumerator;
|
|
|
|
begin
|
|
|
|
Result := TX2HashObjectEnumerator.Create(Self, True);
|
|
|
|
end;
|
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function TX2CustomObjectHash.Find(const AKey: TObject;
|
|
|
|
const AAllowCreate: Boolean): PX2HashValue;
|
|
|
|
begin
|
|
|
|
Result := inherited Find(@AKey, SizeOf(Pointer), AAllowCreate);
|
|
|
|
end;
|
2004-07-29 15:49:42 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function TX2CustomObjectHash.Exists(const AKey: TObject): Boolean;
|
|
|
|
begin
|
|
|
|
Result := inherited Exists(@AKey, SizeOf(Pointer));
|
2004-07-29 06:33:18 +00:00
|
|
|
end;
|
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function TX2CustomObjectHash.Delete(const AKey: TObject): Boolean;
|
|
|
|
begin
|
|
|
|
Result := inherited Delete(@AKey, SizeOf(Pointer));
|
|
|
|
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
|
|
|
========================================}
|
2005-06-30 12:18:53 +00:00
|
|
|
function TX2CustomStringHash.CreateKeyManager(): TX2CustomHashManager;
|
2004-07-29 06:33:18 +00:00
|
|
|
begin
|
2005-06-30 12:18:53 +00:00
|
|
|
Result := TX2HashStringManager.Create();
|
2004-07-29 06:33:18 +00:00
|
|
|
end;
|
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function TX2CustomStringHash.GetCurrentKey(): String;
|
2004-07-29 06:33:18 +00:00
|
|
|
begin
|
2005-06-30 12:18:53 +00:00
|
|
|
CursorRequired();
|
|
|
|
Result := TX2HashStringManager(KeyManager).ToValue(Cursor.Current^.Key);
|
|
|
|
end;
|
2004-07-29 06:33:18 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
|
2005-12-28 19:15:17 +00:00
|
|
|
function TX2CustomStringHash.GetEnumerator(): TX2HashStringEnumerator;
|
|
|
|
begin
|
|
|
|
Result := TX2HashStringEnumerator.Create(Self, True);
|
|
|
|
end;
|
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function TX2CustomStringHash.Find(const AKey: String;
|
|
|
|
const AAllowCreate: Boolean): PX2HashValue;
|
|
|
|
begin
|
|
|
|
Result := inherited Find(PChar(AKey), Length(AKey), AAllowCreate);
|
2004-07-29 06:33:18 +00:00
|
|
|
end;
|
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function TX2CustomStringHash.Exists(const AKey: String): Boolean;
|
2004-07-29 06:33:18 +00:00
|
|
|
begin
|
2005-06-30 12:18:53 +00:00
|
|
|
Result := inherited Exists(PChar(AKey), Length(AKey));
|
|
|
|
end;
|
2004-07-29 06:33:18 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function TX2CustomStringHash.Delete(const AKey: String): Boolean;
|
|
|
|
begin
|
|
|
|
Result := inherited Delete(PChar(AKey), Length(AKey));
|
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
|
|
|
========================================}
|
2005-06-30 12:18:53 +00:00
|
|
|
function TX2PPHash.CreateValueManager(): TX2CustomHashManager;
|
2004-07-29 13:48:35 +00:00
|
|
|
begin
|
2005-06-30 12:18:53 +00:00
|
|
|
Result := TX2HashPointerManager.Create();
|
2004-07-29 13:48:35 +00:00
|
|
|
end;
|
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function TX2PPHash.GetCurrentValue(): Pointer;
|
|
|
|
begin
|
|
|
|
CursorRequired();
|
|
|
|
Result := TX2HashPointerManager(ValueManager).ToValue(Cursor.Current^.Value);
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TX2PPHash.GetValue(Key: Pointer): Pointer;
|
2004-07-29 06:33:18 +00:00
|
|
|
var
|
2005-06-30 12:18:53 +00:00
|
|
|
pItem: PX2HashValue;
|
2004-07-29 06:33:18 +00:00
|
|
|
|
|
|
|
begin
|
2004-07-29 13:48:35 +00:00
|
|
|
Result := nil;
|
2005-06-30 12:18:53 +00:00
|
|
|
pItem := Find(Key, False);
|
|
|
|
if Assigned(pItem) then
|
|
|
|
Result := TX2HashPointerManager(ValueManager).ToValue(pItem^.Value);
|
|
|
|
end;
|
2004-07-29 13:48:35 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
procedure TX2PPHash.SetValue(Key: Pointer; const Value: Pointer);
|
|
|
|
begin
|
|
|
|
inherited SetValue(Find(Key, True),
|
|
|
|
TX2HashPointerManager(ValueManager).ToPointer(Value));
|
|
|
|
end;
|
2004-07-29 13:48:35 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
{========================================
|
|
|
|
TX2PIHash
|
|
|
|
========================================}
|
|
|
|
function TX2PIHash.CreateValueManager(): TX2CustomHashManager;
|
|
|
|
begin
|
|
|
|
Result := TX2HashIntegerManager.Create();
|
|
|
|
end;
|
2004-07-29 13:48:35 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function TX2PIHash.GetCurrentValue(): Integer;
|
|
|
|
begin
|
|
|
|
CursorRequired();
|
|
|
|
Result := TX2HashIntegerManager(ValueManager).ToValue(Cursor.Current^.Value);
|
|
|
|
end;
|
2004-07-29 13:48:35 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function TX2PIHash.GetValue(Key: Pointer): Integer;
|
|
|
|
var
|
|
|
|
pItem: PX2HashValue;
|
2004-07-29 13:48:35 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
begin
|
|
|
|
Result := 0;
|
|
|
|
pItem := Find(Key, False);
|
|
|
|
if Assigned(pItem) then
|
|
|
|
Result := TX2HashIntegerManager(ValueManager).ToValue(pItem^.Value);
|
|
|
|
end;
|
2004-07-29 13:48:35 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
procedure TX2PIHash.SetValue(Key: Pointer; const Value: Integer);
|
|
|
|
begin
|
|
|
|
inherited SetValue(Find(Key, True),
|
|
|
|
TX2HashIntegerManager(ValueManager).ToPointer(Value));
|
|
|
|
end;
|
2004-07-29 13:48:35 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
{========================================
|
|
|
|
TX2POHash
|
|
|
|
========================================}
|
|
|
|
constructor TX2POHash.Create(const AOwnsObjects: Boolean);
|
|
|
|
begin
|
|
|
|
inherited Create();
|
|
|
|
OwnsObjects := AOwnsObjects;
|
|
|
|
end;
|
2004-07-29 13:48:35 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function TX2POHash.CreateValueManager(): TX2CustomHashManager;
|
|
|
|
begin
|
|
|
|
Result := TX2HashObjectManager.Create();
|
|
|
|
end;
|
2004-07-29 13:48:35 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function TX2POHash.GetCurrentValue(): TObject;
|
|
|
|
begin
|
|
|
|
Result := TX2HashObjectManager(ValueManager).ToValue(Cursor.Current^.Value);
|
|
|
|
end;
|
2004-07-29 13:48:35 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function TX2POHash.GetOwnsObjects(): Boolean;
|
|
|
|
begin
|
|
|
|
Result := TX2HashObjectManager(ValueManager).OwnsObjects;
|
2004-07-29 06:33:18 +00:00
|
|
|
end;
|
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
procedure TX2POHash.SetOwnsObjects(const Value: Boolean);
|
|
|
|
begin
|
|
|
|
TX2HashObjectManager(ValueManager).OwnsObjects := Value;
|
|
|
|
end;
|
2004-07-29 06:33:18 +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
|
2005-06-30 12:18:53 +00:00
|
|
|
pItem: PX2HashValue;
|
2004-07-29 13:48:35 +00:00
|
|
|
|
2004-07-29 06:33:18 +00:00
|
|
|
begin
|
2005-06-30 12:18:53 +00:00
|
|
|
Result := nil;
|
|
|
|
pItem := Find(Key, False);
|
2004-07-29 13:48:35 +00:00
|
|
|
if Assigned(pItem) then
|
2005-06-30 12:18:53 +00:00
|
|
|
Result := TX2HashObjectManager(ValueManager).ToValue(pItem^.Value);
|
|
|
|
end;
|
2004-07-29 13:48:35 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
procedure TX2POHash.SetValue(Key: Pointer; const Value: TObject);
|
|
|
|
begin
|
|
|
|
inherited SetValue(Find(Key, True),
|
|
|
|
TX2HashObjectManager(ValueManager).ToPointer(Value));
|
|
|
|
end;
|
2004-07-29 13:48:35 +00:00
|
|
|
|
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
{========================================
|
|
|
|
TX2PSHash
|
|
|
|
========================================}
|
|
|
|
function TX2PSHash.CreateValueManager(): TX2CustomHashManager;
|
|
|
|
begin
|
|
|
|
Result := TX2HashStringManager.Create();
|
|
|
|
end;
|
2004-07-29 13:48:35 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function TX2PSHash.GetCurrentValue(): String;
|
|
|
|
begin
|
|
|
|
Result := TX2HashStringManager(ValueManager).ToValue(Cursor.Current^.Value);
|
2004-07-29 06:33:18 +00:00
|
|
|
end;
|
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function TX2PSHash.GetValue(Key: Pointer): String;
|
2004-09-05 13:48:19 +00:00
|
|
|
var
|
2005-06-30 12:18:53 +00:00
|
|
|
pItem: PX2HashValue;
|
2004-09-05 13:48:19 +00:00
|
|
|
|
2004-07-29 06:33:18 +00:00
|
|
|
begin
|
2005-06-30 12:18:53 +00:00
|
|
|
Result := '';
|
|
|
|
pItem := Find(Key, False);
|
|
|
|
if Assigned(pItem) then
|
|
|
|
Result := TX2HashStringManager(ValueManager).ToValue(pItem^.Value);
|
2004-07-29 06:33:18 +00:00
|
|
|
end;
|
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
procedure TX2PSHash.SetValue(Key: Pointer; const Value: String);
|
|
|
|
begin
|
|
|
|
inherited SetValue(Find(Key, True),
|
|
|
|
TX2HashStringManager(ValueManager).ToPointer(Value));
|
|
|
|
end;
|
2004-07-29 06:33:18 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
{========================================
|
|
|
|
TX2IPHash
|
|
|
|
========================================}
|
|
|
|
function TX2IPHash.CreateValueManager(): TX2CustomHashManager;
|
2004-07-29 06:33:18 +00:00
|
|
|
begin
|
2005-06-30 12:18:53 +00:00
|
|
|
Result := TX2HashPointerManager.Create();
|
2004-07-29 06:33:18 +00:00
|
|
|
end;
|
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function TX2IPHash.GetCurrentValue(): Pointer;
|
|
|
|
begin
|
|
|
|
CursorRequired();
|
|
|
|
Result := TX2HashPointerManager(ValueManager).ToValue(Cursor.Current^.Value);
|
|
|
|
end;
|
2004-07-29 06:33:18 +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
|
2005-06-30 12:18:53 +00:00
|
|
|
pItem: PX2HashValue;
|
2004-07-29 06:33:18 +00:00
|
|
|
|
|
|
|
begin
|
2005-06-30 12:18:53 +00:00
|
|
|
Result := nil;
|
|
|
|
pItem := Find(Key, False);
|
|
|
|
if Assigned(pItem) then
|
|
|
|
Result := TX2HashPointerManager(ValueManager).ToValue(pItem^.Value);
|
2004-07-29 06:33:18 +00:00
|
|
|
end;
|
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
procedure TX2IPHash.SetValue(Key: Integer; const Value: Pointer);
|
|
|
|
begin
|
|
|
|
inherited SetValue(Find(Key, True),
|
|
|
|
TX2HashPointerManager(ValueManager).ToPointer(Value));
|
|
|
|
end;
|
2004-07-29 06:33:18 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
{========================================
|
|
|
|
TX2IIHash
|
|
|
|
========================================}
|
|
|
|
function TX2IIHash.CreateValueManager(): TX2CustomHashManager;
|
2004-07-29 06:33:18 +00:00
|
|
|
begin
|
2005-06-30 12:18:53 +00:00
|
|
|
Result := TX2HashIntegerManager.Create();
|
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
|
|
|
function TX2IIHash.GetCurrentValue(): Integer;
|
2004-07-29 13:48:35 +00:00
|
|
|
begin
|
2005-06-30 12:18:53 +00:00
|
|
|
CursorRequired();
|
|
|
|
Result := TX2HashIntegerManager(ValueManager).ToValue(Cursor.Current^.Value);
|
|
|
|
end;
|
2004-07-29 13:48:35 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function TX2IIHash.GetValue(Key: Integer): Integer;
|
|
|
|
var
|
|
|
|
pItem: PX2HashValue;
|
2004-07-29 13:48:35 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
begin
|
|
|
|
Result := 0;
|
|
|
|
pItem := Find(Key, False);
|
|
|
|
if Assigned(pItem) then
|
|
|
|
Result := TX2HashIntegerManager(ValueManager).ToValue(pItem^.Value);
|
|
|
|
end;
|
2004-07-29 13:48:35 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
procedure TX2IIHash.SetValue(Key: Integer; const Value: Integer);
|
|
|
|
begin
|
|
|
|
inherited SetValue(Find(Key, True),
|
|
|
|
TX2HashIntegerManager(ValueManager).ToPointer(Value));
|
2004-07-29 13:48:35 +00:00
|
|
|
end;
|
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
{========================================
|
|
|
|
TX2IOHash
|
|
|
|
========================================}
|
|
|
|
constructor TX2IOHash.Create(const AOwnsObjects: Boolean);
|
|
|
|
begin
|
|
|
|
inherited Create();
|
|
|
|
OwnsObjects := AOwnsObjects;
|
|
|
|
end;
|
2004-07-29 13:48:35 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function TX2IOHash.CreateValueManager(): TX2CustomHashManager;
|
2004-07-29 13:48:35 +00:00
|
|
|
begin
|
2005-06-30 12:18:53 +00:00
|
|
|
Result := TX2HashObjectManager.Create();
|
2004-07-29 06:33:18 +00:00
|
|
|
end;
|
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function TX2IOHash.GetCurrentValue(): TObject;
|
|
|
|
begin
|
|
|
|
Result := TX2HashObjectManager(ValueManager).ToValue(Cursor.Current^.Value);
|
|
|
|
end;
|
2004-07-29 06:33:18 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function TX2IOHash.GetOwnsObjects(): Boolean;
|
2004-07-29 06:33:18 +00:00
|
|
|
begin
|
2005-06-30 12:18:53 +00:00
|
|
|
Result := TX2HashObjectManager(ValueManager).OwnsObjects;
|
|
|
|
end;
|
2004-07-29 06:33:18 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
procedure TX2IOHash.SetOwnsObjects(const Value: Boolean);
|
|
|
|
begin
|
|
|
|
TX2HashObjectManager(ValueManager).OwnsObjects := Value;
|
2004-07-29 06:33:18 +00:00
|
|
|
end;
|
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function TX2IOHash.GetValue(Key: Integer): TObject;
|
2004-07-29 06:33:18 +00:00
|
|
|
var
|
2005-06-30 12:18:53 +00:00
|
|
|
pItem: PX2HashValue;
|
2004-07-29 06:33:18 +00:00
|
|
|
|
|
|
|
begin
|
2004-08-20 19:04:22 +00:00
|
|
|
Result := nil;
|
2005-06-30 12:18:53 +00:00
|
|
|
pItem := Find(Key, False);
|
2004-08-20 11:18:01 +00:00
|
|
|
if Assigned(pItem) then
|
2005-06-30 12:18:53 +00:00
|
|
|
Result := TX2HashObjectManager(ValueManager).ToValue(pItem^.Value);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TX2IOHash.SetValue(Key: Integer; const Value: TObject);
|
|
|
|
begin
|
|
|
|
inherited SetValue(Find(Key, True),
|
|
|
|
TX2HashObjectManager(ValueManager).ToPointer(Value));
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
{========================================
|
|
|
|
TX2ISHash
|
|
|
|
========================================}
|
|
|
|
function TX2ISHash.CreateValueManager(): TX2CustomHashManager;
|
|
|
|
begin
|
|
|
|
Result := TX2HashStringManager.Create();
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TX2ISHash.GetCurrentValue(): String;
|
|
|
|
begin
|
|
|
|
Result := TX2HashStringManager(ValueManager).ToValue(Cursor.Current^.Value);
|
2004-07-29 06:33:18 +00:00
|
|
|
end;
|
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function TX2ISHash.GetValue(Key: Integer): String;
|
2004-07-29 06:33:18 +00:00
|
|
|
var
|
2005-06-30 12:18:53 +00:00
|
|
|
pItem: PX2HashValue;
|
2004-07-29 06:33:18 +00:00
|
|
|
|
|
|
|
begin
|
2005-06-30 12:18:53 +00:00
|
|
|
Result := '';
|
|
|
|
pItem := Find(Key, False);
|
2004-08-20 11:18:01 +00:00
|
|
|
if Assigned(pItem) then
|
2005-06-30 12:18:53 +00:00
|
|
|
Result := TX2HashStringManager(ValueManager).ToValue(pItem^.Value);
|
2004-07-29 06:33:18 +00:00
|
|
|
end;
|
|
|
|
|
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
|
2005-06-30 12:18:53 +00:00
|
|
|
inherited SetValue(Find(Key, True),
|
|
|
|
TX2HashStringManager(ValueManager).ToPointer(Value));
|
2004-08-20 11:18:01 +00:00
|
|
|
end;
|
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
{========================================
|
|
|
|
TX2OPHash
|
2004-08-20 11:18:01 +00:00
|
|
|
========================================}
|
2005-06-30 12:18:53 +00:00
|
|
|
function TX2OPHash.CreateValueManager(): TX2CustomHashManager;
|
2004-08-20 11:18:01 +00:00
|
|
|
begin
|
2005-06-30 12:18:53 +00:00
|
|
|
Result := TX2HashPointerManager.Create();
|
2004-08-20 11:18:01 +00:00
|
|
|
end;
|
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function TX2OPHash.GetCurrentValue(): Pointer;
|
2004-08-20 11:18:01 +00:00
|
|
|
begin
|
2005-06-30 12:18:53 +00:00
|
|
|
CursorRequired();
|
|
|
|
Result := TX2HashPointerManager(ValueManager).ToValue(Cursor.Current^.Value);
|
2004-08-20 11:18:01 +00:00
|
|
|
end;
|
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function TX2OPHash.GetValue(Key: TObject): Pointer;
|
|
|
|
var
|
|
|
|
pItem: PX2HashValue;
|
|
|
|
|
2004-08-20 11:18:01 +00:00
|
|
|
begin
|
2005-06-30 12:18:53 +00:00
|
|
|
Result := nil;
|
|
|
|
pItem := Find(Key, False);
|
|
|
|
if Assigned(pItem) then
|
|
|
|
Result := TX2HashPointerManager(ValueManager).ToValue(pItem^.Value);
|
2004-07-29 06:33:18 +00:00
|
|
|
end;
|
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
procedure TX2OPHash.SetValue(Key: TObject; const Value: Pointer);
|
|
|
|
begin
|
|
|
|
inherited SetValue(Find(Key, True),
|
|
|
|
TX2HashPointerManager(ValueManager).ToPointer(Value));
|
|
|
|
end;
|
2004-07-29 06:33:18 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
{========================================
|
|
|
|
TX2OIHash
|
2004-07-29 06:33:18 +00:00
|
|
|
========================================}
|
2005-06-30 12:18:53 +00:00
|
|
|
function TX2OIHash.CreateValueManager(): TX2CustomHashManager;
|
2004-07-29 06:33:18 +00:00
|
|
|
begin
|
2005-06-30 12:18:53 +00:00
|
|
|
Result := TX2HashIntegerManager.Create();
|
|
|
|
end;
|
2004-07-29 06:33:18 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function TX2OIHash.GetCurrentValue(): Integer;
|
|
|
|
begin
|
|
|
|
CursorRequired();
|
|
|
|
Result := TX2HashIntegerManager(ValueManager).ToValue(Cursor.Current^.Value);
|
2004-07-29 06:33:18 +00:00
|
|
|
end;
|
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function TX2OIHash.GetValue(Key: TObject): Integer;
|
2004-07-29 06:33:18 +00:00
|
|
|
var
|
2005-06-30 12:18:53 +00:00
|
|
|
pItem: PX2HashValue;
|
2004-07-29 06:33:18 +00:00
|
|
|
|
|
|
|
begin
|
2005-06-30 12:18:53 +00:00
|
|
|
Result := 0;
|
|
|
|
pItem := Find(Key, False);
|
2004-07-29 13:48:35 +00:00
|
|
|
if Assigned(pItem) then
|
2005-06-30 12:18:53 +00:00
|
|
|
Result := TX2HashIntegerManager(ValueManager).ToValue(pItem^.Value);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TX2OIHash.SetValue(Key: TObject; const Value: Integer);
|
|
|
|
begin
|
|
|
|
inherited SetValue(Find(Key, True),
|
|
|
|
TX2HashIntegerManager(ValueManager).ToPointer(Value));
|
|
|
|
end;
|
|
|
|
|
|
|
|
{========================================
|
|
|
|
TX2OOHash
|
|
|
|
========================================}
|
|
|
|
constructor TX2OOHash.Create(const AOwnsObjects: Boolean);
|
|
|
|
begin
|
|
|
|
inherited Create();
|
|
|
|
OwnsObjects := AOwnsObjects;
|
2004-07-29 06:33:18 +00:00
|
|
|
end;
|
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function TX2OOHash.CreateValueManager(): TX2CustomHashManager;
|
|
|
|
begin
|
|
|
|
Result := TX2HashObjectManager.Create();
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TX2OOHash.GetCurrentValue(): TObject;
|
|
|
|
begin
|
|
|
|
Result := TX2HashObjectManager(ValueManager).ToValue(Cursor.Current^.Value);
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TX2OOHash.GetOwnsObjects(): Boolean;
|
|
|
|
begin
|
|
|
|
Result := TX2HashObjectManager(ValueManager).OwnsObjects;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TX2OOHash.SetOwnsObjects(const Value: Boolean);
|
|
|
|
begin
|
|
|
|
TX2HashObjectManager(ValueManager).OwnsObjects := Value;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TX2OOHash.GetValue(Key: TObject): TObject;
|
2004-07-29 06:33:18 +00:00
|
|
|
var
|
2005-06-30 12:18:53 +00:00
|
|
|
pItem: PX2HashValue;
|
2004-07-29 06:33:18 +00:00
|
|
|
|
|
|
|
begin
|
2005-06-30 12:18:53 +00:00
|
|
|
Result := nil;
|
|
|
|
pItem := Find(Key, False);
|
2004-07-29 13:48:35 +00:00
|
|
|
if Assigned(pItem) then
|
2005-06-30 12:18:53 +00:00
|
|
|
Result := TX2HashObjectManager(ValueManager).ToValue(pItem^.Value);
|
2004-07-29 06:33:18 +00:00
|
|
|
end;
|
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
procedure TX2OOHash.SetValue(Key: TObject; const Value: TObject);
|
|
|
|
begin
|
|
|
|
inherited SetValue(Find(Key, True),
|
|
|
|
TX2HashObjectManager(ValueManager).ToPointer(Value));
|
|
|
|
end;
|
2004-07-29 06:33:18 +00:00
|
|
|
|
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
{========================================
|
|
|
|
TX2OSHash
|
|
|
|
========================================}
|
|
|
|
function TX2OSHash.CreateValueManager(): TX2CustomHashManager;
|
2004-07-29 06:33:18 +00:00
|
|
|
begin
|
2005-06-30 12:18:53 +00:00
|
|
|
Result := TX2HashStringManager.Create();
|
|
|
|
end;
|
2004-07-29 06:33:18 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function TX2OSHash.GetCurrentValue(): String;
|
|
|
|
begin
|
|
|
|
Result := TX2HashStringManager(ValueManager).ToValue(Cursor.Current^.Value);
|
2004-07-29 06:33:18 +00:00
|
|
|
end;
|
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function TX2OSHash.GetValue(Key: TObject): String;
|
2004-07-29 06:33:18 +00:00
|
|
|
var
|
2005-06-30 12:18:53 +00:00
|
|
|
pItem: PX2HashValue;
|
2004-07-29 06:33:18 +00:00
|
|
|
|
|
|
|
begin
|
2005-06-30 12:18:53 +00:00
|
|
|
Result := '';
|
|
|
|
pItem := Find(Key, False);
|
|
|
|
if Assigned(pItem) then
|
|
|
|
Result := TX2HashStringManager(ValueManager).ToValue(pItem^.Value);
|
|
|
|
end;
|
2004-07-29 06:33:18 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
procedure TX2OSHash.SetValue(Key: TObject; const Value: String);
|
|
|
|
begin
|
|
|
|
inherited SetValue(Find(Key, True),
|
|
|
|
TX2HashStringManager(ValueManager).ToPointer(Value));
|
2004-07-29 06:33:18 +00:00
|
|
|
end;
|
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
{========================================
|
|
|
|
TX2SPHash
|
|
|
|
========================================}
|
|
|
|
function TX2SPHash.CreateValueManager(): TX2CustomHashManager;
|
|
|
|
begin
|
|
|
|
Result := TX2HashPointerManager.Create();
|
|
|
|
end;
|
2004-07-29 06:33:18 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function TX2SPHash.GetCurrentValue(): Pointer;
|
2004-07-29 06:33:18 +00:00
|
|
|
begin
|
2005-06-30 12:18:53 +00:00
|
|
|
CursorRequired();
|
|
|
|
Result := TX2HashPointerManager(ValueManager).ToValue(Cursor.Current^.Value);
|
2004-07-29 06:33:18 +00:00
|
|
|
end;
|
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function TX2SPHash.GetValue(Key: String): Pointer;
|
|
|
|
var
|
|
|
|
pItem: PX2HashValue;
|
2004-08-20 13:03:07 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
begin
|
|
|
|
Result := nil;
|
|
|
|
pItem := Find(Key, False);
|
|
|
|
if Assigned(pItem) then
|
|
|
|
Result := TX2HashPointerManager(ValueManager).ToValue(pItem^.Value);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TX2SPHash.SetValue(Key: String; const Value: Pointer);
|
|
|
|
begin
|
|
|
|
inherited SetValue(Find(Key, True),
|
|
|
|
TX2HashPointerManager(ValueManager).ToPointer(Value));
|
|
|
|
end;
|
|
|
|
|
|
|
|
{========================================
|
|
|
|
TX2SIHash
|
2004-08-20 13:03:07 +00:00
|
|
|
========================================}
|
2005-06-30 12:18:53 +00:00
|
|
|
function TX2SIHash.CreateValueManager(): TX2CustomHashManager;
|
2004-09-01 18:19:31 +00:00
|
|
|
begin
|
2005-06-30 12:18:53 +00:00
|
|
|
Result := TX2HashIntegerManager.Create();
|
|
|
|
end;
|
2004-09-01 18:19:31 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function TX2SIHash.GetCurrentValue(): Integer;
|
|
|
|
begin
|
|
|
|
CursorRequired();
|
|
|
|
Result := TX2HashIntegerManager(ValueManager).ToValue(Cursor.Current^.Value);
|
2004-09-01 18:19:31 +00:00
|
|
|
end;
|
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function TX2SIHash.GetValue(Key: String): Integer;
|
|
|
|
var
|
|
|
|
pItem: PX2HashValue;
|
|
|
|
|
2004-09-01 18:19:31 +00:00
|
|
|
begin
|
2005-06-30 12:18:53 +00:00
|
|
|
Result := 0;
|
|
|
|
pItem := Find(Key, False);
|
|
|
|
if Assigned(pItem) then
|
|
|
|
Result := TX2HashIntegerManager(ValueManager).ToValue(pItem^.Value);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TX2SIHash.SetValue(Key: String; const Value: Integer);
|
|
|
|
begin
|
|
|
|
inherited SetValue(Find(Key, True),
|
|
|
|
TX2HashIntegerManager(ValueManager).ToPointer(Value));
|
|
|
|
end;
|
2004-09-01 18:19:31 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
{========================================
|
|
|
|
TX2SOHash
|
|
|
|
========================================}
|
|
|
|
constructor TX2SOHash.Create(const AOwnsObjects: Boolean);
|
|
|
|
begin
|
|
|
|
inherited Create();
|
|
|
|
OwnsObjects := AOwnsObjects;
|
2004-09-01 18:19:31 +00:00
|
|
|
end;
|
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function TX2SOHash.CreateValueManager(): TX2CustomHashManager;
|
|
|
|
begin
|
|
|
|
Result := TX2HashObjectManager.Create();
|
|
|
|
end;
|
2004-09-01 18:19:31 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function TX2SOHash.GetCurrentValue(): TObject;
|
2004-08-20 13:03:07 +00:00
|
|
|
begin
|
2005-06-30 12:18:53 +00:00
|
|
|
Result := TX2HashObjectManager(ValueManager).ToValue(Cursor.Current^.Value);
|
2004-08-20 13:03:07 +00:00
|
|
|
end;
|
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function TX2SOHash.GetOwnsObjects(): Boolean;
|
2004-08-20 13:03:07 +00:00
|
|
|
begin
|
2005-06-30 12:18:53 +00:00
|
|
|
Result := TX2HashObjectManager(ValueManager).OwnsObjects;
|
2004-08-20 13:03:07 +00:00
|
|
|
end;
|
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
procedure TX2SOHash.SetOwnsObjects(const Value: Boolean);
|
2004-08-20 13:03:07 +00:00
|
|
|
begin
|
2005-06-30 12:18:53 +00:00
|
|
|
TX2HashObjectManager(ValueManager).OwnsObjects := Value;
|
2004-08-20 13:03:07 +00:00
|
|
|
end;
|
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
function TX2SOHash.GetValue(Key: String): TObject;
|
2004-08-20 13:03:07 +00:00
|
|
|
var
|
2005-06-30 12:18:53 +00:00
|
|
|
pItem: PX2HashValue;
|
2004-08-20 13:03:07 +00:00
|
|
|
|
|
|
|
begin
|
2005-06-30 12:18:53 +00:00
|
|
|
Result := nil;
|
|
|
|
pItem := Find(Key, False);
|
|
|
|
if Assigned(pItem) then
|
|
|
|
Result := TX2HashObjectManager(ValueManager).ToValue(pItem^.Value);
|
|
|
|
end;
|
2004-08-20 13:03:07 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
procedure TX2SOHash.SetValue(Key: String; const Value: TObject);
|
|
|
|
begin
|
|
|
|
inherited SetValue(Find(Key, True),
|
|
|
|
TX2HashObjectManager(ValueManager).ToPointer(Value));
|
|
|
|
end;
|
2004-08-20 13:03:07 +00:00
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
|
|
|
|
{========================================
|
|
|
|
TX2SSHash
|
|
|
|
========================================}
|
|
|
|
function TX2SSHash.CreateValueManager(): TX2CustomHashManager;
|
|
|
|
begin
|
|
|
|
Result := TX2HashStringManager.Create();
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TX2SSHash.GetCurrentValue(): String;
|
|
|
|
begin
|
|
|
|
Result := TX2HashStringManager(ValueManager).ToValue(Cursor.Current^.Value);
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TX2SSHash.GetValue(Key: String): String;
|
|
|
|
var
|
|
|
|
pItem: PX2HashValue;
|
|
|
|
|
|
|
|
begin
|
|
|
|
Result := '';
|
|
|
|
pItem := Find(Key, False);
|
|
|
|
if Assigned(pItem) then
|
|
|
|
Result := TX2HashStringManager(ValueManager).ToValue(pItem^.Value);
|
2004-08-20 13:03:07 +00:00
|
|
|
end;
|
|
|
|
|
2005-06-30 12:18:53 +00:00
|
|
|
procedure TX2SSHash.SetValue(Key: String; const Value: String);
|
|
|
|
begin
|
|
|
|
inherited SetValue(Find(Key, True),
|
|
|
|
TX2HashStringManager(ValueManager).ToPointer(Value));
|
|
|
|
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
|
|
|
|
CRC32Init();
|
|
|
|
|
2004-07-29 06:33:18 +00:00
|
|
|
end.
|