Ejemplo n.º 1
0
static bool loopVisit(const Block* b,
                      boost::dynamic_bitset<>& visited,
                      boost::dynamic_bitset<>& path) {
  if (b == nullptr) return false;

  auto const id = b->id();

  // If we're revisiting a block in our current search, then we've
  // found a backedge.
  if (path.test(id)) return true;

  // Otherwise if we're getting back to a block that's already been
  // visited, but it hasn't been visited in this path, then we can
  // prune this search.
  if (visited.test(id)) return false;

  visited.set(id);
  path.set(id);

  bool res = loopVisit(b->taken(), visited, path) ||
             loopVisit(b->next(), visited, path);

  path.set(id, false);

  return res;
}
Ejemplo n.º 2
0
void DFSSortClusters::dfs(uint32_t cid) {

  if (m_visited.test(cid)) return;
  m_visited.set(cid);
  m_list.push_back(Vlabel(cid));

  // find the best successor, which is the one to which cid has the
  // highest weight among the ones that haven't been visited yet
  int64_t  maxWgt = 0;
  uint32_t bestSucc = uint32_t(-1);
  for (auto& sInfo : m_clusterSuccs[cid]) {
    auto succId = sInfo.first;
    if (m_visited.test(succId)) continue;
    auto wgt = sInfo.second;
    if (wgt >= maxWgt) {
      maxWgt   = wgt;
      bestSucc = succId;
    }
  }

  if (bestSucc == uint32_t(-1)) return;

  // visit bestSucc first
  dfs(bestSucc);

  // now visit the remaining ones
  for (auto& sInfo : m_clusterSuccs[cid]) {
    if (sInfo.first != bestSucc) {
      dfs(sInfo.first);
    }
  }
}
Ejemplo n.º 3
0
/******************************************************************************
* Remaps the bonds after some of the particles have been deleted.
* Dangling bonds are removed too.
******************************************************************************/
void BondsObject::particlesDeleted(const boost::dynamic_bitset<>& deletedParticlesMask)
{
	// Build map that maps old particle indices to new indices.
	std::vector<size_t> indexMap(deletedParticlesMask.size());
	auto index = indexMap.begin();
	size_t oldParticleCount = deletedParticlesMask.size();
	size_t newParticleCount = 0;
	for(size_t i = 0; i < deletedParticlesMask.size(); i++)
		*index++ = deletedParticlesMask.test(i) ? std::numeric_limits<size_t>::max() : newParticleCount++;

	auto result = modifiableStorage()->begin();
	auto bond = modifiableStorage()->begin();
	auto last = modifiableStorage()->end();
	for(; bond != last; ++bond) {
		// Remove invalid bonds.
		if(bond->index1 >= oldParticleCount || bond->index2 >= oldParticleCount)
			continue;

		// Remove dangling bonds whose particles have gone.
		if(deletedParticlesMask.test(bond->index1) || deletedParticlesMask.test(bond->index2))
			continue;

		// Keep but remap particle indices.
		result->pbcShift = bond->pbcShift;
		result->index1 = indexMap[bond->index1];
		result->index2 = indexMap[bond->index2];
		++result;
	}
	modifiableStorage()->erase(result, last);
	changed();
}
    void operator()( space_type & ss, boost::dynamic_bitset<> & indices, result_type column_margin, result_type row_margin ) {

        const unsigned int N = ss.haploid_genome_count();

        for( unsigned int i = 0; i < N; ++i ) {
            if( !indices.test(i) ) continue;

            genome_pointer first = ss.begin_genome(i), last = ss.end_genome(i);

            unsigned int j = 0;
            unsigned int M = 0;
            while( first != last ) {
                block_type b = *first++;

                unsigned int idx = j;
                while( b ) {
                    idx += bit_walker_type::next_and_shift( b );
                    column_margin[ idx ]++;
                    ++M;
                }
                j += bit_helper_type::BITS_PER_BLOCK;
            }

            row_margin[ i ] = M;
        }
    }
Ejemplo n.º 5
0
void normalize_split( boost::dynamic_bitset<>& split, const vector< vector< int > >& splitmap, int target_size ){
	boost::dynamic_bitset<> newsplit( target_size );
	for( int i=0; i<splitmap.size(); i++ )
		for(int j=0; j<splitmap[i].size(); j++)
			newsplit.set( splitmap[i][j], split.test(i) );
	split = newsplit;
}
    void operator()( space_type & ss, boost::dynamic_bitset<> & indices, result_type column_margin, result_type row_margin ) {
        typedef typename space_type::raw_block_pointer iterator;

        size_type N = ss.row_count();
        size_type i = 0;
        while ( i < N ) {
            if( !indices.test(i) ) {
                ++i;
                continue;
            }

            iterator start = ss.begin_row(i);
            iterator end = ss.end_row(i);

            size_type j = 0, M = 0;
            while( start != end ) {
                block_type b = *start++;

                while( b ) {
                    unsigned int b_idx = bit_walker_type::unset_next_index( b ) + j;
                    column_margin[ b_idx ] += 1;
                    ++M;
                }
                
                j += bit_helper_type::BITS_PER_BLOCK;
            }
            row_margin[ i ] = M;
            ++i;
        }
    }
Ejemplo n.º 7
0
 void bitset_to_vector( binary_truth_table::cube_type& vec, const boost::dynamic_bitset<> number )
 {
   vec.clear();
   for ( unsigned i = 0u; i < number.size(); ++i )
   {
     vec.push_back( number.test( i ) );
   }
 }
Ejemplo n.º 8
0
template<typename PointT, typename NormalT> bool 
pcl::NormalSpaceSampling<PointT, NormalT>::isEntireBinSampled (boost::dynamic_bitset<> &array, unsigned int start_index, unsigned int length)
{
  bool status = true;
  for (unsigned int i = start_index; i < start_index + length; i++)
  {
    status = status & array.test (i);
  }
  return status;
}
Ejemplo n.º 9
0
 //
 // Derive index code from a bitset, that is, return a vector of all indices
 // that are set in the bitset
 //
 std::vector<int> index_code(const boost::dynamic_bitset<>& b)
 {
     std::vector<int> v;
     v.reserve(b.count());
     for (int i=0; i<int(b.size()); ++i) {
         if (b.test(i)) {    //if (b[i] == 1)
             v.push_back(i);
         }
     }
     return v;
 }
Ejemplo n.º 10
0
void removeDeadInstructions(Trace* trace, const boost::dynamic_bitset<>& live) {
  auto &blocks = trace->getBlocks();
  for (auto it = blocks.begin(), end = blocks.end(); it != end;) {
    auto cur = it; ++it;
    Block* block = *cur;
    block->remove_if([&] (const IRInstruction& inst) {
      assert(inst.getIId() < live.size());
      return !live.test(inst.getIId());
    });
    if (block->empty()) blocks.erase(cur);
  }
}
Ejemplo n.º 11
0
    // Returns true if at least one destination has been retained, i.e. one
    // destination is remote. It returns false if all destinations have been
    // local.
    inline std::vector<naming::gid_type>::iterator
    remove_local_destinations(std::vector<naming::gid_type>& gids,
        std::vector<naming::address>& addrs,
        boost::dynamic_bitset<> const& locals)
    {
        HPX_ASSERT(gids.size() == addrs.size());

        std::vector<naming::gid_type>::iterator gids_it = gids.begin();
        std::vector<naming::gid_type>::iterator gids_end = gids.end();
        std::vector<naming::address>::iterator addrs_it = addrs.begin();

        // gids_it = find_if(gids_it, gids_end, pred)
        std::size_t i = 0;
        for (/**/; gids_it != gids_end; ++gids_it, ++addrs_it)
        {
            if (locals.test(i++))
                break;
        }
        if (gids_it == gids_end)
            return gids_it;

        // gids_next = remove_if(gids_it, gids_end, pred)
        std::vector<naming::gid_type>::iterator gids_next = gids_it;
        std::vector<naming::address>::iterator addrs_next = addrs_it;

        for (++gids_it, ++addrs_it; gids_it != gids_end; ++gids_it, ++addrs_it)
        {
            if (!locals.test(i++))
            {
                *gids_next++ = std::move(*gids_it);
                *addrs_next++ = std::move(*addrs_it);
            }
        }

        return gids_next;
    }
Ejemplo n.º 12
0
	std::string format_binary(const boost::dynamic_bitset<>& b) {
		std::ostringstream oss;
		oss.imbue(std::locale::classic());
		oss.put('"');
		oss << std::hex << std::setw(1);
		unsigned c = b.size();
		unsigned n = (4 - (c % 4)) & 3;
		oss << n;
		for (unsigned i = 0; i < c + n;) {
			unsigned accum = 0;
			for (int j = 0; j < 4; ++j, ++i) {
				unsigned bit = i < n ? 0 : b.test(c - i + n - 1) ? 1 : 0;
				accum |= bit << (3-j);
			}
			oss << accum;
		}
		oss.put('"');
		return oss.str();
	}
Ejemplo n.º 13
0
bool BDDCalculator::calculate(const boost::dynamic_bitset<> &varValues) const
{
	if(!m_proot)
		return false;

	BDDCalculator::Node *pnode = m_proot -> m_pnode;

	if(!pnode)
		return false;


	for(;;)
	{
		if(pnode -> m_fixTrue && pnode -> m_fixFalse)
		{
			if(varValues.test(pnode -> m_varId))
				pnode = pnode -> m_fixTrue;
			else
				pnode = pnode -> m_fixFalse;
		}
		else
			return pnode -> m_value;
	}
}
Ejemplo n.º 14
0
	/**
	 * Allow certain vertices to have only children, but no parents
	 */
	bool getChildrenOnly(const uint vertex) const { return _childrenOnly.test(vertex); }