PriorityQueue

Introduction

vtkPriorityQueue is a general object for creating and manipulating lists of
object ids (e.g., point or cell ids). Object ids are sorted according to a
user-specified priority, where entries at the top of the queue have the
smallest values.

Methods

deleteById

Delete an element from the queue by its ID.

Argument Type Required Description
id Number Yes The id of the element.

extend

Method used to decorate a given object (publicAPI+model) with vtkPriorityQueue characteristics.

Argument Type Required Description
publicAPI Yes object on which methods will be bounds (public)
model Yes object on which data structure will be bounds (protected)
initialValues IPriorityQueueInitialValues No (default: {})

length

Get the length of the queue.

newInstance

Method used to create a new instance of vtkPriorityQueue

Argument Type Required Description
initialValues IPriorityQueueInitialValues No for pre-setting some of its content

pop

push

Push an element to the queue while defining a priority.

Argument Type Required Description
priority Number Yes The priority of the element.
element Yes

Source

index.d.ts
import { vtkObject } from "../../../interfaces" ;

/**
*
*/
export interface IPriorityQueueInitialValues {
elements?: Array<any>;
}

export interface vtkPriorityQueue extends vtkObject {

/**
* Push an element to the queue while defining a priority.
* @param {Number} priority The priority of the element.
* @param element
*/
push(priority: number, element: any): void;

/**
*
*/
pop(): any | null;

/**
* Delete an element from the queue by its ID.
* @param {Number} id The id of the element.
*/
deleteById(id: number): void;

/**
* Get the length of the queue.
*/
length(): number;
}

/**
* Method used to decorate a given object (publicAPI+model) with vtkPriorityQueue characteristics.
*
* @param publicAPI object on which methods will be bounds (public)
* @param model object on which data structure will be bounds (protected)
* @param {IPriorityQueueInitialValues} [initialValues] (default: {})
*/
export function extend(publicAPI: object, model: object, initialValues?: IPriorityQueueInitialValues): void;

/**
* Method used to create a new instance of vtkPriorityQueue
* @param {IPriorityQueueInitialValues} [initialValues] for pre-setting some of its content
*/
export function newInstance(initialValues?: IPriorityQueueInitialValues): vtkPriorityQueue;


/**
* vtkPriorityQueue is a general object for creating and manipulating lists of
* object ids (e.g., point or cell ids). Object ids are sorted according to a
* user-specified priority, where entries at the top of the queue have the
* smallest values.
*/
export declare const vtkPriorityQueue: {
newInstance: typeof newInstance;
extend: typeof extend;
}
export default vtkPriorityQueue;
index.js
import macro from 'vtk.js/Sources/macros';

// ----------------------------------------------------------------------------
// vtkPriorityQueue methods
// ----------------------------------------------------------------------------

function vtkPriorityQueue(publicAPI, model) {
// Set our classname
model.classHierarchy.push('vtkPriorityQueue');

publicAPI.push = (priority, element) => {
// naive algo
const i = model.elements.findIndex((e) => e.priority > priority);

model.elements.splice(i, 0, { priority, element });
};

publicAPI.pop = () => {
if (model.elements.length > 0) {
return model.elements.shift().element;
}

return null;
};

publicAPI.deleteById = (id) => {
model.elements = model.elements.filter(({ element }) => element.id !== id);
};

publicAPI.length = () => model.elements.length;
}

// ----------------------------------------------------------------------------
// Object factory
// ----------------------------------------------------------------------------

const DEFAULT_VALUES = {
elements: [],
};

// ----------------------------------------------------------------------------

export function extend(publicAPI, model, initialValues = {}) {
Object.assign(model, DEFAULT_VALUES, initialValues);

// Build VTK API
macro.obj(publicAPI, model);
vtkPriorityQueue(publicAPI, model);
}

// ----------------------------------------------------------------------------

export const newInstance = macro.newInstance(extend, 'vtkPriorityQueue');

// ----------------------------------------------------------------------------

export default { newInstance, extend };