queuePriority

Class: matlab.DiscreteEventSystem
Package: matlab

Define priority queue storage

Syntax

storage=queuePriority(entityType,capacity,key,order)

Description

storage=queuePriority(entityType,capacity,key,order) defines a priority queue that sorts entities by custom attribute. Use this function when implementing the getEntityStorageImpl method.

Input Arguments

expand all

Type of entities that the new storage element works with.

Maximum number of entities that the storage can contain, specified as a double.

Name of the attribute that is used as the key for sorting.

Direction of sorting. Specify 'ascending' if you want entities with smaller key values to appear in front of the queue. Specify 'descending' if you want entities with greater key values to appear in front of the queue.

Output Arguments

expand all

Queue storage element that contains entities and sorts them using a custom attribute.

Examples

expand all

Define storage element as a priority queue.

% Define a storage element as a priority queue        
% - Queue sorts entities using a specific attribute of the entities
% - Queue can store entities of type 'myEntity'
% - Queue can store no more than 25 entities
% - Queue uses the attribute 'age' to sort entities
% - Sorting direction is 'ascending', resulting entities with
%   smaller 'age' attribute values to appear in front of the queue
storage = obj.queuePriority('myEntity', 25, 'age', 'ascending'); 

Introduced in R2016a