Added: Pointer and Integer hashes
This commit is contained in:
parent
b105c57f5b
commit
c47722f0db
@ -188,7 +188,4 @@ c:\program files\borland\delphi6\Bin\dclwebsnap60.bpl=Borland WebSnap Components
|
||||
c:\program files\borland\delphi6\Bin\dclite60.bpl=Borland Integrated Translation Environment
|
||||
c:\program files\borland\delphi6\Bin\dcldbx60.bpl=Borland dbExpress Components
|
||||
c:\program files\borland\delphi6\Bin\dcldbxcds60.bpl=Borland Local DBX ClientDataset Components
|
||||
<<<<<<< .working
|
||||
=======
|
||||
F:\Delphi\Components\DevExpress\OrgChart Suite\Lib\dcldxDBOrD6.bpl=ExpressDBOrgChart by Developer Express Inc.
|
||||
>>>>>>> .merge-right.r40
|
||||
|
@ -11,24 +11,6 @@ uses
|
||||
FBTree in 'Forms\FBTree.pas' {frmBTree};
|
||||
|
||||
|
||||
<<<<<<< .working
|
||||
procedure DebugBTree(const ANode: PX2UtBTreeNode; const AIndent: Integer = 0);
|
||||
begin
|
||||
WriteLn(StringOfChar(' ', AIndent), ANode^.Index);
|
||||
|
||||
if Assigned(ANode^.Left) then
|
||||
DebugBTree(ANode^.Left, AIndent + 2);
|
||||
|
||||
if Assigned(ANode^.Right) then
|
||||
DebugBTree(ANode^.Right, AIndent + 2);
|
||||
end;
|
||||
|
||||
|
||||
type
|
||||
THackBTree = class(TX2UtCustomBTree);
|
||||
|
||||
=======
|
||||
>>>>>>> .merge-right.r40
|
||||
var
|
||||
shData: TX2UtStringHash;
|
||||
btTest: TX2UtStringBTree;
|
||||
@ -44,22 +26,8 @@ begin
|
||||
for iItem := 0 to 61 do
|
||||
btTest[Random(500)] := 'bla';
|
||||
|
||||
<<<<<<< .working
|
||||
btTest[300] := 'bla';
|
||||
btTest.Delete(300);
|
||||
=======
|
||||
TfrmBTree.Execute(btTest);
|
||||
>>>>>>> .merge-right.r40
|
||||
|
||||
<<<<<<< .working
|
||||
// Heh, hacking my own class. This is just for debugging the tree,
|
||||
// there should never be any need to access the root node outside of the
|
||||
// class otherwise, so I made it protected.
|
||||
pItem := THackBTree(btTest).Root;
|
||||
DebugBTree(pItem);
|
||||
|
||||
=======
|
||||
>>>>>>> .merge-right.r40
|
||||
WriteLn;
|
||||
btTest.Reset();
|
||||
while btTest.Next() do
|
||||
|
@ -200,6 +200,7 @@ type
|
||||
protected
|
||||
function GetItem(Index: Cardinal): Integer;
|
||||
procedure SetItem(Index: Cardinal; const Value: Integer);
|
||||
|
||||
function GetCurrentValue(): Integer;
|
||||
public
|
||||
//:$ Gets or sets an item.
|
||||
@ -571,6 +572,8 @@ end;
|
||||
|
||||
function TX2UtCustomBTree.DeleteLeftShrunk;
|
||||
begin
|
||||
Result := CError;
|
||||
|
||||
case ANode^.Balance of
|
||||
-1:
|
||||
begin
|
||||
@ -634,6 +637,8 @@ end;
|
||||
|
||||
function TX2UtCustomBTree.DeleteRightShrunk;
|
||||
begin
|
||||
Result := CError;
|
||||
|
||||
case ANode^.Balance of
|
||||
1:
|
||||
begin
|
||||
|
@ -25,7 +25,7 @@ type
|
||||
Prev: PX2UtHashItem;
|
||||
Next: PX2UtHashItem;
|
||||
Key: String;
|
||||
Value: record end;
|
||||
Data: record end;
|
||||
end;
|
||||
|
||||
{
|
||||
@ -91,7 +91,6 @@ type
|
||||
{
|
||||
:$ Hash implementation for pointer values
|
||||
}
|
||||
(*
|
||||
TX2UtHash = class(TX2UtCustomHash)
|
||||
private
|
||||
function GetItem(Key: String): Pointer;
|
||||
@ -109,7 +108,25 @@ type
|
||||
//:$ Returns the value at the current cursor location.
|
||||
property CurrentValue: Pointer read GetCurrentValue;
|
||||
end;
|
||||
*)
|
||||
|
||||
{
|
||||
:$ Hash implementation for integer values
|
||||
}
|
||||
TX2UtIntegerHash = class(TX2UtHash)
|
||||
private
|
||||
function GetItem(Key: String): Integer;
|
||||
procedure SetItem(Key: String; const Value: Integer);
|
||||
|
||||
function GetCurrentValue(): Integer;
|
||||
public
|
||||
//:$ Gets or sets an item.
|
||||
property Items[Key: String]: Integer read GetItem
|
||||
write SetItem; default;
|
||||
|
||||
//:$ Returns the value at the current cursor location.
|
||||
property CurrentValue: Integer read GetCurrentValue;
|
||||
end;
|
||||
|
||||
|
||||
{
|
||||
:$ Hash implementation for string values
|
||||
@ -431,41 +448,62 @@ end;
|
||||
{============================== TX2UtHash
|
||||
Item Management
|
||||
========================================}
|
||||
(*
|
||||
constructor TX2UtHash.Create;
|
||||
begin
|
||||
inherited;
|
||||
|
||||
DataSize := SizeOf(Pointer);
|
||||
HashDataSize := SizeOf(Pointer);
|
||||
end;
|
||||
|
||||
function TX2UtHash.GetItem;
|
||||
var
|
||||
pNode: PX2UtBTreeNode;
|
||||
pItem: PX2UtHashItem;
|
||||
|
||||
begin
|
||||
pNode := LookupNode(Key);
|
||||
if Assigned(pNode) then
|
||||
Result := PPointer(GetNodeData(pNode))^;
|
||||
Assert(Length(Key) > 0, RSEmptyKey);
|
||||
pItem := LookupItem(Key, pNode);
|
||||
if Assigned(pItem) then
|
||||
Result := PPointer(GetItemData(pItem))^;
|
||||
end;
|
||||
|
||||
procedure TX2UtHash.SetItem;
|
||||
var
|
||||
pNode: PX2UtBTreeNode;
|
||||
pItem: PX2UtHashItem;
|
||||
|
||||
begin
|
||||
pNode := LookupNode(Key, True);
|
||||
if Assigned(pNode) then
|
||||
PPointer(GetNodeData(pNode))^ := Value;
|
||||
Assert(Length(Key) > 0, RSEmptyKey);
|
||||
pItem := LookupItem(Key, pNode, True);
|
||||
if Assigned(pItem) then
|
||||
PPointer(GetItemData(pItem))^ := Value;
|
||||
end;
|
||||
|
||||
function TX2UtHash.GetCurrentValue;
|
||||
begin
|
||||
Result := nil;
|
||||
if ValidCursor(True) then
|
||||
Result := PPointer(GetNodeData(Cursor))^;
|
||||
if ValidCursor() then
|
||||
Result := PPointer(GetItemData(HashCursor))^;
|
||||
end;
|
||||
|
||||
|
||||
{======================= TX2UtIntegerHash
|
||||
Item Management
|
||||
========================================}
|
||||
function TX2UtIntegerHash.GetItem;
|
||||
begin
|
||||
Result := Integer(inherited GetItem(Key));
|
||||
end;
|
||||
|
||||
procedure TX2UtIntegerHash.SetItem;
|
||||
begin
|
||||
inherited SetItem(Key, Pointer(Value));
|
||||
end;
|
||||
|
||||
function TX2UtIntegerHash.GetCurrentValue;
|
||||
begin
|
||||
Result := Integer(inherited GetCurrentValue());
|
||||
end;
|
||||
*)
|
||||
|
||||
|
||||
{======================== TX2UtStringHash
|
||||
@ -484,6 +522,7 @@ var
|
||||
pItem: PX2UtHashItem;
|
||||
|
||||
begin
|
||||
Assert(Length(Key) > 0, RSEmptyKey);
|
||||
pItem := LookupItem(Key, pNode);
|
||||
if Assigned(pItem) then
|
||||
Result := PString(GetItemData(pItem))^;
|
||||
@ -527,6 +566,7 @@ end;
|
||||
|
||||
function TX2UtStringHash.GetCurrentValue;
|
||||
begin
|
||||
Result := '';
|
||||
if ValidCursor() then
|
||||
Result := PString(GetItemData(HashCursor))^;
|
||||
end;
|
||||
|
Loading…
Reference in New Issue
Block a user