Skip to content

MatrixAI/js-resource-counter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

js-resource-counter

Sequentially Allocatable and Deallocatable Resource Counter written in JavaScript. It is useful for tracking resource usage such as inodes and file descriptors. The resource counter is backed by a new lazy recursive perfectly balanced dynamically growing and shrinking bitmap tree data structure. This allows logarithmic allocation and deallocation performance. It's memory usage is better than the alternative deallocated stack + counter method.

Basic Usage

npm install --save 'resource-counter';
import Counter from 'resource-counter';
let c = new Counter;
let first = c.allocate();
let second = c.allocate();
let third = c.allocate();
let fourth = c.allocate();
c.deallocate(second);
c.deallocate(third);
console.log(c.allocate() === second);
console.log(c.allocate() === third);
console.log(c.allocate() === (fourth + 1));

Documentation

Documentation is located in the doc folder. You can also view the rendered HTML.

Development

To build this package for release:

npm run build

It will run tests, generate documentation and output multiple targets. One for browsers and one for nodejs. See rollup.config.js to see the target specification.

If your bundler is aware of the module field in package.json, you'll get the ES6 module directly.

Once you've updated the package run this:

npm version <update_type>
npm publish

About

Sequentially Allocatable and Deallocatable Resource Counter written in JavaScript

Resources

License

Stars

Watchers

Forks

Packages

No packages published