代码拉取完成,页面将自动刷新
(*
* DGL(The Delphi Generic Library)
*
* Copyright (c) 2004
* HouSisong@gmail.com
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*)
//------------------------------------------------------------------------------
// _TSetIterator\_TSet\_TMultiSetʵ
// Create by HouSisong, 2006.10.20
//------------------------------------------------------------------------------
//Set.inc_Pas ; Set.inc_h
{$ifndef __Set_inc_pas_}
{$define __Set_inc_pas_}
{$I DGLIntf.inc_pas}
{$I _RB_Tree.inc_pas}
{_TSet_Base}
function _TSet_Base.GetSelfObj():TObject;
begin
result:=self;
end;
function _TSet_Base.IsEmpty(): Boolean;
begin
result:=FRB_TRee.Size()=0;
end;
constructor _TSet_Base.Create;
begin
inherited Create();
self.FRB_TRee:=_TRB_Tree.Create(true);
end;
procedure _TSet_Base.Clear;
begin
self.FRB_TRee.Clear();
end;
function _TSet_Base.Count(const Value: _ValueType): _TNativeInt;
begin
result:=self.FRB_TRee.Count(Value);
end;
destructor _TSet_Base.Destroy;
begin
self.FRB_TRee.Free();
inherited;
end;
procedure _TSet_Base.EqualRange(const Value: _ValueType; out ItBegin,
ItEnd: _IIterator);
var
ItBeginNode,ItEndNode :_TRB_TreeIterator;
begin
self.FRB_Tree.EqualRange(Value,ItBeginNode,ItEndNode);
_TSetIterator.ItCreate(_IIterator(ItBegin),ItBeginNode);
_TSetIterator.ItCreate(_IIterator(ItEnd),ItEndNode);
end;
procedure _TSet_Base.Erase(const ItPos: _IIterator);
begin
self.FRB_TRee.Erase(_TRB_TreeIterator(ItPos._Data0));
end;
function _TSet_Base.EraseValue(const Value: _ValueType): _TNativeInt;
begin
result:=self.FRB_TRee.EraseKey(Value);
end;
procedure _TSet_Base.Erase(const ItBegin, ItEnd: _IIterator);
begin
self.FRB_TRee.Erase(_TRB_TreeIterator(ItBegin._Data0), _TRB_TreeIterator(ItEnd._Data0));
end;
function _TSet_Base.Find(const Value: _ValueType): _IIterator;
begin
_TSetIterator.ItCreate(result,self.FRB_TRee.FindKey(Value));
end;
function _TSet_Base.ItBegin: _IIterator;
begin
_TSetIterator.ItCreate(result,self.FRB_TRee.ItBegin);
end;
function _TSet_Base.ItEnd: _IIterator;
begin
_TSetIterator.ItCreate(result,self.FRB_TRee.ItEnd);
end;
function _TSet_Base.LowerBound(const Value: _ValueType): _IIterator;
begin
_TSetIterator.ItCreate(result,self.FRB_TRee.LowerBound(Value));
end;
function _TSet_Base.Size: _TNativeInt;
begin
result:=self.FRB_TRee.Size();
end;
function _TSet_Base.UpperBound(const Value: _ValueType): _IIterator;
begin
_TSetIterator.ItCreate(result,self.FRB_TRee.UpperBound(Value));
end;
///////////////////////////
{ _TSet }
constructor _TSet.Create;
begin
inherited Create();
end;
constructor _TSet.Create(const ItBegin,ItEnd: _IIterator);
begin
inherited Create();
self.Insert(self.ItBegin,ItBegin,ItEnd);
end;
procedure _TSet.Assign(const num: _TNativeInt; const Value: _ValueType);
begin
self.FRB_TRee.Clear();
if num>0 then
self.FRB_TRee.UniqueInsert(Value);
end;
procedure _TSet.Assign(const ItBegin, ItEnd: _IIterator);
begin
self.FRB_TRee.Clear();
self.Insert(self.ItBegin,ItBegin, ItEnd);
end;
function _TSet.Clone: _IContainer;
begin
result:=_ISet(_TSet.Create(self));
end;
procedure _TSet.CloneToInterface(out NewContainer);
begin
_ISet(NewContainer):=_TSet.Create(self);
end;
constructor _TSet.Create(const ASet: _TSet);
begin
inherited Create();
self.Insert(self.ItBegin,ASet.ItBegin, ASet.ItEnd);
end;
procedure _TSet.Insert(const ItPos: _IIterator;
const Value: _ValueType);
begin
self.FRB_TRee.UniqueInsert(Value);
end;
procedure _TSet.Insert(const Value: _ValueType);
begin
self.FRB_TRee.UniqueInsert(Value);
end;
procedure _TSet.Insert(const ItPos, ItBegin, ItEnd: _IIterator);
var
It :_IIterator;
begin
It:=ItBegin.Clone();
while (not It.IsEqual(ItEnd)) do
begin
self.FRB_TRee.UniqueInsert(It.Value);
It.Next();
end;
end;
procedure _TSet.Insert(const ItPos: _IIterator; const num: _TNativeInt;
const Value: _ValueType);
begin
if num>0 then
self.FRB_TRee.UniqueInsert(Value);
end;
{ _TMultiSet }
procedure _TMultiSet.Assign(const num: _TNativeInt; const Value: _ValueType);
var
i : _TNativeInt;
begin
self.FRB_Tree.Clear();
for i:=0 to num-1 do
self.FRB_TRee.MultiInsert(Value);
end;
procedure _TMultiSet.Assign(const ItBegin,ItEnd:_IIterator);
begin
self.FRB_TRee.Clear();
Insert(self.ItBegin(),ItBegin,ItEnd);
end;
function _TMultiSet.Clone: _IContainer;
begin
result:=_IMultiSet(_TMultiSet.Create(self));
end;
procedure _TMultiSet.CloneToInterface(out NewContainer);
begin
_IMultiSet(NewContainer):=_TMultiSet.Create(self);
end;
procedure _TMultiSet.Insert(const Value: _ValueType);
begin
self.FRB_TRee.MultiInsert(Value);
end;
procedure _TMultiSet.Insert(const ItPos, ItBegin, ItEnd: _IIterator);
var
It :_IIterator;
begin
It:=ItBegin.Clone();
while (not It.IsEqual(ItEnd)) do
begin
self.FRB_TRee.MultiInsert(It.Value);
It.Next();
end;
end;
procedure _TMultiSet.Insert(const ItPos: _IIterator; const num: _TNativeInt;
const Value: _ValueType);
var
i : _TNativeInt;
begin
for i:=0 to num-1 do
self.FRB_TRee.MultiInsert(Value);
end;
procedure _TMultiSet.Insert(const ItPos: _IIterator;const Value: _ValueType);
begin
self.FRB_TRee.MultiInsert(Value);
end;
constructor _TMultiSet.Create(const num: _TNativeInt;
const Value: _ValueType);
begin
inherited Create();
self.Insert(self.ItBegin,num,Value);
end;
constructor _TMultiSet.Create;
begin
inherited Create();
end;
constructor _TMultiSet.Create(const ItBegin, ItEnd: _IIterator);
begin
inherited Create();
self.Insert(self.ItBegin,ItBegin,ItEnd);
end;
constructor _TMultiSet.Create(const ASet: _TMultiSet);
begin
inherited Create();
self.Insert(self.ItBegin,Aset.ItBegin,ASet.ItEnd);
end;
{ _TSetIterator }
class procedure _TSetIterator.ItCreate(var SelfItData:_IIterator;const NodeIt:_TRB_TreeIterator);
begin
SelfItData._ObjIteratorClass:=_TSetIterator;
_TRB_TreeIterator(SelfItData._Data0):=NodeIt;
end;
class function _TSetIterator.Clone(const SelfItData:_IIterator): _IIterator;
begin
result:=SelfItData;
end;
class procedure _TSetIterator.Assign(var SelfItData:_IIterator;const Iterator: _IIterator);
begin
SelfItData:=Iterator;
end;
class function _TSetIterator.GetValue(const SelfItData:_IIterator): _ValueType;
begin
result:=inherited Map_GetKey(SelfItData);
end;
class procedure _TSetIterator.SetValue(const SelfItData:_IIterator;const Value: _ValueType);
begin
Assert(false); //key
end;
{$endif } // __Set_inc_pas_
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。