Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. # sparse-bitfield
  2. Bitfield implementation that allocates a series of 1kb buffers to support sparse bitfields
  3. without allocating a massive buffer. If you want to simple implementation of a flat bitfield
  4. see the [bitfield](https://github.com/fb55/bitfield) module.
  5. This module is mostly useful if you need a big bitfield where you won't nessecarily set every bit.
  6. ```
  7. npm install sparse-bitfield
  8. ```
  9. [![build status](http://img.shields.io/travis/mafintosh/sparse-bitfield.svg?style=flat)](http://travis-ci.org/mafintosh/sparse-bitfield)
  10. ## Usage
  11. ``` js
  12. var bitfield = require('sparse-bitfield')
  13. var bits = bitfield()
  14. bits.set(0, true) // set first bit
  15. bits.set(1, true) // set second bit
  16. bits.set(1000000000000, true) // set the 1.000.000.000.000th bit
  17. ```
  18. Running the above example will allocate two 1kb buffers internally.
  19. Each 1kb buffer can hold information about 8192 bits so the first one will be used to store information about the first two bits and the second will be used to store the 1.000.000.000.000th bit.
  20. ## API
  21. #### `var bits = bitfield([options])`
  22. Create a new bitfield. Options include
  23. ``` js
  24. {
  25. pageSize: 1024, // how big should the partial buffers be
  26. buffer: anExistingBitfield,
  27. trackUpdates: false // track when pages are being updated in the pager
  28. }
  29. ```
  30. #### `bits.set(index, value)`
  31. Set a bit to true or false.
  32. #### `bits.get(index)`
  33. Get the value of a bit.
  34. #### `bits.pages`
  35. A [memory-pager](https://github.com/mafintosh/memory-pager) instance that is managing the underlying memory.
  36. If you set `trackUpdates` to true in the constructor you can use `.lastUpdate()` on this instance to get the last updated memory page.
  37. #### `var buffer = bits.toBuffer()`
  38. Get a single buffer representing the entire bitfield.
  39. ## License
  40. MIT