Giter Site home page Giter Site logo

bitmap-tree's Introduction

bitmap-tree

This is an efficient data structure that can be used to manage index slots for bindless GPU resources. It can also be used for any other purpose which requires tracking resources.

Introduction

It works similarily to an ordinary bitmap with the difference that finding the first available slot is very fast. The tree can be sparse so very big indices are possible (if indices need to be assigned manually).

Internally it's implemented as an 32/64-ary tree of 32/64 bit integers storing the bits. Leaf nodes are flattened to contain 4096 available bit positions.

For managing 16 777 216 resources the tree has only 3 levels and requires calculating 3 ctz/BitScanForward intrinsics.

Building

Simply include bitmap_tree.hpp and that's it!

Usage

// Create new tree. It can dynamically expand as necessary
bmt::tree_t<uint64_t> tree;

// This will reserve the first available index
auto idx = tree.allocate();

// We can test if the index is reserved
assert(tree.is_allocated(idx));

// We can deallocate
tree.deallocate(idx);

// We can allocate a specific index. Since the tree is sparse
// this won't be too problematic memory wise like normal bitmap
// even if the index is very big. However the level of the tree
// might increase.
tree.allocate_at(10000000000ull);

// We can get the total slots allocated
assert(tree.allocated_slots() == 1);

// The current maximum capacity can be aquired with this.
// The tree will automatically expand when the total
// allocated slots reach the capacity
assert(tree.current_capacity() == 4096);

bitmap-tree's People

Contributors

theoreticalphysicsftw avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.