예제 #1
0
    void IdCollection<ESXRecordT>::merge()
    {
        for (typename std::vector<Record<ESXRecordT> >::iterator iter (mRecords.begin()); iter!=mRecords.end(); ++iter)
            iter->merge();

        purge();
    }
예제 #2
0
    // adds a value, returning false if the given token is not
    // "reasonable".  A reasonable token is one not currently in use,
    // and if any previously used tokens are available, it must be one
    // of the previously used ones.  If no previously used tokens are
    // available, it must be the smallest unused token.  You'll get
    // good performance if you never choose a bad token and use the
    // most recently dropped token.
    bool add(token_type known_token, T const& value) {
        if (free_.empty()) {
            if (known_token == values_.size()) {
                values_.push_back(value);
#ifndef NDEBUG
                is_free_.push_back(false);
#endif
                return true;
            } else {
                return false;
            }
        } else {
            // If a replicand used add(), then it picked the token
            // from the bock of its free list.  So the replicant, the
            // presumed caller of this function, searches in reverse
            // order.
            typename std::vector<token_t>::reverse_iterator p = std::find(free_.rbegin(), free_.rend(), known_token);
            if (p == free_.rend()) {
                return false;
            }

            if (values_.size() > known_token) {
                free_.erase(p.base() - 1);
                values_[known_token] = value;
                rassert(is_free_[known_token]);
#ifndef NDEBUG
                is_free_[known_token] = false;
#endif

                return true;
            } else {
                return false;
            }
        }
    }
예제 #3
0
    void CorrectKiKf::correctKiKfEventHelper(std::vector<T>& wevector, double efixed,const std::string emodeStr)
{
  double Ei,Ef;
  float kioverkf;
  typename std::vector<T>::iterator it;
  for (it=wevector.begin(); it<wevector.end();)
  {
    if (emodeStr == "Direct")  //Ei=Efixed
    {
      Ei = efixed;
      Ef = Ei - it->tof();
    } else                     //Ef=Efixed
    { 
      Ef = efixed;
      Ei = Ef + it->tof();
    }
    // if Ei or Ef is negative, delete the event
    if ((Ei <= 0)||(Ef <= 0))
    {
      it=wevector.erase(it);
    } 
    else 
    {
      kioverkf = static_cast<float>(std::sqrt( Ei / Ef ));
      it->m_weight*=kioverkf;
      it->m_errorSquared*=kioverkf*kioverkf;
      ++it;
    }
  }
}
예제 #4
0
파일: output.cpp 프로젝트: DavidPH/DH-acc
//
// BinaryTokenACS::output_ACS0
//
template<typename T> void BinaryTokenACS::output_ACS0
(std::ostream *out, std::vector<T> const &instructions)
{
   typename std::vector<T>::const_iterator instr;

   // 0
   *out << 'A' << 'C' << 'S' << '\0';
   write_ACS0_32(out, ObjectExpression::get_address_count());

   // 8
   for (instr = instructions.begin(); instr != instructions.end(); ++instr)
      instr->writeACS0(out);

   // directoryOffset
   ObjectData::Script::Iterate(write_ACS0_script_counter, NULL);
   write_ACS0_script_count(out);

   // directoryOffset+4
   ObjectData::Script::Iterate(write_ACS0_script, out);

   // directoryOffset+4+(scriptCount*12)
   ObjectData::String::Iterate(write_ACS0_string_counter, NULL);
   write_ACS0_string_count(out);

   // directoryOffset+4+(scriptCount*12)+4
   ObjectData::String::Iterate(write_ACS0_string_offset, out);

   // directoryOffset+4+(scriptCount*12)+4+(stringCount*4)
   ObjectData::String::Iterate(write_ACS0_string, out);
}
예제 #5
0
파일: 4_2.cpp 프로젝트: Ganglians/Practice
 //Prints graph node's adjacency lists
 void print() {
     for(typename std::vector<node>::iterator it = nodeL.begin(); it != nodeL.end(); it ++) {
         cout << "Node " << it->val << "'s adj list:\n";
         it->print();
         cout << endl;
     }
 }
예제 #6
0
 void cancelAll() {
   assert(*_closed);
   for (typename std::vector< Future<T> >::iterator it = this->_futures.begin();
        it != this->_futures.end();
        ++it)
     it->cancel();
 }
int GenomicRegionCollection<T>::TotalWidth() const { 
  int wid = 0; 
  for (typename std::vector<T>::const_iterator i = m_grv->begin(); i != m_grv->end(); ++i)
    //  for (auto& i : *m_grv) 
    wid += i->Width(); 
  return wid; 
}
예제 #8
0
void Array2D<T>::resize( const std::size_t& x, const std::size_t& y )
{

    // scale x-dimension up or down
    if( x != m_SizeX )
    {
        m_Array.resize( x );
        while( x > m_SizeX )
        {
            m_Array[m_SizeX].resize( m_SizeY, m_DefaultContent );
            ++m_SizeX;
        }
        m_SizeX = x;
    }

    // scale y-dimension up or down
    if( y != m_SizeY )
    {
        for( typename std::vector< std::vector<T> >::iterator it = m_Array.begin(); it != m_Array.end(); ++it )
        {
            it->resize( y, m_DefaultContent );
        }
        m_SizeY = y;
    }
}
예제 #9
0
void SaveNexusProcessed::appendEventListData(std::vector<T> events,
                                             size_t offset, double *tofs,
                                             float *weights,
                                             float *errorSquareds,
                                             int64_t *pulsetimes) {
  // Do nothing if there are no events.
  if (events.empty())
    return;

  typename std::vector<T>::const_iterator it;
  typename std::vector<T>::const_iterator it_end = events.end();
  size_t i = offset;

  // Fill the C-arrays with the fields from all the events, as requested.
  for (it = events.begin(); it != it_end; it++) {
    if (tofs)
      tofs[i] = it->tof();
    if (weights)
      weights[i] = static_cast<float>(it->weight());
    if (errorSquareds)
      errorSquareds[i] = static_cast<float>(it->errorSquared());
    if (pulsetimes)
      pulsetimes[i] = it->pulseTime().totalNanoseconds();
    i++;
  }
}
예제 #10
0
 int put(const T& name)
 {
   int symbol = m_int2name.size();
   m_int2name.push_back(name);
   m_name2int[name] = symbol;
   return symbol;
 }
예제 #11
0
 void cancelAll() {
   QI_ASSERT(_closed.load());
   for (typename std::vector< Future<T> >::iterator it = this->_futures.begin();
        it != this->_futures.end();
        ++it)
     it->cancel();
 }
예제 #12
0
inline void  BaseGeneticAlgorithm<FITNESS_TYPE>::registerObserver(const std::shared_ptr<AlgorithmObserver<FITNESS_TYPE>> &observer)
{
    typedef std::set<typename AlgorithmObserver<FITNESS_TYPE>::ObserveableEvent> setType;
    const setType events = observer->getSubscribedEvents();
    for (const auto &it :events)
    {

        typename observers_map::iterator lb = _observers.lower_bound(it);

        if (lb != _observers.end() && !(_observers.key_comp()(it, lb->first)))
        {
            // key already exists
            // update lb->second if you care to
            lb->second.emplace_back(observer);
        }
        else
        {
            // the key does not exist in the map
            // add it to the map
            typename std::vector<std::shared_ptr<AlgorithmObserver<FITNESS_TYPE>>> list;
            list.emplace_back(observer);
            _observers.insert(lb, typename observers_map::value_type(it, list));    // Use lb as a hint to insert,
        }

    }

}
//**********************************************************************
PHX_EVALUATE_FIELDS(GlobalStatistics,workset)
{
    if (workset.num_cells == 0)
        return;

    Intrepid::FunctionSpaceTools::integrate<ScalarT>(volumes, ones,
            (this->wda(workset).int_rules[ir_index])->weighted_measure,
            Intrepid::COMP_BLAS);

    for (std::size_t cell = 0; cell < workset.num_cells; ++cell)
        total_volume += volumes(cell);

    typename std::vector<PHX::MDField<ScalarT,Cell,IP> >::size_type field_index = 0;
    for (typename std::vector<PHX::MDField<ScalarT,Cell,IP> >::iterator field = field_values.begin();
            field != field_values.end(); ++field,++field_index) {

        Intrepid::FunctionSpaceTools::integrate<ScalarT>(tmp, *field,
                (this->wda(workset).int_rules[ir_index])->weighted_measure,
                Intrepid::COMP_BLAS);

        for (std::size_t cell = 0; cell < workset.num_cells; ++cell) {
            averages[field_index] += tmp(cell);

            for (typename PHX::MDField<ScalarT,Cell,IP>::size_type ip = 0; ip < (field->dimension(1)); ++ip) {
                maxs[field_index] = std::max( (*field)(cell,ip), maxs[field_index]);
                mins[field_index] = std::min( (*field)(cell,ip), mins[field_index]);
            }
        }

    }
}
예제 #14
0
파일: enum_box.hpp 프로젝트: brojudd/ubuntu
 std::vector<std::string> get_names() const
 {
   typename std::vector<std::string> lst;
   for(const_iterator i = begin(); i != end(); ++i)
   {
     lst.push_back(i->second);
   }
   return lst;
 }
예제 #15
0
inline boost::shared_ptr< Base > Construct(
	std::vector< t_OriginalVectorType >& vectors,
	std::vector< double >& labels,
	unsigned int const trainingSize,
	std::vector< std::string > const& kernelParameters,
	unsigned int const cacheSize = 0
)
{
	uint64_t sparseSize = 0;
	if ( t_Traits::SPARSE_ALLOWED ) {

		typename std::vector< SparseVector< t_Type > >::const_iterator ii    = vectors.begin();
		typename std::vector< SparseVector< t_Type > >::const_iterator iiEnd = vectors.end();
		for ( ; ii != iiEnd; ++ii )
			sparseSize += ii->Size();
	}

	uint64_t spanSize = 0;
	if ( t_Traits::SPAN_ALLOWED ) {

		typename std::vector< SparseVector< t_Type > >::const_iterator ii    = vectors.begin();
		typename std::vector< SparseVector< t_Type > >::const_iterator iiEnd = vectors.end();
		for ( ; ii != iiEnd; ++ii )
			spanSize += SpanVector< t_Type >( *ii ).Size();
	}

	uint64_t denseSize = 0;
	{	typename std::vector< SparseVector< t_Type > >::const_iterator ii    = vectors.begin();
		typename std::vector< SparseVector< t_Type > >::const_iterator iiEnd = vectors.end();
		for ( ; ii != iiEnd; ++ii )
			denseSize += DenseVector< t_Type >( *ii ).Size();
	}

	boost::shared_ptr< Base > result;

	if (
		t_Traits::SPARSE_ALLOWED &&
		( ( ! t_Traits::SPAN_ALLOWED ) || ( sparseSize <= spanSize ) ) &&
		( sparseSize <= denseSize )
	)
	{
		result = boost::shared_ptr< Base >( new t_KernelType< SparseVector< t_Type >, t_Traits >( vectors, labels, trainingSize, kernelParameters, cacheSize ) );
	}
	else if (
		t_Traits::SPAN_ALLOWED &&
		( spanSize <= denseSize )
	)
	{
		result = boost::shared_ptr< Base >( new t_KernelType< SpanVector< t_Type >, t_Traits >( vectors, labels, trainingSize, kernelParameters, cacheSize ) );
	}
	else {

		result = boost::shared_ptr< Base >( new t_KernelType< DenseVector< t_Type >, t_Traits >( vectors, labels, trainingSize, kernelParameters, cacheSize ) );
	}

	return result;
}
 property_t(const std::vector<std::vector<T> >& mtx) {
     vector matrix;
     for(typename std::vector<std::vector<T> >::const_iterator i = mtx.begin(); i != mtx.end(); ++i) {
         vector row;
         for(typename std::vector<T>::const_iterator j = i->begin(); j != i->end(); ++j)
             row.push_back(*j);
         matrix.push_back(row);
     }
     property_base::operator= <vector>(matrix);
 }
예제 #17
0
qi::FutureSync< qi::Future<T> > waitForFirst(std::vector< Future<T> >& vect) {
  typename std::vector< Future<T> >::iterator it;
  qi::Promise< qi::Future<T> > prom;
  qi::Atomic<int>* count = new qi::Atomic<int>();
  count->swap((int)vect.size());
  for (it = vect.begin(); it != vect.end(); ++it) {
    it->connect(boost::bind<void>(&detail::waitForFirstHelper<T>, prom, *it, count));
  }
  return prom.future();
}
 std::vector<T> getCallbacks() {
   typename std::vector<T> result;
   result.reserve(functionList.size() - invalidIndexCount);
   for (typename TypedFunctionPointerWrapperRefVector<T>::type::iterator it = functionList.begin(); it != functionList.end(); it++) {
     if (*it) {
       result.push_back((*it)->callback);
     }
   }
   return result;
 }
예제 #19
0
파일: grid.hpp 프로젝트: Xecantur/yap
  void update() {
    typename std::vector<Element>::iterator i;
    int count = 0;
    SDL_Rect * warn_if_same_pos = grid.begin()->getSize();
    int warn_count = 0;
    for (i = grid.begin(); i != grid.end(); i++) {
#ifndef NO_WARNINGS
        if(i->getSize()->x == warn_if_same_pos->x
                &&
           i->getSize()->y == warn_if_same_pos->y)
        {
            warn_count++;
        }
        if(warn_count > 2)
        {
            printf("Warning!!!! you may be using the same object over and over again!\nuse object *  name = new * object(args); in your population routine: gridObject.append(*object); delete name; name = new * object(args);\n");
        }
#endif
#ifdef DEBUG
        printf("Render[%d]: at (%d,%d)\n",count,i->getSize()->x,i->getSize()->y);
#endif

      SDL_RenderCopy(i->getRenderer(), i->getImage(), NULL, i->getSize());
      warn_if_same_pos = i->getSize();
      count++;
    }
  }
예제 #20
0
 Y interpolate(const X&x) const {
     if (mElements.size() == 0) return Y();
 
     typename std::vector<element_type>::const_iterator it;
     it = std::lower_bound(mElements.begin(), mElements.end(), element_type(x));
     if (it != mElements.begin()) {
         it--;
     }   
     
     return it->eval(x);
 }
예제 #21
0
  virtual void execute(const DOM::Node<string_type, string_adaptor>& node, ExecutionContext<string_type, string_adaptor>& context) const
  {
    if(context.sink().start_element(name_, namespace_))
    {
      for(typename std::vector<InlineAttribute<string_type, string_adaptor> >::const_iterator a = attrs_.begin(), ae = attrs_.end(); a != ae; ++a)
        a->execute(node, context);

      ChainStackFrame<string_type, string_adaptor> frame(context);
      this->execute_children(node, context);
      context.sink().end_element(name_, namespace_);
    }
  } // execute
예제 #22
0
void
flushBuffer(int tag,
		std::vector<T>& input,
		std::vector< std::vector<T> >& output,
		boost::mpi::communicator& world)
{
	broadcast(world, tag, MASTER);
	scatter(world, output, input, MASTER);
	for(typename std::vector< std::vector<T> >::iterator i = output.begin(); i != output.end(); ++i) {
		i->clear();
	}
}
예제 #23
0
  void MultiplyMD::execEventScalar(typename MDEventWorkspace<MDE, nd>::sptr ws)
  {
    // Get the scalar multiplying
    float scalar = float(m_rhs_scalar->dataY(0)[0]);
    float scalarError = float(m_rhs_scalar->dataE(0)[0]);
    float scalarRelativeErrorSquared = (scalarError * scalarError) / (scalar * scalar);

    // Get all the MDBoxes contained
    MDBoxBase<MDE,nd> * parentBox = ws->getBox();
    std::vector<API::IMDNode *> boxes;
    parentBox->getBoxes(boxes, 1000, true);

    bool fileBackedTarget(false);
    Kernel::DiskBuffer *dbuff(NULL);
    if(ws->isFileBacked())
    {
        fileBackedTarget = true;
        dbuff = ws->getBoxController()->getFileIO();
    }
 

    for (size_t i=0; i<boxes.size(); i++)
    {
      MDBox<MDE,nd> * box = dynamic_cast<MDBox<MDE,nd> *>(boxes[i]);
      if (box)
      {
        typename std::vector<MDE> & events = box->getEvents();
        size_t ic(events.size());
        typename std::vector<MDE>::iterator it = events.begin();
        typename std::vector<MDE>::iterator it_end = events.end();
        for (; it != it_end; it++)
        {
          // Multiply weight by a scalar, propagating error
          float oldSignal = it->getSignal();
          float signal = oldSignal * scalar;
          float errorSquared = signal * signal * (it->getErrorSquared() / (oldSignal * oldSignal) + scalarRelativeErrorSquared);
          it->setSignal(signal);
          it->setErrorSquared(errorSquared);
        }
        box->releaseEvents();
        if(fileBackedTarget && ic>0)
        {
            Kernel::ISaveable *const pSaver(box->getISaveable());
            dbuff->toWrite(pSaver);
        }

      }
    }
    // Recalculate the totals
    ws->refreshCache();
    // Mark file-backed workspace as dirty
    ws->setFileNeedsUpdating(true);
  }
예제 #24
0
 void clearAll()
 {
     CriticalBlock b(crit); 
     typename std::vector<Linked<T> >::iterator it;
     for(it=resources.begin();it!=resources.end();it++)
     {
         if(it->get())
         {
             it->clear();
         }
     }
 }
예제 #25
0
void UnaryOperation::unaryOperationEventHelper(std::vector<T> &wevector) {

  typename std::vector<T>::iterator it;
  for (it = wevector.begin(); it < wevector.end(); ++it) {
    double yout, eout;
    // Call the abstract function, passing in the current values
    performUnaryOperation(it->tof(), it->weight(),
                          std::sqrt(it->errorSquared()), yout, eout);
    it->m_weight = static_cast<float>(yout);
    it->m_errorSquared = static_cast<float>(eout * eout);
  }
}
예제 #26
0
파일: max_size.cpp 프로젝트: azer89/BBW
IGL_INLINE int igl::max_size(const std::vector<T> & V)
{
  int max_size = -1;
  for(
    typename std::vector<T>::const_iterator iter = V.begin();
    iter != V.end(); 
    iter++)
  {
    int size = (int)iter->size();
    max_size = (max_size > size ? max_size : size);
  }
  return max_size;
}
std::string GenomicRegionCollection<T>::AsBEDString(const BamHeader& h) const {
  
  if (m_grv->size() ==  0)
    return std::string(); 

  std::stringstream ss;
  //for (auto& i : *m_grv)
  for (typename std::vector<T>::const_iterator i = m_grv->begin(); i != m_grv->end(); ++i)
    ss << i->ChrName(h) << "\t" << i->pos1 << "\t" << i->pos2 << "\t" << i->strand << std::endl;

  return ss.str();

}
예제 #28
0
파일: Map.hpp 프로젝트: m2omou/bomberman
  virtual std::string serialize() const
  {
    std::stringstream ss;
    typename std::vector<U>::const_iterator it = this->begin();
    std::string tmp;

    ss << _width << " " << _height << " ";
    for (; it != this->end() ; ++it)
      {
	tmp = it->serialize();
	ss << tmp.length() << " " << tmp << " ";
      }
    return ss.str();
  }
예제 #29
0
파일: grid.hpp 프로젝트: Xecantur/yap
  void gridify() {
    typename std::vector<Element>::iterator i;
    SDL_Rect *last = grid.begin()->getSize();
    int count = 0;
    for (i = grid.begin(); i != grid.end(); i++) {
      if (i == grid.begin()) {
          i->getSize()->x = position.x;
          i->getSize()->y = position.y;
          last = i->getSize();
#ifdef DEBUG
          std::cout << "First Grid Element: " << i->getSize()->x << " , " << i->getSize()->y << std::endl;
#endif
      }
      else {
        if(count != (gx - 1))
        {
            i->getSize()->x = last->x + padding;
            i->getSize()->y = last->y;
            count++;
        } else {
            count = 0;
            i->getSize()->x = position.x;
            i->getSize()->y = last->y + padding;
        }
        last = i->getSize();
        }
      }
  }
예제 #30
0
void shiftGrid( std::vector<std::vector<Point2> >& grid, const Point2& shift )
{
	for( typename std::vector<std::vector<Point2> >::iterator itv = grid.begin(), itvEnd = grid.end();
	     itv != itvEnd;
	     ++itv )
	{
		for( typename std::vector<Point2>::iterator it = itv->begin(), itEnd = itv->end();
		     it != itEnd;
		     ++it  )
		{
			*it += shift;
		}
	}
}