|
|
@@ -110,10 +110,10 @@ type |
|
|
function CreateItem: PListItem; virtual; |
|
|
function CreateItem: PListItem; virtual; |
|
|
procedure DestroyItem(const aItem: PListItem; const aFreeItem: Boolean = true); virtual; |
|
|
procedure DestroyItem(const aItem: PListItem; const aFreeItem: Boolean = true); virtual; |
|
|
procedure InsertIntern(const aIndex: Integer; const aItem: T); virtual; |
|
|
procedure InsertIntern(const aIndex: Integer; const aItem: T); virtual; |
|
|
procedure DeleteIntern(const aIndex: Integer; const aFreeItem: Boolean = true); |
|
|
|
|
|
|
|
|
procedure DeleteIntern(const aIndex: Integer; const aFreeItem: Boolean = true); virtual; |
|
|
|
|
|
|
|
|
public |
|
|
public |
|
|
property OwnsObjects: Boolean read fOwnsObjects write fOwnsObjects; |
|
|
|
|
|
|
|
|
property OwnsObjects: Boolean read fOwnsObjects write fOwnsObjects; |
|
|
|
|
|
|
|
|
function GetEnumerator: TEnumerator; |
|
|
function GetEnumerator: TEnumerator; |
|
|
function GetReverseEnumerator: TEnumerator; |
|
|
function GetReverseEnumerator: TEnumerator; |
|
|
@@ -178,12 +178,20 @@ type |
|
|
end; |
|
|
end; |
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
generic TutlCustomHashSet<T> = class(specialize TutlListBase<T>) |
|
|
|
|
|
|
|
|
generic TutlHashSetBase<T> = class(specialize TutlListBase<T>) |
|
|
public type |
|
|
public type |
|
|
IComparer = specialize IutlComparer<T>; |
|
|
IComparer = specialize IutlComparer<T>; |
|
|
private |
|
|
private |
|
|
fComparer: IComparer; |
|
|
fComparer: IComparer; |
|
|
|
|
|
protected |
|
|
function SearchItem(const aMin, aMax: Integer; const aItem: T; out aIndex: Integer): Integer; |
|
|
function SearchItem(const aMin, aMax: Integer; const aItem: T; out aIndex: Integer): Integer; |
|
|
|
|
|
public |
|
|
|
|
|
constructor Create(aComparer: IComparer; const aOwnsObjects: Boolean = true); |
|
|
|
|
|
destructor Destroy; override; |
|
|
|
|
|
end; |
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
|
|
|
generic TutlCustomHashSet<T> = class(specialize TutlHashSetBase<T>) |
|
|
public |
|
|
public |
|
|
property Items[const aIndex: Integer]: T read GetItem; default; |
|
|
property Items[const aIndex: Integer]: T read GetItem; default; |
|
|
property Count: Integer read GetCount; |
|
|
property Count: Integer read GetCount; |
|
|
@@ -193,9 +201,6 @@ type |
|
|
function IndexOf(const aItem: T): Integer; |
|
|
function IndexOf(const aItem: T): Integer; |
|
|
function Remove(const aItem: T): Boolean; |
|
|
function Remove(const aItem: T): Boolean; |
|
|
procedure Delete(const aIndex: Integer); |
|
|
procedure Delete(const aIndex: Integer); |
|
|
|
|
|
|
|
|
constructor Create(aComparer: IComparer; const aOwnsObjects: Boolean = true); |
|
|
|
|
|
destructor Destroy; override; |
|
|
|
|
|
end; |
|
|
end; |
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
@@ -216,23 +221,23 @@ type |
|
|
public |
|
|
public |
|
|
constructor Create; |
|
|
constructor Create; |
|
|
end; |
|
|
end; |
|
|
generic TutlCustomMap<TKey, TValue> = class(TObject) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
generic TutlMapBase<TKey, TValue> = class(TObject) |
|
|
public type |
|
|
public type |
|
|
IComparer = specialize IutlComparer<TKey>; |
|
|
IComparer = specialize IutlComparer<TKey>; |
|
|
TKeyValuePair = packed record |
|
|
TKeyValuePair = packed record |
|
|
Key: TKey; |
|
|
Key: TKey; |
|
|
Value: TValue; |
|
|
Value: TValue; |
|
|
end; |
|
|
end; |
|
|
private type |
|
|
|
|
|
THashSetBase = specialize TutlCustomHashSet<TKeyValuePair>; |
|
|
|
|
|
THashSet = class(THashSetBase) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
THashSet = class(specialize TutlCustomHashSet<TKeyValuePair>) |
|
|
protected |
|
|
protected |
|
|
procedure DestroyItem(const aItem: PListItem; const aFreeItem: Boolean = true); override; |
|
|
procedure DestroyItem(const aItem: PListItem; const aFreeItem: Boolean = true); override; |
|
|
public |
|
|
public |
|
|
property Items[const aIndex: Integer]: TKeyValuePair read GetItem write SetItem; default; |
|
|
property Items[const aIndex: Integer]: TKeyValuePair read GetItem write SetItem; default; |
|
|
end; |
|
|
end; |
|
|
|
|
|
|
|
|
TKVPComparer = class(TInterfacedObject, THashSet.IComparer) |
|
|
|
|
|
|
|
|
TKeyValuePairComparer = class(TInterfacedObject, THashSet.IComparer) |
|
|
private |
|
|
private |
|
|
fComparer: IComparer; |
|
|
fComparer: IComparer; |
|
|
public |
|
|
public |
|
|
@@ -299,8 +304,7 @@ type |
|
|
end; |
|
|
end; |
|
|
|
|
|
|
|
|
private |
|
|
private |
|
|
fComparer: IComparer; |
|
|
|
|
|
fHashSet: THashSet; |
|
|
|
|
|
|
|
|
fHashSetRef: THashSet; |
|
|
fKeyWrapper: TKeyWrapper; |
|
|
fKeyWrapper: TKeyWrapper; |
|
|
fKeyValuePairWrapper: TKeyValuePairWrapper; |
|
|
fKeyValuePairWrapper: TKeyValuePairWrapper; |
|
|
|
|
|
|
|
|
@@ -326,7 +330,16 @@ type |
|
|
|
|
|
|
|
|
function GetEnumerator: TValueEnumerator; |
|
|
function GetEnumerator: TValueEnumerator; |
|
|
|
|
|
|
|
|
constructor Create(aComparer: IComparer; const aOwnsObjects: Boolean = true); |
|
|
|
|
|
|
|
|
constructor Create(const aHashSet: THashSet); |
|
|
|
|
|
destructor Destroy; override; |
|
|
|
|
|
end; |
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
|
|
|
generic TutlCustomMap<TKey, TValue> = class(specialize TutlMapBase<TKey, TValue>) |
|
|
|
|
|
private |
|
|
|
|
|
fHashSetImpl: THashSet; |
|
|
|
|
|
public |
|
|
|
|
|
constructor Create(const aComparer: IComparer; const aOwnsObjects: Boolean = true); |
|
|
destructor Destroy; override; |
|
|
destructor Destroy; override; |
|
|
end; |
|
|
end; |
|
|
|
|
|
|
|
|
@@ -629,6 +642,20 @@ begin |
|
|
end; |
|
|
end; |
|
|
end; |
|
|
end; |
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
|
|
|
constructor TutlCustomMap.Create(const aComparer: IComparer; const aOwnsObjects: Boolean); |
|
|
|
|
|
begin |
|
|
|
|
|
fHashSetImpl := THashSet.Create(TKeyValuePairComparer.Create(aComparer), aOwnsObjects); |
|
|
|
|
|
inherited Create(fHashSetImpl); |
|
|
|
|
|
end; |
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
|
|
|
destructor TutlCustomMap.Destroy; |
|
|
|
|
|
begin |
|
|
|
|
|
inherited Destroy; |
|
|
|
|
|
FreeAndNil(fHashSetImpl); |
|
|
|
|
|
end; |
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
//EutlEnumConvert/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
//EutlEnumConvert/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
@@ -1094,9 +1121,9 @@ begin |
|
|
end; |
|
|
end; |
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
//TutlCustomHashSet///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
|
|
|
|
|
|
//TutlHashSetBase/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
function TutlCustomHashSet.SearchItem(const aMin, aMax: Integer; const aItem: T; out aIndex: Integer): Integer; |
|
|
|
|
|
|
|
|
function TutlHashSetBase.SearchItem(const aMin, aMax: Integer; const aItem: T; out aIndex: Integer): Integer; |
|
|
var |
|
|
var |
|
|
i, cmp: Integer; |
|
|
i, cmp: Integer; |
|
|
begin |
|
|
begin |
|
|
@@ -1115,6 +1142,22 @@ begin |
|
|
end; |
|
|
end; |
|
|
end; |
|
|
end; |
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
|
|
|
constructor TutlHashSetBase.Create(aComparer: IComparer; const aOwnsObjects: Boolean); |
|
|
|
|
|
begin |
|
|
|
|
|
inherited Create(aOwnsObjects); |
|
|
|
|
|
fComparer := aComparer; |
|
|
|
|
|
end; |
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
|
|
|
destructor TutlHashSetBase.Destroy; |
|
|
|
|
|
begin |
|
|
|
|
|
fComparer := nil; |
|
|
|
|
|
inherited Destroy; |
|
|
|
|
|
end; |
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
|
|
|
//TutlCustomHashSet///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
function TutlCustomHashSet.Add(const aItem: T): Boolean; |
|
|
function TutlCustomHashSet.Add(const aItem: T): Boolean; |
|
|
var |
|
|
var |
|
|
@@ -1158,20 +1201,6 @@ begin |
|
|
DeleteIntern(aIndex); |
|
|
DeleteIntern(aIndex); |
|
|
end; |
|
|
end; |
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
|
|
|
constructor TutlCustomHashSet.Create(aComparer: IComparer; const aOwnsObjects: Boolean); |
|
|
|
|
|
begin |
|
|
|
|
|
inherited Create(aOwnsObjects); |
|
|
|
|
|
fComparer := aComparer; |
|
|
|
|
|
end; |
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
|
|
|
destructor TutlCustomHashSet.Destroy; |
|
|
|
|
|
begin |
|
|
|
|
|
fComparer := nil; |
|
|
|
|
|
inherited Destroy; |
|
|
|
|
|
end; |
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
//TutlHashSet/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
//TutlHashSet/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
@@ -1181,9 +1210,9 @@ begin |
|
|
end; |
|
|
end; |
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
//TutlCustomMap.THashSet//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
|
|
|
|
|
|
//TutlMapBase.THashSet////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
procedure TutlCustomMap.THashSet.DestroyItem(const aItem: PListItem; const aFreeItem: Boolean); |
|
|
|
|
|
|
|
|
procedure TutlMapBase.THashSet.DestroyItem(const aItem: PListItem; const aFreeItem: Boolean); |
|
|
begin |
|
|
begin |
|
|
// never free objects used as keys, but do finalize strings, interfaces etc. |
|
|
// never free objects used as keys, but do finalize strings, interfaces etc. |
|
|
utlFreeOrFinalize(aItem^.data.key, TypeInfo(aItem^.data.key), false); |
|
|
utlFreeOrFinalize(aItem^.data.key, TypeInfo(aItem^.data.key), false); |
|
|
@@ -1192,44 +1221,44 @@ begin |
|
|
end; |
|
|
end; |
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
//TutlCustomMap.TKVPComparer//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
|
|
|
|
|
|
//TutlMapBase.TKeyValuePairComparer///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
function TutlCustomMap.TKVPComparer.Compare(const i1, i2: TKeyValuePair): Integer; |
|
|
|
|
|
|
|
|
function TutlMapBase.TKeyValuePairComparer.Compare(const i1, i2: TKeyValuePair): Integer; |
|
|
begin |
|
|
begin |
|
|
result := fComparer.Compare(i1.Key, i2.Key); |
|
|
result := fComparer.Compare(i1.Key, i2.Key); |
|
|
end; |
|
|
end; |
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
constructor TutlCustomMap.TKVPComparer.Create(aComparer: IComparer); |
|
|
|
|
|
|
|
|
constructor TutlMapBase.TKeyValuePairComparer.Create(aComparer: IComparer); |
|
|
begin |
|
|
begin |
|
|
inherited Create; |
|
|
inherited Create; |
|
|
fComparer := aComparer; |
|
|
fComparer := aComparer; |
|
|
end; |
|
|
end; |
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
destructor TutlCustomMap.TKVPComparer.Destroy; |
|
|
|
|
|
|
|
|
destructor TutlMapBase.TKeyValuePairComparer.Destroy; |
|
|
begin |
|
|
begin |
|
|
fComparer := nil; |
|
|
fComparer := nil; |
|
|
inherited Destroy; |
|
|
inherited Destroy; |
|
|
end; |
|
|
end; |
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
//TutlCustomMap.TValueEnumerator//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
|
|
|
|
|
|
//TutlMapBase.TValueEnumerator////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
function TutlCustomMap.TValueEnumerator.GetCurrent: TValue; |
|
|
|
|
|
|
|
|
function TutlMapBase.TValueEnumerator.GetCurrent: TValue; |
|
|
begin |
|
|
begin |
|
|
result := fHashSet[fPos].Value; |
|
|
result := fHashSet[fPos].Value; |
|
|
end; |
|
|
end; |
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
function TutlCustomMap.TValueEnumerator.MoveNext: Boolean; |
|
|
|
|
|
|
|
|
function TutlMapBase.TValueEnumerator.MoveNext: Boolean; |
|
|
begin |
|
|
begin |
|
|
inc(fPos); |
|
|
inc(fPos); |
|
|
result := (fPos < fHashSet.Count); |
|
|
result := (fPos < fHashSet.Count); |
|
|
end; |
|
|
end; |
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
constructor TutlCustomMap.TValueEnumerator.Create(const aHashSet: THashSet); |
|
|
|
|
|
|
|
|
constructor TutlMapBase.TValueEnumerator.Create(const aHashSet: THashSet); |
|
|
begin |
|
|
begin |
|
|
inherited Create; |
|
|
inherited Create; |
|
|
fHashSet := aHashSet; |
|
|
fHashSet := aHashSet; |
|
|
@@ -1237,22 +1266,22 @@ begin |
|
|
end; |
|
|
end; |
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
//TutlCustomMap.TKeyEnumerator////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
|
|
|
|
|
|
//TutlMapBase.TKeyEnumerator//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
function TutlCustomMap.TKeyEnumerator.GetCurrent: TKey; |
|
|
|
|
|
|
|
|
function TutlMapBase.TKeyEnumerator.GetCurrent: TKey; |
|
|
begin |
|
|
begin |
|
|
result := fHashSet[fPos].Key; |
|
|
result := fHashSet[fPos].Key; |
|
|
end; |
|
|
end; |
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
function TutlCustomMap.TKeyEnumerator.MoveNext: Boolean; |
|
|
|
|
|
|
|
|
function TutlMapBase.TKeyEnumerator.MoveNext: Boolean; |
|
|
begin |
|
|
begin |
|
|
inc(fPos); |
|
|
inc(fPos); |
|
|
result := (fPos < fHashSet.Count); |
|
|
result := (fPos < fHashSet.Count); |
|
|
end; |
|
|
end; |
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
constructor TutlCustomMap.TKeyEnumerator.Create(const aHashSet: THashSet); |
|
|
|
|
|
|
|
|
constructor TutlMapBase.TKeyEnumerator.Create(const aHashSet: THashSet); |
|
|
begin |
|
|
begin |
|
|
inherited Create; |
|
|
inherited Create; |
|
|
fHashSet := aHashSet; |
|
|
fHashSet := aHashSet; |
|
|
@@ -1260,22 +1289,22 @@ begin |
|
|
end; |
|
|
end; |
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
//TutlCustomMap.TKeyValuePairEnumerator///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
|
|
|
|
|
|
//TutlMapBase.TKeyValuePairEnumerator/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
function TutlCustomMap.TKeyValuePairEnumerator.GetCurrent: TKeyValuePair; |
|
|
|
|
|
|
|
|
function TutlMapBase.TKeyValuePairEnumerator.GetCurrent: TKeyValuePair; |
|
|
begin |
|
|
begin |
|
|
result := fHashSet[fPos]; |
|
|
result := fHashSet[fPos]; |
|
|
end; |
|
|
end; |
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
function TutlCustomMap.TKeyValuePairEnumerator.MoveNext: Boolean; |
|
|
|
|
|
|
|
|
function TutlMapBase.TKeyValuePairEnumerator.MoveNext: Boolean; |
|
|
begin |
|
|
begin |
|
|
inc(fPos); |
|
|
inc(fPos); |
|
|
result := (fPos < fHashSet.Count); |
|
|
result := (fPos < fHashSet.Count); |
|
|
end; |
|
|
end; |
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
constructor TutlCustomMap.TKeyValuePairEnumerator.Create(const aHashSet: THashSet); |
|
|
|
|
|
|
|
|
constructor TutlMapBase.TKeyValuePairEnumerator.Create(const aHashSet: THashSet); |
|
|
begin |
|
|
begin |
|
|
inherited Create; |
|
|
inherited Create; |
|
|
fHashSet := aHashSet; |
|
|
fHashSet := aHashSet; |
|
|
@@ -1283,185 +1312,183 @@ begin |
|
|
end; |
|
|
end; |
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
//TutlCustomMap.TKeyWrapper///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
|
|
|
|
|
|
//TutlMapBase.TKeyWrapper/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
function TutlCustomMap.TKeyWrapper.GetItem(const aIndex: Integer): TKey; |
|
|
|
|
|
|
|
|
function TutlMapBase.TKeyWrapper.GetItem(const aIndex: Integer): TKey; |
|
|
begin |
|
|
begin |
|
|
result := fHashSet[aIndex].Key; |
|
|
result := fHashSet[aIndex].Key; |
|
|
end; |
|
|
end; |
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
function TutlCustomMap.TKeyWrapper.GetCount: Integer; |
|
|
|
|
|
|
|
|
function TutlMapBase.TKeyWrapper.GetCount: Integer; |
|
|
begin |
|
|
begin |
|
|
result := fHashSet.Count; |
|
|
result := fHashSet.Count; |
|
|
end; |
|
|
end; |
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
function TutlCustomMap.TKeyWrapper.GetEnumerator: TKeyEnumerator; |
|
|
|
|
|
|
|
|
function TutlMapBase.TKeyWrapper.GetEnumerator: TKeyEnumerator; |
|
|
begin |
|
|
begin |
|
|
result := TKeyEnumerator.Create(fHashSet); |
|
|
result := TKeyEnumerator.Create(fHashSet); |
|
|
end; |
|
|
end; |
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
constructor TutlCustomMap.TKeyWrapper.Create(const aHashSet: THashSet); |
|
|
|
|
|
|
|
|
constructor TutlMapBase.TKeyWrapper.Create(const aHashSet: THashSet); |
|
|
begin |
|
|
begin |
|
|
inherited Create; |
|
|
inherited Create; |
|
|
fHashSet := aHashSet; |
|
|
fHashSet := aHashSet; |
|
|
end; |
|
|
end; |
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
//TutlCustomMap.TKeyValuePairWrapper//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
|
|
|
|
|
|
//TutlMapBase.TKeyValuePairWrapper////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
function TutlCustomMap.TKeyValuePairWrapper.GetItem(const aIndex: Integer): TKeyValuePair; |
|
|
|
|
|
|
|
|
function TutlMapBase.TKeyValuePairWrapper.GetItem(const aIndex: Integer): TKeyValuePair; |
|
|
begin |
|
|
begin |
|
|
result := fHashSet[aIndex]; |
|
|
result := fHashSet[aIndex]; |
|
|
end; |
|
|
end; |
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
function TutlCustomMap.TKeyValuePairWrapper.GetCount: Integer; |
|
|
|
|
|
|
|
|
function TutlMapBase.TKeyValuePairWrapper.GetCount: Integer; |
|
|
begin |
|
|
begin |
|
|
result := fHashSet.Count; |
|
|
result := fHashSet.Count; |
|
|
end; |
|
|
end; |
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
function TutlCustomMap.TKeyValuePairWrapper.GetEnumerator: TKeyValuePairEnumerator; |
|
|
|
|
|
|
|
|
function TutlMapBase.TKeyValuePairWrapper.GetEnumerator: TKeyValuePairEnumerator; |
|
|
begin |
|
|
begin |
|
|
result := TKeyValuePairEnumerator.Create(fHashSet); |
|
|
result := TKeyValuePairEnumerator.Create(fHashSet); |
|
|
end; |
|
|
end; |
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
constructor TutlCustomMap.TKeyValuePairWrapper.Create(const aHashSet: THashSet); |
|
|
|
|
|
|
|
|
constructor TutlMapBase.TKeyValuePairWrapper.Create(const aHashSet: THashSet); |
|
|
begin |
|
|
begin |
|
|
inherited Create; |
|
|
inherited Create; |
|
|
fHashSet := aHashSet; |
|
|
fHashSet := aHashSet; |
|
|
end; |
|
|
end; |
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
//TutlCustomMap///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
|
|
|
|
|
|
//TutlMapBase/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
function TutlCustomMap.GetValues(const aKey: TKey): TValue; |
|
|
|
|
|
|
|
|
function TutlMapBase.GetValues(const aKey: TKey): TValue; |
|
|
var |
|
|
var |
|
|
i: Integer; |
|
|
i: Integer; |
|
|
kvp: TKeyValuePair; |
|
|
kvp: TKeyValuePair; |
|
|
begin |
|
|
begin |
|
|
kvp.Key := aKey; |
|
|
kvp.Key := aKey; |
|
|
i := fHashSet.IndexOf(kvp); |
|
|
|
|
|
|
|
|
i := fHashSetRef.IndexOf(kvp); |
|
|
if (i < 0) then |
|
|
if (i < 0) then |
|
|
FillByte(result{%H-}, SizeOf(result), 0) |
|
|
FillByte(result{%H-}, SizeOf(result), 0) |
|
|
else |
|
|
else |
|
|
result := fHashSet[i].Value; |
|
|
|
|
|
|
|
|
result := fHashSetRef[i].Value; |
|
|
end; |
|
|
end; |
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
function TutlCustomMap.GetValueAt(const aIndex: Integer): TValue; |
|
|
|
|
|
|
|
|
function TutlMapBase.GetValueAt(const aIndex: Integer): TValue; |
|
|
begin |
|
|
begin |
|
|
result := fHashSet[aIndex].Value; |
|
|
|
|
|
|
|
|
result := fHashSetRef[aIndex].Value; |
|
|
end; |
|
|
end; |
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
function TutlCustomMap.GetCount: Integer; |
|
|
|
|
|
|
|
|
function TutlMapBase.GetCount: Integer; |
|
|
begin |
|
|
begin |
|
|
result := fHashSet.Count; |
|
|
|
|
|
|
|
|
result := fHashSetRef.Count; |
|
|
end; |
|
|
end; |
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
procedure TutlCustomMap.SetValues(const aKey: TKey; aValue: TValue); |
|
|
|
|
|
|
|
|
procedure TutlMapBase.SetValues(const aKey: TKey; aValue: TValue); |
|
|
var |
|
|
var |
|
|
i: Integer; |
|
|
i: Integer; |
|
|
kvp: TKeyValuePair; |
|
|
kvp: TKeyValuePair; |
|
|
begin |
|
|
begin |
|
|
kvp.Key := aKey; |
|
|
kvp.Key := aKey; |
|
|
kvp.Value := aValue; |
|
|
kvp.Value := aValue; |
|
|
i := fHashSet.IndexOf(kvp); |
|
|
|
|
|
|
|
|
i := fHashSetRef.IndexOf(kvp); |
|
|
if (i < 0) then |
|
|
if (i < 0) then |
|
|
raise EutlMap.Create('key not found'); |
|
|
raise EutlMap.Create('key not found'); |
|
|
fHashSet[i] := kvp; |
|
|
|
|
|
|
|
|
fHashSetRef[i] := kvp; |
|
|
end; |
|
|
end; |
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
procedure TutlCustomMap.SetValueAt(const aIndex: Integer; aValue: TValue); |
|
|
|
|
|
|
|
|
procedure TutlMapBase.SetValueAt(const aIndex: Integer; aValue: TValue); |
|
|
var |
|
|
var |
|
|
kvp: TKeyValuePair; |
|
|
kvp: TKeyValuePair; |
|
|
begin |
|
|
begin |
|
|
kvp := fHashSet[aIndex]; |
|
|
|
|
|
|
|
|
kvp := fHashSetRef[aIndex]; |
|
|
kvp.Value := aValue; |
|
|
kvp.Value := aValue; |
|
|
fHashSet[aIndex] := kvp; |
|
|
|
|
|
|
|
|
fHashSetRef[aIndex] := kvp; |
|
|
end; |
|
|
end; |
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
procedure TutlCustomMap.Add(const aKey: TKey; const aValue: TValue); |
|
|
|
|
|
|
|
|
procedure TutlMapBase.Add(const aKey: TKey; const aValue: TValue); |
|
|
var |
|
|
var |
|
|
kvp: TKeyValuePair; |
|
|
kvp: TKeyValuePair; |
|
|
begin |
|
|
begin |
|
|
kvp.Key := aKey; |
|
|
kvp.Key := aKey; |
|
|
kvp.Value := aValue; |
|
|
kvp.Value := aValue; |
|
|
if not fHashSet.Add(kvp) then |
|
|
|
|
|
|
|
|
if not fHashSetRef.Add(kvp) then |
|
|
raise EutlMapKeyAlreadyExists.Create(); |
|
|
raise EutlMapKeyAlreadyExists.Create(); |
|
|
end; |
|
|
end; |
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
function TutlCustomMap.IndexOf(const aKey: TKey): Integer; |
|
|
|
|
|
|
|
|
function TutlMapBase.IndexOf(const aKey: TKey): Integer; |
|
|
var |
|
|
var |
|
|
kvp: TKeyValuePair; |
|
|
kvp: TKeyValuePair; |
|
|
begin |
|
|
begin |
|
|
kvp.Key := aKey; |
|
|
kvp.Key := aKey; |
|
|
result := fHashSet.IndexOf(kvp); |
|
|
|
|
|
|
|
|
result := fHashSetRef.IndexOf(kvp); |
|
|
end; |
|
|
end; |
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
function TutlCustomMap.Contains(const aKey: TKey): Boolean; |
|
|
|
|
|
|
|
|
function TutlMapBase.Contains(const aKey: TKey): Boolean; |
|
|
var |
|
|
var |
|
|
kvp: TKeyValuePair; |
|
|
kvp: TKeyValuePair; |
|
|
begin |
|
|
begin |
|
|
kvp.Key := aKey; |
|
|
kvp.Key := aKey; |
|
|
result := (fHashSet.IndexOf(kvp) >= 0); |
|
|
|
|
|
|
|
|
result := (fHashSetRef.IndexOf(kvp) >= 0); |
|
|
end; |
|
|
end; |
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
procedure TutlCustomMap.Delete(const aKey: TKey); |
|
|
|
|
|
|
|
|
procedure TutlMapBase.Delete(const aKey: TKey); |
|
|
var |
|
|
var |
|
|
kvp: TKeyValuePair; |
|
|
kvp: TKeyValuePair; |
|
|
begin |
|
|
begin |
|
|
kvp.Key := aKey; |
|
|
kvp.Key := aKey; |
|
|
if not fHashSet.Remove(kvp) then |
|
|
|
|
|
|
|
|
if not fHashSetRef.Remove(kvp) then |
|
|
raise EutlMapKeyNotFound.Create; |
|
|
raise EutlMapKeyNotFound.Create; |
|
|
end; |
|
|
end; |
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
procedure TutlCustomMap.DeleteAt(const aIndex: Integer); |
|
|
|
|
|
|
|
|
procedure TutlMapBase.DeleteAt(const aIndex: Integer); |
|
|
begin |
|
|
begin |
|
|
fHashSet.Delete(aIndex); |
|
|
|
|
|
|
|
|
fHashSetRef.Delete(aIndex); |
|
|
end; |
|
|
end; |
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
procedure TutlCustomMap.Clear; |
|
|
|
|
|
|
|
|
procedure TutlMapBase.Clear; |
|
|
begin |
|
|
begin |
|
|
fHashSet.Clear; |
|
|
|
|
|
|
|
|
fHashSetRef.Clear; |
|
|
end; |
|
|
end; |
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
function TutlCustomMap.GetEnumerator: TValueEnumerator; |
|
|
|
|
|
|
|
|
function TutlMapBase.GetEnumerator: TValueEnumerator; |
|
|
begin |
|
|
begin |
|
|
result := TValueEnumerator.Create(fHashSet); |
|
|
|
|
|
|
|
|
result := TValueEnumerator.Create(fHashSetRef); |
|
|
end; |
|
|
end; |
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
constructor TutlCustomMap.Create(aComparer: IComparer; const aOwnsObjects: Boolean); |
|
|
|
|
|
|
|
|
constructor TutlMapBase.Create(const aHashSet: THashSet); |
|
|
begin |
|
|
begin |
|
|
inherited Create; |
|
|
inherited Create; |
|
|
fComparer := aComparer; |
|
|
|
|
|
fHashSet := THashSet.Create(TKVPComparer.Create(fComparer), aOwnsObjects); |
|
|
|
|
|
fKeyWrapper := TKeyWrapper.Create(fHashSet); |
|
|
|
|
|
fKeyValuePairWrapper := TKeyValuePairWrapper.Create(fHashSet); |
|
|
|
|
|
|
|
|
fHashSetRef := aHashSet; |
|
|
|
|
|
fKeyWrapper := TKeyWrapper.Create(fHashSetRef); |
|
|
|
|
|
fKeyValuePairWrapper := TKeyValuePairWrapper.Create(fHashSetRef); |
|
|
end; |
|
|
end; |
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
destructor TutlCustomMap.Destroy; |
|
|
|
|
|
|
|
|
destructor TutlMapBase.Destroy; |
|
|
begin |
|
|
begin |
|
|
FreeAndNil(fKeyValuePairWrapper); |
|
|
FreeAndNil(fKeyValuePairWrapper); |
|
|
FreeAndNil(fKeyWrapper); |
|
|
FreeAndNil(fKeyWrapper); |
|
|
FreeAndNil(fHashSet); |
|
|
|
|
|
fComparer := nil; |
|
|
|
|
|
|
|
|
fHashSetRef := nil; |
|
|
inherited Destroy; |
|
|
inherited Destroy; |
|
|
end; |
|
|
end; |
|
|
|
|
|
|
|
|
|