Ejemplo n.º 1
0
void bitsetDivide(std::bitset<N> x, std::bitset<N> y,
  std::bitset<N>& q, std::bitset<N>& r)
{
  if (y.none( )) {
    throw std::domain_error("division by zero undefined");
  }
  q.reset( );
  r.reset( );
  if (x.none( )) {
    return;
  }
  if (x == y) {
    q[0] = 1;
    return;
  }
  r = x;
  if (bitsetLt(x, y)) {
    return;
  }

  // count significant digits in divisor and dividend
  unsigned int sig_x;
  for (int i=N-1; i>=0; i--) {
    sig_x = i;
    if (x[i]) break;
  }
  unsigned int sig_y;
  for (int i=N-1; i>=0; i--) {
    sig_y = i;
    if (y[i]) break;
  }

  // align the divisor with the dividend
  unsigned int n = (sig_x - sig_y);
  y <<= n;

  // make sure the loop executes the right number of times
  n += 1;

  // long division algorithm, shift, and subtract
  while (n--)
  {
    // shift the quotient to the left
    if (bitsetLtEq(y, r))
    {
      // add a new digit to quotient
      q[n] = true;
      bitsetSubtract(r, y);
    }
    // shift the divisor to the right
    y >>= 1;
  }
}
Ejemplo n.º 2
0
float Apriori::calc_support(std::bitset<NUM> bsdata)
{
    float support = 0.0;
    unsigned count = 0;
    std::bitset<NUM> b;
    /*
     * 1. std::map<unsigned ,IndexBitSet_t>   m_base_dataset;
     *    (data,vec float) -> (data,bitset)
     * */
    if(bsdata.none()) return 0.0;
    for(auto iter = this->m_base_dataset.begin();
             iter!= this->m_base_dataset.end(); iter++){
        b.reset();
        b |= (this->m_bitset_vec[iter->second] & bsdata) ^ bsdata;
        if(b.none()) count++;
    }
    support = (count*1.0) / (this->m_base_dataset.size() * 1.0);
    return support;
}
Ejemplo n.º 3
0
			inline void evaluateResultConditions(std::bitset<bit_width> const& result) {
				if (result.none())
					this->setFlag(FLAGS::Zero);
				if (result.test(bit_width - 1))
					this->setFlag(FLAGS::Negative);
			}