# tinyqueue **Repository Path**: ArkTSCentralRepository/tinyqueue ## Basic Information - **Project Name**: tinyqueue - **Description**: tinyqueue 是一个简单且轻量的二叉堆优先队列库,支持基本的队列操作如添加、移除和查看队列中的元素,适用于数值和自定义对象排序。 - **Primary Language**: Unknown - **License**: ISC - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-11-21 - **Last Updated**: 2024-11-24 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # tinyqueue 基于[tinyqueue](https://www.npmjs.com/package/tinyqueue)原库3.0.0版本进行适配, 所有功能代码已经转换为`ArkTS`文件 ## Install ```sh ohpm install tinyqueue ``` ## Description The smallest and simplest binary heap priority queue in JavaScript. ```typescript import TinyQueue from 'tinyqueue'; // create an empty priority queue const queue = new TinyQueue(); // add some items queue.push(7); queue.push(5); queue.push(10); // remove the top item let top = queue.pop(); // returns 5 // return the top item (without removal) top = queue.peek(); // returns 7 // get queue length queue.length; // returns 2 // create a priority queue from an existing array (modifies the array) queue = new TinyQueue([7, 5, 10]); // pass a custom item comparator as a second argument queue = new TinyQueue([{value: 5}, {value: 7}], function (a, b) { return a.value - b.value; }); // turn a queue into a sorted array const array: number[] = []; while (queue.length) array.push(queue.pop()); ``` For a faster number-based queue, see [flatqueue](https://github.com/mourner/flatqueue). ### Thanks Inspired by [js-priority-queue](https://github.com/adamhooper/js-priority-queue) by [Adam Hooper](https://github.com/adamhooper).