void IndexingVariables::set(
    boost::unordered_map<std::string, boost::shared_ptr<ArrayStorage> > as,
    int offset) {
  hm.clear();
  hm.insert(as.begin(), as.end());
  this->offset = offset;
}
void IfcTreeWidget::slotObjectsSelected( boost::unordered_map<int, shared_ptr<IfcPPEntity> >& map )
{
	if( m_block_selection_signals )
	{
		return;
	}

	if( map.size() < 1 )
	{
		return;
	}

	// take the first object from map and highlight it
	shared_ptr<IfcPPEntity> object = (*(map.begin())).second;
	int selected_id = object->m_id;

	for( int i=0; i<topLevelItemCount(); ++i )
	{
		QTreeWidgetItem* toplevel_item = topLevelItem( i );
		QTreeWidgetItem* selected_item = ViewerUtil::findItemByIfcId( toplevel_item, selected_id );
		if( selected_item != 0 )
		{
			blockSignals(true);
			m_block_selection_signals = true;
			setCurrentItem( selected_item, 1, QItemSelectionModel::SelectCurrent );
			blockSignals(false);
			m_block_selection_signals = false;
			break;
		}
	}
}
Beispiel #3
0
 size_t count(std::string const& x) const {
     auto iter = counts.find(x);
     if (iter != counts.end()) {
         return iter->second;
     }
     return 0;
 }
Beispiel #4
0
Datei: var.cpp Projekt: hyln9/nV
wcs Symbol::name() const {
    boost::unordered_map<sym, wcs>::const_iterator
    iter = names.find(this);
    if (iter != names.end())
        return iter->second;
    return 0;
}
Beispiel #5
0
void read_db_torrents_sql()
{
	try
	{
		if (!m_config.m_auto_register)
		{
			Csql_result result = Csql_query(m_database, "select info_hash, @fid from @files where flags & 1").execute();
			while (Csql_row row = result.fetch_row())
			{
				m_torrents.erase(to_array<char, 20>(row[0]));
				Csql_query(m_database, "delete from @files where @fid = ?")(row[1]).execute();
			}
		}
		if (m_config.m_auto_register && !m_torrents.empty())
			return;
		Csql_result result = Csql_query(m_database, "select info_hash, @completed, @fid, ctime from @files where @fid >= ?")(m_fid_end).execute();
		// m_torrents.reserve(m_torrents.size() + result.size());
		while (Csql_row row = result.fetch_row())
		{
			m_fid_end = std::max<int>(m_fid_end, row[2].i() + 1);
			if (row[0].size() != 20 || find_torrent(row[0].s()))
				continue;
			t_torrent& file = m_torrents[to_array<char, 20>(row[0])];
			if (file.fid)
				continue;
			file.completed = row[1].i();
			file.dirty = false;
			file.fid = row[2].i();
			file.ctime = row[3].i();
		}
	}
	catch (bad_query&)
	{
	}
}
std::string RippleAddress::humanAccountID () const
{
    switch (nVersion)
    {
    case VER_NONE:
        throw std::runtime_error ("unset source - humanAccountID");

    case VER_ACCOUNT_ID:
    {
        boost::mutex::scoped_lock sl (rncLock);
        boost::unordered_map< Blob , std::string >::iterator it = rncMap.find (vchData);

        if (it != rncMap.end ())
            return it->second;

        if (rncMap.size () > 10000)
            rncMap.clear ();

        return rncMap[vchData] = ToString ();
    }

    case VER_ACCOUNT_PUBLIC:
    {
        RippleAddress   accountID;

        (void) accountID.setAccountID (getAccountID ());

        return accountID.ToString ();
    }

    default:
        throw std::runtime_error (str (boost::format ("bad source: %d") % int (nVersion)));
    }
}
Beispiel #7
0
void Graph::read(const char * fn) {
    std::ifstream inf (fn);
    std::string line;
    int n;
    node_number = 0;
    std::vector<int> tmp;
    while (std::getline(inf, line)) {
	read_line(line, &tmp);
	if ( tmp.size() == 2 ) {
	    if( node_order.find(tmp.at(0)) == node_order.end() ) {
		node_order[tmp.at(0)] = node_number;
		node_number++;
	    };
	    if( node_order.find(tmp.at(1)) == node_order.end() ) {
		node_order[tmp.at(1)] = node_number;
		node_number++;
	    };
	};
	tmp.clear();
    };
    nodes.resize(node_number);
    times.resize(node_number);
    visited.insert(visited.begin(), node_number, false);
    inf.clear();
    inf.seekg(0);
    while (std::getline(inf, line)) {
	read_line(line, &tmp);
	if ( tmp.size() == 2 ) {
	    nodes.at(node_order[tmp.at(1)]).add_reverse_edge(node_order[tmp.at(0)]);
	    nodes.at(node_order[tmp.at(0)]).add_edge(node_order[tmp.at(1)]);
	    };
	tmp.clear();
    };
    node_order.clear();
};
//! Dump Legendre polynomial cache data to stream (table and history).
void dumpLegendrePolynomialCacheData( std::ostream& outputStream,
                                      boost::unordered_map< Point, double > cacheTable,
                                      boost::circular_buffer< Point > cacheHistory )
{
    outputStream << "Table:\n";

    for ( boost::unordered_map< Point, double >::iterator iteratorCacheTable = cacheTable.begin( );
          iteratorCacheTable != cacheTable.end( ); iteratorCacheTable++ )
    {
        outputStream << "\t" << writeLegendrePolynomialStructureToString(
                            iteratorCacheTable->first ).c_str( ) << " => "
                     << iteratorCacheTable->second << std::endl;
    }

    outputStream << "History:\n";

    for ( boost::circular_buffer< Point >::iterator iteratorCacheHistory = cacheHistory.begin( );
          iteratorCacheHistory != cacheHistory.end( ); iteratorCacheHistory++ )
    {
        outputStream << "\t"
                     << writeLegendrePolynomialStructureToString( *iteratorCacheHistory ).c_str( )
                     << ", ";
    }

    outputStream << std::endl;
}
Beispiel #9
0
	bool dbconn_pool::init_pool(boost::unordered_map<std::string, std::string>& cfg)
	{
		std::vector<std::string> keys;
		{
			keys.push_back("host");
			keys.push_back("userid");
			keys.push_back("passwd");
			keys.push_back("database");
			keys.push_back("port");
			keys.push_back("charset");
			keys.push_back("pool_size");
			keys.push_back("wait_timeout_sec");
		}

		boost::unordered_map<std::string, std::string>::iterator found;
		for (std::size_t i = 0; i < keys.size(); ++i)
		{
			found = cfg.find(keys[i]);
			if (found == cfg.end())
			{
				return false;
			}

			if (keys[i] == "host")
			{
				host = found->second;
			}
			else if (keys[i] == "userid")
			{
				userid = found->second;
			}
			else if (keys[i] == "passwd")
			{
				passwd = found->second;
			}
			else if (keys[i] == "database")
			{
				database = found->second;
			}
			else if (keys[i] == "port")
			{
				port = boost::lexical_cast<unsigned int>(found->second);
			}
			else if (keys[i] == "charset")
			{
				charset = found->second;
			}
			else if (keys[i] == "pool_size")
			{
				pool_size = boost::lexical_cast<std::size_t>(found->second);
			}
			else if (keys[i] == "wait_timeout_sec")
			{
				wait_timeout_sec = boost::lexical_cast<double>(found->second);
			}
		}

		return true;
	}
Beispiel #10
0
///Calculates the Gini impurity of a node. The impurity is defined as
///1-sum_j p(j|t)^2
///i.e the 1 minus the sum of the squared probability of observing class j in node t
double CARTTrainer::gini(boost::unordered_map<std::size_t, std::size_t>& countMatrix, std::size_t n){
	double res = 0;
	boost::unordered_map<std::size_t, std::size_t>::iterator it;
	double denominator = n;
	for ( it=countMatrix.begin() ; it != countMatrix.end(); it++ ){
		res += sqr(it->second/denominator);
	}
	return 1-res;
}
Beispiel #11
0
bool buildNameLookupTable(Kompex::SQLiteStatement * stmt,
                          boost::unordered_map<std::string,int32_t> &table_names)
{
    std::string stmt_insert = "INSERT INTO name_lookup";
    stmt_insert += "(name_id,name_lookup) VALUES(@name_id,@name_lookup);";

    try   {
        stmt->BeginTransaction();
        stmt->Sql(stmt_insert);
    }
    catch(Kompex::SQLiteException &exception)   {
        qDebug() << "ERROR: SQLite exception with insert statement:"
                 << QString::fromStdString(exception.GetString());
        return false;
    }

    // keep track of the number of transactions and
    // commit after a certain limit
    size_t transaction_limit=5000;
    size_t transaction_count=0;

    // write name lookup info the database
    boost::unordered_map<std::string,int32_t>::iterator it;
    for(it  = table_names.begin(); it != table_names.end(); ++it)   {
        // prepare sql
        try   {
            //[name_id, name_lookup]
            stmt->BindInt(1,it->second);
            stmt->BindString(2,it->first);
            stmt->Execute();
            stmt->Reset();

            if(transaction_count > transaction_limit)   {
                stmt->FreeQuery();
                stmt->CommitTransaction();

                stmt->BeginTransaction();
                stmt->Sql(stmt_insert);
                transaction_count=0;
            }
            transaction_count++;
        }
        catch(Kompex::SQLiteException &exception)   {
            qDebug() << "ERROR: SQLite exception writing tile data:"
                     << QString::fromStdString(exception.GetString());
            qDebug() << "ERROR: name_id:" << it->second;
            qDebug() << "ERROR: name_lookup:" << QString::fromStdString(it->first);
            return false;
        }
    }

    stmt->FreeQuery();
    stmt->CommitTransaction();

    return true;
}
Beispiel #12
0
	cairo_surface_t* getImage(string path)
	{
		auto it = images.find(path);
		if (it != images.end())
			return (*it).second;

		cairo_surface_t* image = cairo_image_surface_create_from_png(path.c_str());
		images.insert(std::make_pair(path, image));
		return image;
	}
Beispiel #13
0
	operators from_name( const std::string& name){
		boost::unordered_map< std::string, operators >::const_iterator
			find_result_it = name_to_enum.find(name);
			
		if ( find_result_it != name_to_enum.end() ){
			return find_result_it->second;
		}

		throw "unexcepted enumuration name!";
	}
	Cairo::RefPtr<Cairo::ImageSurface> getIcon(string path)
	{
		auto it = stored.find(path);
		if (it != stored.end())
			return (*it).second;

		Cairo::RefPtr<Cairo::ImageSurface> image = Cairo::ImageSurface::create_from_png(path);
		stored[path] = image;
		return image;
	}
Beispiel #15
0
	std::string to_name( operators const& val ){
		boost::unordered_map< operators, std::string >::const_iterator
			find_result_it = enum_to_name.find(val);
			
		if ( find_result_it != enum_to_name.end() ){
			return find_result_it->second;
		}

		return "__unknown_enum_val__";
	}
Beispiel #16
0
void read_db_users()
{
	m_read_db_users_time = srv_time();
	if (!m_use_sql)
		return;
	try
	{
		Csql_query q(m_database, "select @uid");
		if (m_read_users_can_leech)
			q += ", can_leech";
		if (m_read_users_peers_limit)
			q += ", peers_limit";
		if (m_read_users_torrent_pass)
			q += ", torrent_pass";
		q += ", torrent_pass_version";
		if (m_read_users_wait_time)
			q += ", wait_time";
		q += " from @users";
		Csql_result result = q.execute();
		// m_users.reserve(result.size());
		for (auto& i : m_users)
			i.second.marked = true;
		m_users_torrent_passes.clear();
		while (Csql_row row = result.fetch_row())
		{
			t_user& user = m_users[row[0].i()];
			user.marked = false;
			int c = 0;
			user.uid = row[c++].i();
			if (m_read_users_can_leech)
				user.can_leech = row[c++].i();
			if (m_read_users_peers_limit)
				user.peers_limit = row[c++].i();
			if (m_read_users_torrent_pass)
			{
				if (row[c].size() == 32)
					m_users_torrent_passes[to_array<char, 32>(row[c])] = &user;
				c++;
			}
			user.torrent_pass_version = row[c++].i();
			if (m_read_users_wait_time)
				user.wait_time = row[c++].i();
		}
		for (auto i = m_users.begin(); i != m_users.end(); )
		{
			if (i->second.marked)
				m_users.erase(i++);
			else
				i++;
		}
	}
	catch (bad_query&)
	{
	}
}
    // finds a promise by ID, returns and unregisters the promise
    inline boost::promise<message_reply*>* get_promise(uint64_t promise_id) {
      boost::unordered_map<uint64_t, boost::promise<message_reply*>* >
          ::iterator iter = promises.find(promise_id);
      if (iter == promises.end()) return NULL;
      else {
        boost::promise<message_reply*>* ret = iter->second;
        promises.erase(iter);
        return ret;
      }

    }
		static void serialize(storage_type& s, const boost::unordered_map<T1, T2>& o)
			{
			uint32_t sz = o.size();
			s.serialize(sz);

			for (typename boost::unordered_map<T1,T2>::const_iterator it = o.begin(), it_end = o.end(); it != it_end; ++it)
				{
				s.serialize(it->first);
				s.serialize(it->second);
				}
			}
Beispiel #19
0
///Calculates the Gini impurity of a node. The impurity is defined as
///1-sum_j p(j|t)^2
///i.e the 1 minus the sum of the squared probability of observing class j in node t
double RFTrainer::gini(boost::unordered_map<std::size_t, std::size_t> & countMatrix, std::size_t n){
	double res = 0;
	boost::unordered_map<std::size_t, std::size_t>::iterator it;
	if(n){
		n = n*n;
		for ( it=countMatrix.begin() ; it != countMatrix.end(); it++ ){
			res += sqr(it->second)/(double)n;
		}
	}
	return 1-res;
}
Beispiel #20
0
Datei: var.cpp Projekt: hyln9/nV
var Symbol::get(wcs x) const {
    boost::unordered_map<sym, Context>::const_iterator
    iter = contexts.find(this);
    if (iter != contexts.end()) {
        Context::const_iterator
        iter2 = iter->second.find(reinterpret_cast<uint>(x));
        if (iter2 != iter->second.end())
            return iter2->second;
    }
    return null;
}
void Streamer::processPickups(Player &player, const std::vector<SharedCell> &cells)
{
	static boost::unordered_map<int, Item::SharedPickup> discoveredPickups;
	for (std::vector<SharedCell>::const_iterator c = cells.begin(); c != cells.end(); ++c)
	{
		for (boost::unordered_map<int, Item::SharedPickup>::const_iterator p = (*c)->pickups.begin(); p != (*c)->pickups.end(); ++p)
		{
			boost::unordered_map<int, Item::SharedPickup>::iterator d = discoveredPickups.find(p->first);
			if (d == discoveredPickups.end())
			{
				if (checkPlayer(p->second->players, player.playerID, p->second->interiors, player.interiorID, p->second->worlds, player.worldID))
				{
					if (boost::geometry::comparable_distance(player.position, p->second->position) <= p->second->streamDistance)
					{
						boost::unordered_map<int, int>::iterator i = internalPickups.find(p->first);
						if (i == internalPickups.end())
						{
							p->second->worldID = !p->second->worlds.empty() ? player.worldID : -1;
						}
						discoveredPickups.insert(*p);
					}
				}
			}
		}
	}
	if (processingFinalPlayer)
	{
		boost::unordered_map<int, int>::iterator i = internalPickups.begin();
		while (i != internalPickups.end())
		{
			boost::unordered_map<int, Item::SharedPickup>::iterator d = discoveredPickups.find(i->first);
			if (d == discoveredPickups.end())
			{
				DestroyPickup(i->second);
				i = internalPickups.erase(i);
			}
			else
			{
				discoveredPickups.erase(d);
				++i;
			}
		}
		for (boost::unordered_map<int, Item::SharedPickup>::iterator d = discoveredPickups.begin(); d != discoveredPickups.end(); ++d)
		{
			if (internalPickups.size() == visiblePickups)
			{
				break;
			}
			int internalID = CreatePickup(d->second->modelID, d->second->type, d->second->position[0], d->second->position[1], d->second->position[2], d->second->worldID);
			if (internalID == INVALID_ALTERNATE_ID)
			{
				break;
			}
			internalPickups.insert(std::make_pair(d->second->pickupID, internalID));
		}
		discoveredPickups.clear();
	}
}
Beispiel #22
0
inline
uint32_t
find_label(uint32_t label, boost::unordered_map<uint32_t, label_info> &labels)
{
        boost::unordered_map<uint32_t, label_info>::iterator it;

        for (it = labels.find(label); label != it->second.m_alias;) {
                label = it->second.m_alias;
                it = labels.find(label);
        }

        return label;
}
Beispiel #23
0
int TwoSum::find_range(int lower, int upper) {
    int count = 0;
    numbers_to_check.resize(upper-lower);
    for (int i=lower; i<= upper; i++ ) {
	numbers_to_check.push_back(i);
    };
    for( auto it = numbers.begin(); it != numbers.end(); ++it ) {
	if( find_sum(it->first) ) { 
	    ++count; 
	};
    };	
    return count;
};
void save(Archive & ar, const boost::unordered_map<T,U> & t, unsigned int version)
{
    // write the size
    // TODO: should we handle bucket size as well?
    typedef typename boost::unordered_map<T, U>::size_type size_type;
    typedef typename boost::unordered_map<T,U>::const_iterator const_iterator;
    size_type size = t.size();
    ar & BOOST_SERIALIZATION_NVP(size);
    unsigned int count = 0;
    for (const_iterator it = t.begin(); it != t.end(); it++) {
        ar & boost::serialization::make_nvp("pair" + count, *it);
        count++;
    }
}
void Task::drawKeypoints(const base::samples::frame::Frame &frame2,
                const std::vector<cv::KeyPoint> &keypoints1,
                const std::vector<cv::KeyPoint> &keypoints2,
                const std::vector<cv::DMatch> &matches,
                const boost::unordered_map<boost::uuids::uuid, StereoFeature> &hash)

{
    /** Convert Images to opencv **/
    cv::Mat img2 = frameHelperLeft.convertToCvMat(frame2);

    ::cv::Mat img_out(img2);
    cv::drawKeypoints (img2, keypoints1, img_out, cv::Scalar(0, 255, 0));//green previous
    for (std::vector<cv::DMatch>::const_iterator it= matches.begin(); it!= matches.end(); ++it)
    {
        cv::Point point1 = keypoints1[it->queryIdx].pt;
        cv::Point point2 = keypoints2[it->trainIdx].pt;

        //cv::circle(img_out, point1, 3, cv::Scalar(0, 255, 0), 1);// green previous
        cv::circle(img_out, point2, 3, cv::Scalar(255, 0, 0), 1);// blue current
        cv::line (img_out, point1, point2, cv::Scalar(0, 0, 255)); // red line

    }

    if (_draw_hash_uuid_features.value())
    {
        /** Draw hash features **/
        for (boost::unordered_map<boost::uuids::uuid, StereoFeature>::const_iterator
                        it = hash.begin(); it != hash.end(); ++it)
        {
            /** Only current features but with the hash id and the image frame index in the label **/
            if (it->second.img_idx == this->fcurrent_left.img_idx)
            {
                float red = 255.0 - (255.0/(this->frame_window_hash_size)*(this->ffinal_left.img_idx-it->second.img_idx));
                cv::circle(img_out, it->second.keypoint_left.pt, 5, cv::Scalar(0, 0, red), 2);
                std::vector<std::string> uuid_tokens = this->split(boost::lexical_cast<std::string>(it->first), '-');
                cv::putText(img_out, uuid_tokens[uuid_tokens.size()-1]+"["+boost::lexical_cast<std::string>(it->second.img_idx)+"]",
                        it->second.keypoint_left.pt, cv::FONT_HERSHEY_COMPLEX_SMALL, 1.0, cv::Scalar(0,0,0), 2.5);
            }
        }
    }

    ::base::samples::frame::Frame *frame_ptr = this->inter_frame_out.write_access();
    frameHelperLeft.copyMatToFrame(img_out, *frame_ptr);

    frame_ptr->time = this->frame_pair.time;
    this->inter_frame_out.reset(frame_ptr);
    _inter_frame_samples_out.write(this->inter_frame_out);

    return;
}
Beispiel #26
0
RealVector CARTTrainer::hist(boost::unordered_map<std::size_t, std::size_t> countMatrix){

	//create a normed histogram
	std::size_t totalElements = 0;
	RealVector normedHistogram(m_maxLabel+1);
	normedHistogram.clear();
	boost::unordered_map<std::size_t, std::size_t>::iterator it;
	for ( it=countMatrix.begin() ; it != countMatrix.end(); it++ ){
		normedHistogram(it->first) = it->second;
		totalElements += it->second;
	}
	normedHistogram /= totalElements;
	return normedHistogram;
}
Beispiel #27
0
static std::pair<int, int>
hit(const boost::unordered_map<int, double> &real,
    const boost::unordered_map<int, double> &fake,
    double thres = 0.0)
{
  int a = 0, b = 0;
  for (auto it = fake.cbegin(); it != fake.cend(); ++it) {
    if (it->second >= thres) {
      ++b;
      if (real.end() != real.find(it->first))
        ++a;
    }
  }
  return std::make_pair(a, b);
}
Beispiel #28
0
RealVector RFTrainer::hist(boost::unordered_map<std::size_t, std::size_t> countMatrix){

	RealVector histogram(m_maxLabel+1,0.0);

	std::size_t totalElements = 0;

	boost::unordered_map<std::size_t, std::size_t>::iterator it;
	for ( it=countMatrix.begin() ; it != countMatrix.end(); it++ ){
		histogram(it->first) = (double)it->second;
		totalElements += it->second;
	}
	histogram /= totalElements;

	return histogram;
}
void PropertyExpressionEngine::buildGraph(const ExpressionMap & exprs,
                                          boost::unordered_map<int, ObjectIdentifier> & revNodes, DiGraph & g) const
{
    boost::unordered_map<ObjectIdentifier, int> nodes;
    std::vector<Edge> edges;

    // Build data structure for graph
    for (ExpressionMap::const_iterator it = exprs.begin(); it != exprs.end(); ++it)
        buildGraphStructures(it->first, it->second.expression, nodes, revNodes, edges);

    // Create graph
    g = DiGraph(revNodes.size());

    // Add edges to graph
    for (std::vector<Edge>::const_iterator i = edges.begin(); i != edges.end(); ++i)
        add_edge(i->first, i->second, g);

    // Check for cycles
    bool has_cycle = false;
    int src = -1;
    cycle_detector vis(has_cycle, src);
    depth_first_search(g, visitor(vis));

    if (has_cycle) {
        std::string s =  revNodes[src].toString() + " reference creates a cyclic dependency.";

        throw Base::Exception(s.c_str());
    }
}
void load(Archive & ar, boost::unordered_map<T,U> & t, unsigned int version)
{
    // clear the map
    t.clear();
    // read the size
    typedef typename boost::unordered_map<T,U>::size_type size_type;
    size_type size;
    ar & BOOST_SERIALIZATION_NVP(size);
    for (size_type i = 0; i < size; i++) {
        // read a pair
        std::pair<T, U> pair;
        ar & boost::serialization::make_nvp("pair"+i, pair);
        // insert it into the map
        t.insert(pair);
    }
}