lazutils: fixed TAVLTree using fnodemgr

git-svn-id: trunk@54538 -
This commit is contained in:
mattias 2017-04-06 10:08:39 +00:00
parent 7fa04aed29
commit 9424db5d62
2 changed files with 11 additions and 7 deletions

View File

@ -38,6 +38,7 @@ type
procedure FreeAndDelete(ANode: TAVLTreeNode); override; procedure FreeAndDelete(ANode: TAVLTreeNode); override;
property OwnsObjects: boolean read FOwnsObjects write FOwnsObjects; property OwnsObjects: boolean read FOwnsObjects write FOwnsObjects;
end; end;
TAvgLvlTreeClass = class of TAvgLvlTree;
{ TIndexedAVLTreeNode } { TIndexedAVLTreeNode }
@ -48,7 +49,7 @@ type
{ TIndexedAVLTree } { TIndexedAVLTree }
TIndexedAVLTree = class(TAvlTree) TIndexedAVLTree = class(TAvgLvlTree)
private private
function GetItems(Index: SizeInt): Pointer; inline; function GetItems(Index: SizeInt): Pointer; inline;
protected protected

View File

@ -244,7 +244,7 @@ end;
function TAVLTree.Add(Data: Pointer): TAVLTreeNode; function TAVLTree.Add(Data: Pointer): TAVLTreeNode;
begin begin
Result:=fNodeMgr.NewNode; Result:=NewNode;
Result.Data:=Data; Result.Data:=Data;
Add(Result); Add(Result);
end; end;
@ -292,16 +292,16 @@ end;
function TAVLTree.NewNode: TAVLTreeNode; function TAVLTree.NewNode: TAVLTreeNode;
begin begin
if LazNodeMemManager<>nil then if fNodeMgr<>nil then
Result:=LazNodeMemManager.NewNode Result:=fNodeMgr.NewNode
else else
Result:=NodeClass.Create; Result:=NodeClass.Create;
end; end;
procedure TAVLTree.DisposeNode(ANode: TAVLTreeNode); procedure TAVLTree.DisposeNode(ANode: TAVLTreeNode);
begin begin
if LazNodeMemManager<>nil then if fNodeMgr<>nil then
LazNodeMemManager.DisposeNode(ANode) fNodeMgr.DisposeNode(ANode)
else else
ANode.Free; ANode.Free;
end; end;
@ -628,7 +628,7 @@ procedure TAVLTree.Clear;
if ANode.Left<>nil then DeleteNode(ANode.Left); if ANode.Left<>nil then DeleteNode(ANode.Left);
if ANode.Right<>nil then DeleteNode(ANode.Right); if ANode.Right<>nil then DeleteNode(ANode.Right);
end; end;
fNodeMgr.DisposeNode(ANode); DisposeNode(ANode);
end; end;
// Clear // Clear
@ -1326,6 +1326,9 @@ procedure TAVLTree.SetNodeManager(NewMgr: TBaseAVLTreeNodeManager;
AutoFree: boolean); AutoFree: boolean);
// only allowed just after create. // only allowed just after create.
begin begin
if fNodeMgr=NewMgr then exit;
if Count>0 then
raise Exception.Create('TAVLTree.SetNodeManager');
if fNodeMgrAutoFree then if fNodeMgrAutoFree then
FreeAndNil(fNodeMgr); FreeAndNil(fNodeMgr);
fNodeMgr:=NewMgr; fNodeMgr:=NewMgr;