How to use bitfield - 5 common examples

To help you get started, we’ve selected a few bitfield examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github js-js / ssa.js / lib / ssa.js View on Github external
function SSA(pipeline) {
  this.pipeline = pipeline;

  this.visited = new BitField(this.pipeline.blocks.length);

  // List of phis for each block
  this.phi = new Array(this.pipeline.blocks.length);
  for (var i = 0; i < this.phi.length; i++)
    this.phi[i] = [];

  this.maxStore = 0;

  this.env = null;
}
module.exports = SSA;
github indutny / json-pipeline / lib / pipeline / dominance / index.js View on Github external
Dominance.prototype.enumerate = function enumerate() {
  // Simple DFS with range tracking
  var queue = [ this.blocks[0] ];
  var visited = new BitField(this.blocks.length);

  this.blocks[0].dominanceDepth = 0;

  var index = 0;
  while (queue.length !== 0) {
    var block = queue[queue.length - 1];
    if (!visited.set(block.blockIndex))
      continue;

    for (var i = block.children.length - 1; i >= 0; i--)
      queue.push(block.children[i]);

    block.dominanceStart = index++;
    if (block.parent !== null)
      block.dominanceDepth = block.parent.dominanceDepth + 1;
github indutny / json-pipeline / lib / pipeline / cfg / index.js View on Github external
CFGBuilder.prototype._reindexBlocks = function _reindexBlocks() {
  var out = [];

  var visited = new BitField(this.blocks.length);
  var queue = [ this.blocks[0] ];
  while (queue.length !== 0) {
    var block = queue.pop();

    var ready = true;
    for (var i = 0; i < block.predecessors.length; i++)
      if (!visited.check(block.predecessors[i].blockIndex))
        ready = false;

    // Back edge
    if (queue.length === 0)
      ready = true;
    if (!ready)
      continue;

    if (visited.set(block.blockIndex))
github webtorrent / webtorrent-desktop / renderer / views / player.js View on Github external
function renderLoadingBar (state) {
  var torrentSummary = getPlayingTorrentSummary(state)
  if (!torrentSummary.progress) {
    return []
  }

  // Find all contiguous parts of the torrent which are loaded
  var prog = torrentSummary.progress
  var fileProg = prog.files[state.playing.fileIndex]
  var parts = []
  var lastPiecePresent = false
  for (var i = fileProg.startPiece; i <= fileProg.endPiece; i++) {
    var partPresent = Bitfield.prototype.get.call(prog.bitfield, i)
    if (partPresent && !lastPiecePresent) {
      parts.push({start: i - fileProg.startPiece, count: 1})
    } else if (partPresent) {
      parts[parts.length - 1].count++
    }
    lastPiecePresent = partPresent
  }

  // Output some bars to show which parts of the file are loaded
  return hx`
    <div class="loading-bar">
      ${parts.map(function (part) {
        var style = {
          left: (100 * part.start / fileProg.numPieces) + '%',
          width: (100 * part.count / fileProg.numPieces) + '%'
        }</div>
github fanpei91 / torsniff / src / wire.js View on Github external
constructor(infohash){
    super();
    
    this._bitfield = new BitField(0, { 
      grow: BITFIELD_GROW 
    });
    this._infohash = infohash;
    
    this._buffer = [];
    this._bufferSize = 0;
    
    this._next = null;
    this._nextSize = 0;
    
    this._metadata = null;
    this._metadataSize = null;
    this._numPieces = 0;
    this._ut_metadata = null;
    
    this._onHandshake();

bitfield

a simple bitfield, compliant with the BitTorrent spec

MIT
Latest version published 4 months ago

Package Health Score

78 / 100
Full package analysis

Popular bitfield functions