All files / Sources/Common/Core/PriorityQueue index.js

94.73% Statements 18/19
33.33% Branches 1/3
100% Functions 8/8
93.75% Lines 15/16

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58                16x   16x   21516x   1584x     16x 528x 528x           16x 64608x     1056x             1x             16x     16x 16x         1x          
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 };