Is there anything like a map or a hashtable in Delphi 6?
I´ve used a library called Hashes.pas from Ciaran McCreesh but since his website is no longer available you can see the single PAS file from the following URL:
Link to Ciaran McCreesh - Hashes.pas
You can also find it with google with the text: "Ciaran McCreesh Hashes"
With this library you can do the following:
aString := TStringHash.Create;
aString['color'] := 'blue';
ShowMessage(aString.Items['color']); // blue
Or objects:
aObj := TObjectHash.Create;
aObj['color'] := TBlueClass.Create;
bcBlue:=(aObj.Items['color'] as TBlueClass);
ShowMessage(bcBlue.Name); // Blue (supposing the TBLusClass as a Name property...
Hope it serves you as well as for me.
PS I think the Ares AudioGalaxy project also uses it.
The Jedi Code Library contains some advanced container classes. Interfaces are declared in JclContainerIntf.pas, for example:
IJclMap = interface(IJclContainer)
['{A7D0A882-6952-496D-A258-23D47DDCCBC4}']
procedure Clear;
function ContainsKey(Key: TObject): Boolean;
function ContainsValue(Value: TObject): Boolean;
function Extract(Key: TObject): TObject;
function GetValue(Key: TObject): TObject;
function IsEmpty: Boolean;
function KeyOfValue(Value: TObject): TObject;
function KeySet: IJclSet;
function MapEquals(const AMap: IJclMap): Boolean;
procedure PutAll(const AMap: IJclMap);
procedure PutValue(Key, Value: TObject);
function Remove(Key: TObject): TObject;
function Size: Integer;
function Values: IJclCollection;
property Items[Key: TObject]: TObject read GetValue write PutValue;
{$IFNDEF BUGGY_DEFAULT_INDEXED_PROP} default; {$ENDIF ~BUGGY_DEFAULT_INDEXED_PROP}
end;
I have tested TStringList and some THashTable implementations and the differences between the two implementations are minimal, and in most cases TStringList (with dicotomical sort implementation) are more efficient than THashTable.
For a small number of values TStringList is faster than Hash, and for a large number of values you must find a complex hash-function for minimize the collision, and this complexity decreases the efficiency of the HashList.
You must use the Object pointer of the StringList to store all the information that you need (the second string).
Regards.
Depending on your exact needs, you might want to use the TStringList object.