buddy-tree
TypeScript icon, indicating that this package has built-in type declarations

2.4.1 • Public • Published

buddy-tree

Immutable buddy memory allocation

Installation

npm install --save buddy-tree

Usage

import * as buddyTree from 'buddy-tree'
 
let tree = buddyTree.createTree(16);
[tree, address1] = buddyTree.allocate(tree, 1);
[tree, address2] = buddyTree.allocate(tree, 1);
[tree, address3] = buddyTree.allocate(tree, 4);
tree = buddyTree.deallocate(tree, address2);

Methods

buddyTree.allocate(tree, size=1)

Find a contiguous free span of memory of size and consumes it. Returns the modified tree and the address of the memory.

Consumes 2ⁿ >= size of the memory. This means in the worst case half the memory is wasted.

const tree = buddyTree.createTree(16);
const [result, address] = buddyTree.allocate(tree, 7);

buddyTree.deallocate(tree, address)

Frees all the memory consumed at the address. Returns the modified tree.

Dependencies (0)

    Dev Dependencies (12)

    Package Sidebar

    Install

    npm i buddy-tree

    Weekly Downloads

    1

    Version

    2.4.1

    License

    MIT

    Unpacked Size

    47.5 kB

    Total Files

    51

    Last publish

    Collaborators

    • mariusgundersen