加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

在Delphi中有HashSet吗?

发布时间:2020-12-15 04:27:42 所属栏目:大数据 来源:网络整理
导读:在Delphi中有HashSet吗? 我知道使用set最多可以保存255项.在最新的Delphi编译器中有HashSet吗? XE8,西雅图 解决方法 标准集合不提供通用的集合类. Spring4D等第三方集合库. 您可以很容易地在TDictionary K,V之上构建一个泛型集类.裸骨版本可能如下所示: t
在Delphi中有HashSet吗?

我知道使用set最多可以保存255项.在最新的Delphi编译器中有HashSet吗? XE8,西雅图

解决方法

标准集合不提供通用的集合类. Spring4D等第三方集合库.

您可以很容易地在TDictionary< K,V>之上构建一个泛型集类.裸骨版本可能如下所示:

type
  TSet<T> = class
  private
    FDict: TDictionary<T,Integer>;
  public
    constructor Create;
    destructor Destroy; override;
    function Contains(const Value: T): Boolean;
    procedure Include(const Value: T);
    procedure Exclude(const Value: T);
  end;

....

constructor TSet<T>.Create;
begin
  inherited;
  FDict := TDictionary<T,Integer>.Create;
end;

destructor TSet<T>.Destroy;
begin
  FDict.Free;
  inherited;
end;

function TSet<T>.Contains(const Value: T): Boolean;
begin
  Result := FDict.ContainsKey(Value);
end;

procedure TSet<T>.Include(const Value: T);
begin
  FDict.AddOrSetValue(Value,0);
end;

procedure TSet<T>.Exclude(const Value: T);
begin
  FDict.Remove(Value);
end;

我没有编译这段代码,所以你可能需要修正我所犯的错误.你可能希望扩展它更有能力.但希望这可以告诉你如何开始.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读