Cache.replaceRemovedItem

Called when a cache element is removed, replaces the cache items at index "replaced" with the one at index "replace" by swapping the items.

Unlike all other situations where indices and are used, "replaced" and "replace" must be always valid, i.e. less than length.

Note: A subclass may erase removed elements by overriding this method as follows:

protected override hash_t replaceRemovedItem ( size_t replaced,
                                               size_t replace )
{
    scope (success) this.items[replace] = this.items[replace].init;

    return (this.items[replaced] = this.items[replace]).key;
}
class Cache(size_t ValueSize = 0, bool TrackCreateTimes = false)
protected override
hash_t
replaceRemovedItem
(
size_t replaced
,
size_t replace
)
out (key) { assert (key == this.items[replaced].key); }

Parameters

replaced size_t

index of the cache item that is to be replaced

replace size_t

index of the cache item that will replace the replaced item

Return Value

Type: hash_t

the key of the cache item that was at index "replace" before and is at index "replaced" now.

In: "replaced" and "replace" must be different and be valid cache item indices, i.e. less than this.length.

Out: The returned key must be the key of this.itemsreplaced.

Meta