<commit_before>const Buffer = require('safe-buffer').Buffer
const assert = require('assert')
const utils = require('ethereumjs-util')
const byteSize = 256

/**
 * Represents a Bloom
 * @constructor
 * @param {Buffer} bitvector
 */
var Bloom = module.exports = function (bitvector) {
  if (!bitvector) {
    this.bitvector = utils.zeros(byteSize)
  } else {
    assert(bitvector.length === byteSize, 'bitvectors must be 2048 bits long')
    this.bitvector = bitvector
  }
}

/**
 * adds an element to a bit vector of a 64 byte bloom filter
 * @method add
 * @param {Buffer} element
 */
Bloom.prototype.add = function (e) {
  e = utils.sha3(e)
  var mask = 2047 // binary 11111111111

  for (var i = 0; i < 3; i++) {
    var first2bytes = e.readUInt16BE(i * 2)
    var loc = mask & first2bytes
    var byteLoc = loc >> 3
    var bitLoc = 1 << loc % 8
    this.bitvector[byteSize - byteLoc - 1] |= bitLoc
  }
}

/**
 * checks if an element is in the blooom
 * @method check
 * @param {Buffer} element
 */
Bloom.prototype.check = function (e) {
  e = utils.sha3(e)
  var mask = 511 // binary 111111111
  var match = true

  for (var i = 0; i < 3 && match; i++) {
    var first2bytes = e.readUInt16BE(i * 2)
    var loc = mask & first2bytes
    var byteLoc = loc >> 3
    var bitLoc = 1 << loc % 8
    match = (this.bitvector[byteSize - byteLoc - 1] & bitLoc)
  }

  return Boolean(match)
}

/**
 * checks if multple topics are in a bloom
 * @method check
 * @param {Buffer} element
 */
Bloom.prototype.multiCheck = function (topics) {
  var self = this
  return topics.every(function (t) {
    if (!Buffer.isBuffer(t)) {
      t = Buffer.from(t, 'hex')
    }
    return self.check(t)
  })
}

/**
 * bitwise or blooms together<commit_msg>Use 11-bit mask in Bloom.check (fixes #303)<commit_after>const Buffer = require('safe-buffer').Buffer
const assert = require('assert')
const utils = require('ethereumjs-util')
const byteSize = 256

/**
 * Represents a Bloom
 * @constructor
 * @param {Buffer} bitvector
 */
var Bloom = module.exports = function (bitvector) {
  if (!bitvector) {
    this.bitvector = utils.zeros(byteSize)
  } else {
    assert(bitvector.length === byteSize, 'bitvectors must be 2048 bits long')
    this.bitvector = bitvector
  }
}

/**
 * adds an element to a bit vector of a 64 byte bloom filter
 * @method add
 * @param {Buffer} element
 */
Bloom.prototype.add = function (e) {
  e = utils.sha3(e)
  var mask = 2047 // binary 11111111111

  for (var i = 0; i < 3; i++) {
    var first2bytes = e.readUInt16BE(i * 2)
    var loc = mask & first2bytes
    var byteLoc = loc >> 3
    var bitLoc = 1 << loc % 8
    this.bitvector[byteSize - byteLoc - 1] |= bitLoc
  }
}

/**
 * checks if an element is in the blooom
 * @method check
 * @param {Buffer} element
 */
Bloom.prototype.check = function (e) {
  e = utils.sha3(e)
  var mask = 2047 // binary 11111111111
  var match = true

  for (var i = 0; i < 3 && match; i++) {
    var first2bytes = e.readUInt16BE(i * 2)
    var loc = mask & first2bytes
    var byteLoc = loc >> 3
    var bitLoc = 1 << loc % 8
    match = (this.bitvector[byteSize - byteLoc - 1] & bitLoc)
  }

  return Boolean(match)
}

/**
 * checks if multple topics are in a bloom
 * @method check
 * @param {Buffer} element
 */
Bloom.prototype.multiCheck = function (topics) {
  var self = this
  return topics.every(function (t) {
    if (!Buffer.isBuffer(t)) {
      t = Buffer.from(t, 'hex')
    }
    return self.check(t)
  })
}

/**
 * bitwise or blooms together
{'fraction_non_alphanumeric': 0.135181480422978, 'fraction_numerical': 0.03658188053729637, 'mean_word_length': 2.8845726970033296, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 4, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1114763', 'n_tokens_mistral': 1302, 'n_tokens_neox': 1197, 'n_words': 377}