Class TMutableSet

Unit

Declaration

type generic TMutableSet<TItem,TInfo> = class(specialize TReadOnlySet<TItem,TInfo>)

Description

Generic mutable set

Data in this set can be read (see ancestor TReadOnlySet) and modified.

Example:

type TMutableSetString = specialize TMutableSet<string, THAMTTypeInfo>;
var stringSet: TMutableSetString;
    p: TMutableSetString.PItem;
begin
  stringSet := TMutableSetString.create;
  stringSet.Insert('hello');
  stringSet.insert('foo');

  writeln(stringSet['hello']); // true
  writeln(stringSet.contains('foo')); // true
  writeln(stringSet.contains('abc')); // false

  //enumerate all
  for p in stringSet do
    writeln(pˆ);

  stringSet.free;
end.

Hierarchy

Overview

Methods

Public constructor Create;
Public constructor Create(other: specialize TReadOnlyCustomSet<TItem, TInfo>);
Public function include(const item: TItem; allowOverride: boolean = true): boolean; inline;
Public function exclude(const item: TItem): boolean; inline;
Public procedure insert(const item: TItem); inline;
Public procedure remove(const item: TItem); inline;
Public procedure clear;
Public function clone: TMutableSet;

Properties

Public property items[item: TItem]: Boolean read contains write toggleItem;

Description

Methods

Public constructor Create;

Creates an empty set

Public constructor Create(other: specialize TReadOnlyCustomSet<TItem, TInfo>);

Creates a set equal to other. No data is copied, till either set is modified (copy-on-write).

Public function include(const item: TItem; allowOverride: boolean = true): boolean; inline;

Inserts an item, if the set does not contain the item or allowOverride is true.

Returns

If the set did not contain item.

Public function exclude(const item: TItem): boolean; inline;

Removes an item,

Returns

If the set did contain item.

Public procedure insert(const item: TItem); inline;

Inserts an item, or raises an exception if the set already contains the item

Public procedure remove(const item: TItem); inline;

Removes an item, or raises an exception if the set did not contain the item

Public procedure clear;

Removes everything from the set;

Public function clone: TMutableSet;

Creates a new set equal to self. No data is copied, till either set is modified (copy-on-write).

Properties

Public property items[item: TItem]: Boolean read contains write toggleItem;

Default parameter, so you can test and update the set with set[key]


Generated by PasDoc 0.16.0.