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\dclite60.bpl=Borland Integrated Translation Environment
|
||||||
c:\program files\borland\delphi6\Bin\dcldbx60.bpl=Borland dbExpress Components
|
c:\program files\borland\delphi6\Bin\dcldbx60.bpl=Borland dbExpress Components
|
||||||
c:\program files\borland\delphi6\Bin\dcldbxcds60.bpl=Borland Local DBX ClientDataset 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.
|
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};
|
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
|
var
|
||||||
shData: TX2UtStringHash;
|
shData: TX2UtStringHash;
|
||||||
btTest: TX2UtStringBTree;
|
btTest: TX2UtStringBTree;
|
||||||
@ -44,22 +26,8 @@ begin
|
|||||||
for iItem := 0 to 61 do
|
for iItem := 0 to 61 do
|
||||||
btTest[Random(500)] := 'bla';
|
btTest[Random(500)] := 'bla';
|
||||||
|
|
||||||
<<<<<<< .working
|
|
||||||
btTest[300] := 'bla';
|
|
||||||
btTest.Delete(300);
|
|
||||||
=======
|
|
||||||
TfrmBTree.Execute(btTest);
|
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;
|
WriteLn;
|
||||||
btTest.Reset();
|
btTest.Reset();
|
||||||
while btTest.Next() do
|
while btTest.Next() do
|
||||||
|
@ -200,6 +200,7 @@ type
|
|||||||
protected
|
protected
|
||||||
function GetItem(Index: Cardinal): Integer;
|
function GetItem(Index: Cardinal): Integer;
|
||||||
procedure SetItem(Index: Cardinal; const Value: Integer);
|
procedure SetItem(Index: Cardinal; const Value: Integer);
|
||||||
|
|
||||||
function GetCurrentValue(): Integer;
|
function GetCurrentValue(): Integer;
|
||||||
public
|
public
|
||||||
//:$ Gets or sets an item.
|
//:$ Gets or sets an item.
|
||||||
@ -571,6 +572,8 @@ end;
|
|||||||
|
|
||||||
function TX2UtCustomBTree.DeleteLeftShrunk;
|
function TX2UtCustomBTree.DeleteLeftShrunk;
|
||||||
begin
|
begin
|
||||||
|
Result := CError;
|
||||||
|
|
||||||
case ANode^.Balance of
|
case ANode^.Balance of
|
||||||
-1:
|
-1:
|
||||||
begin
|
begin
|
||||||
@ -634,6 +637,8 @@ end;
|
|||||||
|
|
||||||
function TX2UtCustomBTree.DeleteRightShrunk;
|
function TX2UtCustomBTree.DeleteRightShrunk;
|
||||||
begin
|
begin
|
||||||
|
Result := CError;
|
||||||
|
|
||||||
case ANode^.Balance of
|
case ANode^.Balance of
|
||||||
1:
|
1:
|
||||||
begin
|
begin
|
||||||
|
@ -25,7 +25,7 @@ type
|
|||||||
Prev: PX2UtHashItem;
|
Prev: PX2UtHashItem;
|
||||||
Next: PX2UtHashItem;
|
Next: PX2UtHashItem;
|
||||||
Key: String;
|
Key: String;
|
||||||
Value: record end;
|
Data: record end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -91,7 +91,6 @@ type
|
|||||||
{
|
{
|
||||||
:$ Hash implementation for pointer values
|
:$ Hash implementation for pointer values
|
||||||
}
|
}
|
||||||
(*
|
|
||||||
TX2UtHash = class(TX2UtCustomHash)
|
TX2UtHash = class(TX2UtCustomHash)
|
||||||
private
|
private
|
||||||
function GetItem(Key: String): Pointer;
|
function GetItem(Key: String): Pointer;
|
||||||
@ -109,7 +108,25 @@ type
|
|||||||
//:$ Returns the value at the current cursor location.
|
//:$ Returns the value at the current cursor location.
|
||||||
property CurrentValue: Pointer read GetCurrentValue;
|
property CurrentValue: Pointer read GetCurrentValue;
|
||||||
end;
|
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
|
:$ Hash implementation for string values
|
||||||
@ -431,41 +448,62 @@ end;
|
|||||||
{============================== TX2UtHash
|
{============================== TX2UtHash
|
||||||
Item Management
|
Item Management
|
||||||
========================================}
|
========================================}
|
||||||
(*
|
|
||||||
constructor TX2UtHash.Create;
|
constructor TX2UtHash.Create;
|
||||||
begin
|
begin
|
||||||
inherited;
|
inherited;
|
||||||
|
|
||||||
DataSize := SizeOf(Pointer);
|
HashDataSize := SizeOf(Pointer);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TX2UtHash.GetItem;
|
function TX2UtHash.GetItem;
|
||||||
var
|
var
|
||||||
pNode: PX2UtBTreeNode;
|
pNode: PX2UtBTreeNode;
|
||||||
|
pItem: PX2UtHashItem;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
pNode := LookupNode(Key);
|
Assert(Length(Key) > 0, RSEmptyKey);
|
||||||
if Assigned(pNode) then
|
pItem := LookupItem(Key, pNode);
|
||||||
Result := PPointer(GetNodeData(pNode))^;
|
if Assigned(pItem) then
|
||||||
|
Result := PPointer(GetItemData(pItem))^;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TX2UtHash.SetItem;
|
procedure TX2UtHash.SetItem;
|
||||||
var
|
var
|
||||||
pNode: PX2UtBTreeNode;
|
pNode: PX2UtBTreeNode;
|
||||||
|
pItem: PX2UtHashItem;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
pNode := LookupNode(Key, True);
|
Assert(Length(Key) > 0, RSEmptyKey);
|
||||||
if Assigned(pNode) then
|
pItem := LookupItem(Key, pNode, True);
|
||||||
PPointer(GetNodeData(pNode))^ := Value;
|
if Assigned(pItem) then
|
||||||
|
PPointer(GetItemData(pItem))^ := Value;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TX2UtHash.GetCurrentValue;
|
function TX2UtHash.GetCurrentValue;
|
||||||
begin
|
begin
|
||||||
Result := nil;
|
Result := nil;
|
||||||
if ValidCursor(True) then
|
if ValidCursor() then
|
||||||
Result := PPointer(GetNodeData(Cursor))^;
|
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;
|
end;
|
||||||
*)
|
|
||||||
|
|
||||||
|
|
||||||
{======================== TX2UtStringHash
|
{======================== TX2UtStringHash
|
||||||
@ -484,6 +522,7 @@ var
|
|||||||
pItem: PX2UtHashItem;
|
pItem: PX2UtHashItem;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
Assert(Length(Key) > 0, RSEmptyKey);
|
||||||
pItem := LookupItem(Key, pNode);
|
pItem := LookupItem(Key, pNode);
|
||||||
if Assigned(pItem) then
|
if Assigned(pItem) then
|
||||||
Result := PString(GetItemData(pItem))^;
|
Result := PString(GetItemData(pItem))^;
|
||||||
@ -527,6 +566,7 @@ end;
|
|||||||
|
|
||||||
function TX2UtStringHash.GetCurrentValue;
|
function TX2UtStringHash.GetCurrentValue;
|
||||||
begin
|
begin
|
||||||
|
Result := '';
|
||||||
if ValidCursor() then
|
if ValidCursor() then
|
||||||
Result := PString(GetItemData(HashCursor))^;
|
Result := PString(GetItemData(HashCursor))^;
|
||||||
end;
|
end;
|
||||||
|
Loading…
Reference in New Issue
Block a user