Class TTreeMapContainer

Unit

Declaration

type TTreeMapContainer = class(TObject)

Description

An owning, size-sorted list of TTreeMapItem instances.

TTreeMapContainer.Add, TTreeMapContainer.Remove, TTreeMapContainer.RemoveAt and TTreeMapContainer.Clear keep the list sorted by TTreeMapItem.Size in descending order and keep TTreeMapContainer.TotalSize up to date on every mutation. The container owns its items: an item is freed as soon as it is removed, and when the container is cleared or destroyed.

For bulk population use TTreeMapContainer.FastAdd – which skips the duplicate check and does not preserve order – followed by a single TTreeMapContainer.Sort.

Hierarchy

Overview

Methods

Public constructor Create;
Public destructor Destroy; override;
Public function Add(aitem: TTreeMapItem): integer;
Public function Remove(aitem: TTreeMapItem): boolean;
Public function RemoveAt(index: integer): boolean;
Public function IndexOf(aitem: TTreeMapItem): integer;
Public function IndexOfData(adata: pointer): integer;
Public function UpdateSizeAt(index: integer; newsize: int64): boolean;
Public function UpdateSize(aitem: TTreeMapItem; newsize: int64): boolean;
Public procedure Clear;
Public procedure Sort;
Public procedure FastAdd(aitem: TTreeMapItem);

Properties

Public property Count: integer read GetCount;
Public property Items[index: integer]: TTreeMapItem read GetItem; default;
Public property TotalSize: int64 read fTotalSize;

Description

Methods

Public constructor Create;

Creates an empty container.

Public destructor Destroy; override;

Clears and frees all contained items, then destroys the container.

Public function Add(aitem: TTreeMapItem): integer;

Adds a single item, preserving descending size order, and updates TTreeMapContainer.TotalSize.

Parameters
aitem
The item to add; the container takes ownership of it.
Returns

The index at which the item was inserted. If the item is already present, its existing index is returned; returns -1 when aitem is Nil.

Public function Remove(aitem: TTreeMapItem): boolean;

Removes and frees an item, located by reference, and updates TTreeMapContainer.TotalSize.

Parameters
aitem
The item to remove.
Returns

True if the item was found and removed, False otherwise.

Public function RemoveAt(index: integer): boolean;

Removes and frees the item at the given index and updates TTreeMapContainer.TotalSize.

Parameters
index
Zero-based index of the item to remove.
Returns

True if removed, False if index was out of range.

Public function IndexOf(aitem: TTreeMapItem): integer;

Returns the index of an item, located by reference.

Parameters
aitem
The item to look up.
Returns

The zero-based index, or -1 if not present.

Public function IndexOfData(adata: pointer): integer;

Returns the index of the first item whose TTreeMapItem.Data pointer equals adata.

Parameters
adata
The data pointer to match.
Returns

The zero-based index, or -1 if no item matches.

Public function UpdateSizeAt(index: integer; newsize: int64): boolean;

Changes the size of the item at index, moving it to its new sorted position and updating TTreeMapContainer.TotalSize.

This is the only supported way to change an item's size, so that the list can stay sorted without a full re-sort.

Parameters
index
Zero-based index of the item to update.
newsize
The new size value.
Returns

True on success, False if index was out of range.

Public function UpdateSize(aitem: TTreeMapItem; newsize: int64): boolean;

Convenience wrapper around TTreeMapContainer.UpdateSizeAt that first looks the item up by reference.

Parameters
aitem
The item whose size to change.
newsize
The new size value.
Returns

True on success, False if the item was not found.

Public procedure Clear;

Removes and frees all items and resets TTreeMapContainer.TotalSize to zero.

Public procedure Sort;

Sorts the list by TTreeMapItem.Size in descending order. Use together with TTreeMapContainer.FastAdd.

Public procedure FastAdd(aitem: TTreeMapItem);

Appends an item without checking for duplicates and without preserving sort order, updating TTreeMapContainer.TotalSize. Intended for bulk population; call TTreeMapContainer.Sort once all items have been added.

Parameters
aitem
The item to append; the container takes ownership of it.

Properties

Public property Count: integer read GetCount;

The number of items currently in the container.

Public property Items[index: integer]: TTreeMapItem read GetItem; default;

Indexed, read-only access to the contained items. This is the default property, so container[i] is equivalent to container.Items[i].

Public property TotalSize: int64 read fTotalSize;

The sum of the TTreeMapItem.Size values of all contained items.


Generated by PasDoc 1.0.4.