Ejemplo n.º 1
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();
};
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();
	}
}
Ejemplo n.º 3
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;
}
bool LLNetMap::mmenableunmark::handleEvent(LLPointer<LLEvent> event, const LLSD& userdata)
{
	LLNetMap *self = mPtr;
	BOOL enabled = mPtr->mClosestAgentAtLastRightClick.notNull() && mm_MarkerColors.find(mPtr->mClosestAgentAtLastRightClick) != mm_MarkerColors.end();
	self->findControl(userdata["control"].asString())->setValue(enabled);
	return true;
}
Ejemplo n.º 5
0
Archivo: var.cpp Proyecto: 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;
}
Ejemplo n.º 6
0
 size_t count(std::string const& x) const {
     auto iter = counts.find(x);
     if (iter != counts.end()) {
         return iter->second;
     }
     return 0;
 }
Ejemplo n.º 7
0
inline bool lru_cache_cab::ins_rec(const bucket * buck, const double & curT, bool newFlow)
{
    const container_T::left_iterator iter = cache.left.find(buck);

    if (iter == cache.left.end())   // cache miss
    {
        insert(buck, curT);

        if (newFlow)
        {
            ++delay_rec[20];
        }
        ++cache_miss;
        return true;
    }
    else     // cache hit
    {
        cache.right.relocate(cache.right.end(),
                             cache.project_right(iter));
        iter->second = curT;
        double delay = curT-buffer_check.find(buck)->second;

        if (newFlow)
        {
            ++reuse_count;
            if(delay < rtt)
            {
                assert (delay >= 0);
                ++delay_rec[int(20*(rtt-delay)/rtt)];
            }
        }
        return false;
    }
}
Ejemplo n.º 8
0
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)));
    }
}
Ejemplo n.º 9
0
bool TwoSum::find_sum(long int target) {
    long int bucket;
    for( auto it = numbers_to_check.begin(); it != numbers_to_check.end(); it++ ) {
	if( numbers.find((*it) - target) == numbers.end() ) { continue; };
	bucket = numbers.bucket( (*it) - target );
	for(auto it_local = numbers.begin(bucket); it_local != numbers.end(bucket); ++it_local) {
	    if ( ( it_local->first + target ) != (*it) ) { continue; }; 
	    if ( it_local->first != target || (it_local->first == target && multi_numbers.find(target) != multi_numbers.end()) ) {
		std::cout << target << " + " << it_local->first << " = " << (*it) << " ( " << target + it_local->first << std::endl;
		numbers_to_check.erase(it);
		return true; 
	    };
	};
    };
    return false;
};
Ejemplo n.º 10
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;
	}
Ejemplo n.º 11
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__";
	}
Ejemplo n.º 12
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!";
	}
Ejemplo n.º 13
0
	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;
	}
Ejemplo n.º 14
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;
	}
Ejemplo n.º 15
0
Archivo: var.cpp Proyecto: 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;
}
Ejemplo n.º 16
0
    // 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;
      }

    }
Ejemplo n.º 17
0
// Makes sure that no three points all on an original tile edge
// are triangulated.
bool is_legal(const Point_3& a, const Point_3& b, const Point_3& c,
	      const boost::unordered_map<Point_3, boost::unordered_set<Segment_3_undirected> >& point2edges)
{
  static log4cplus::Logger logger = log4cplus::Logger::getInstance("polygon_utils.is_legal");

  LOG4CPLUS_TRACE(logger, "is_legal: " << pp(a) << " " << pp(b) << " " << pp(c));

  if (point2edges.find(a) == point2edges.end())
    return true;
  if (point2edges.find(b) == point2edges.end())
    return true;
  if (point2edges.find(c) == point2edges.end())
    return true;

  const boost::unordered_set<Segment_3_undirected>& edgesa = point2edges.find(a)->second;
  const boost::unordered_set<Segment_3_undirected>& edgesb = point2edges.find(b)->second;
  const boost::unordered_set<Segment_3_undirected>& edgesc = point2edges.find(c)->second;

  boost::unordered_set<Segment_3_undirected> edges(set_intersection(edgesa, set_intersection(edgesb, edgesc)));
  return edges.empty();
}
Ejemplo n.º 18
0
void PropertyExpressionEngine::buildGraphStructures(const ObjectIdentifier & path,
                                                    const boost::shared_ptr<Expression> expression,
                                                    boost::unordered_map<ObjectIdentifier, int> & nodes,
                                                    boost::unordered_map<int, ObjectIdentifier> & revNodes,
                                                    std::vector<Edge> & edges) const
{
    std::set<ObjectIdentifier> deps;

    /* Insert target property into nodes structure */
    if (nodes.find(path) == nodes.end()) {
        int s = nodes.size();

        revNodes[s] = path;
        nodes[path] = s;
    }
    else
        revNodes[nodes[path]] = path;

    /* Get the dependencies for this expression */
    expression->getDeps(deps);

    /* Insert dependencies into nodes structure */
    std::set<ObjectIdentifier>::const_iterator di = deps.begin();
    while (di != deps.end()) {
        Property * prop = di->getProperty();

        if (prop) {
            ObjectIdentifier cPath(di->canonicalPath());

            if (nodes.find(cPath) == nodes.end()) {
                int s = nodes.size();

                nodes[cPath] = s;
            }

            edges.push_back(std::make_pair(nodes[path], nodes[cPath]));
        }
        ++di;
    }
}
IncrementalScoringFunction::Data IncrementalScoringFunction::create_data(
    ParticleIndex pi, RestraintsTemp cr,
    const boost::unordered_map<Restraint *, int> &all,
    const Restraints &dummies) const {
  IMP_LOG_TERSE("Dependent restraints for particle "
                << get_model()->get_particle_name(pi) << " are " << cr
                << std::endl);
  Data ret;
  for (unsigned int j = 0; j < cr.size(); ++j) {
    if (all.find(cr[j]) != all.end()) {
      int index = all.find(cr[j])->second;
      IMP_INTERNAL_CHECK(
          std::find(ret.indexes.begin(), ret.indexes.end(), index) ==
              ret.indexes.end(),
          "Found duplicate restraint " << Showable(cr[j]) << " in list " << cr);
      ret.indexes.push_back(index);
    }
  }
  cr += RestraintsTemp(dummies.begin(), dummies.end());
  ret.sf = new IncrementalRestraintsScoringFunction(
      cr, 1.0, NO_MAX, get_model()->get_particle_name(pi) + " restraints");
  return ret;
}
Ejemplo n.º 20
0
double get_volume_from_residue_type(ResidueType rt) {
  typedef std::pair<ResidueType, double> RP;
  static const RP radii[] = {
      RP(ResidueType("ALA"), 2.516), RP(ResidueType("ARG"), 3.244),
      RP(ResidueType("ASN"), 2.887), RP(ResidueType("ASP"), 2.866),
      RP(ResidueType("CYS"), 2.710), RP(ResidueType("GLN"), 3.008),
      RP(ResidueType("GLU"), 2.997), RP(ResidueType("GLY"), 2.273),
      RP(ResidueType("HIS"), 3.051), RP(ResidueType("ILE"), 3.047),
      RP(ResidueType("LEU"), 3.052), RP(ResidueType("LYS"), 3.047),
      RP(ResidueType("MET"), 3.068), RP(ResidueType("PHE"), 3.259),
      RP(ResidueType("PRO"), 2.780), RP(ResidueType("SER"), 2.609),
      RP(ResidueType("THR"), 2.799), RP(ResidueType("TRP"), 3.456),
      RP(ResidueType("TYR"), 3.318), RP(ResidueType("VAL"), 2.888)};
  static const boost::unordered_map<ResidueType, double> radii_map(
      radii, radii + sizeof(radii) / sizeof(RP));
  if (radii_map.find(rt) == radii_map.end()) {
    IMP_THROW("Can't approximate volume of non-standard residue " << rt,
              ValueException);
  }
  double r = radii_map.find(rt)->second;
  IMP_INTERNAL_CHECK(r > 0, "Read garbage r for " << rt);
  return algebra::get_volume(
      algebra::Sphere3D(algebra::get_zero_vector_d<3>(), r));
}
Ejemplo n.º 21
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);
}
Ejemplo n.º 22
0
static CStrInternInternals* GetString(const char* str, size_t len)
{
	// g_Strings is not thread-safe, so complain if anyone is using this
	// type in non-main threads. (If that's desired, g_Strings should be changed
	// to be thread-safe, preferably without sacrificing performance.)
	ENSURE(ThreadUtil::IsMainThread());

#if BOOST_VERSION >= 104200
	StringsKeyProxy proxy = { str, len };
	boost::unordered_map<StringsKey, shared_ptr<CStrInternInternals> >::iterator it =
		g_Strings.find(proxy, StringsKeyProxyHash(), StringsKeyProxyEq());
#else
	// Boost <= 1.41 doesn't support the new find(), so do a slightly less efficient lookup
	boost::unordered_map<StringsKey, shared_ptr<CStrInternInternals> >::iterator it =
		g_Strings.find(str);
#endif

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

	shared_ptr<CStrInternInternals> internals(new CStrInternInternals(str, len));
	g_Strings.insert(std::make_pair(internals->data, internals));
	return internals.get();
}
Ejemplo n.º 23
0
double V_F(const int& n, const int& fullObs_cumulativeTime, const int& fullObs_cumulativeQuantity)
{
    double v_max;
    
    if (n==N+1)
        v_max = 0;    //V_{N+1}()=0
    else
    {
        auto parameters = make_tuple(n, fullObs_cumulativeTime, fullObs_cumulativeQuantity);
        
        bool found = false;
        //#pragma omp critical (v_map)
        {
            auto  it = v_map.find(parameters);
            if (it != v_map.end()) {
                found = true;
                v_max = it->second;
            }
        }
        
        
        if (!found)
        {
            
            //no need to search for optimal inventory level x, the myopic inventory level is optimal
            int x_opt = find_x_myopic(fullObs_cumulativeTime, fullObs_cumulativeQuantity);
            
            v_max = G_F(n, x_opt, fullObs_cumulativeTime, fullObs_cumulativeQuantity);
            
            
            if (n==1)
            {
                cout << x_opt << "\t" << v_max  << "\t";
                file << x_opt << "\t" << v_max  << "\t";
            }
            
            
            //#pragma omp critical (v_map)
            { v_map.emplace(parameters, v_max); }
            
        }
        
    }
    
    return v_max;
}
Ejemplo n.º 24
0
void State::throw_on_illegal_move(const PlayerMove& pm,
                                  boost::unordered_map<Player, boost::unordered_set<Move> >& legals) const
{
    typedef boost::unordered_map<Player, boost::unordered_set<Move> > tmp_t;
    const Player& p = pm.first;
    const Move& m = pm.second;

    tmp_t::const_iterator itp(legals.find(p));
    if (itp == legals.end())
    {
        throw HSFCValueError() << ErrorMsgInfo("Illegal PlayerMove: unknown player");
    }
    boost::unordered_set<Move>::const_iterator itm(itp->second.find(m));
    if (itm == itp->second.end())
    {
        throw HSFCValueError() << ErrorMsgInfo("Illegal PlayerMove: unknown move");
    }
}
Ejemplo n.º 25
0
/***********************************************************************
 * Internal format to return the legals in a structure that is easy
 * to check if some move is legal.
 ***********************************************************************/
void State::get_legals(boost::unordered_map<Player, boost::unordered_set<Move> >& result) const
{
    typedef boost::unordered_map<Player, boost::unordered_set<Move> > tmp_t;

    result.clear();
    std::vector<PlayerMove> legalMoves;
    legals(std::back_inserter(legalMoves));

    for(std::vector<PlayerMove>::iterator pm = legalMoves.begin(); pm != legalMoves.end(); pm++) {
        tmp_t::iterator iter_moves(result.find(pm->first));
        if(iter_moves == result.end()) {
            std::pair<tmp_t::iterator, bool> ok = result.emplace(pm->first, boost::unordered_set<Move>());
            ok.first->second.emplace(pm->second);
        } else {
            iter_moves->second.emplace(pm->second);
        }
    }
}
Ejemplo n.º 26
0
	void styleNodes(const shared_ptr<std::vector<NodeId> >& ids, RenderAttributes& attr) const
	{
		for (auto id : *ids)
		{
			Node* n = data->getNode(id);
			auto& tags = n->getTags();

			auto name = tags.find(CachedString("name"));
			if (name != tags.end())
			{
				auto style = styles.find(name->second);
				if (style != styles.end()) {
					Style* s = attr.getNewStyle(id);
					*s = style->second;
				}
			}
		}
	}
bool PhraseOrientation::SpanIsAligned(int index1, int index2, const boost::unordered_map< std::pair<int,int> , std::pair<int,int> > &minAndMaxAligned) const
{
  boost::unordered_map< std::pair<int,int> , std::pair<int,int> >::const_iterator itMinAndMaxAligned = 
    minAndMaxAligned.find(std::pair<int,int>(std::min(index1,index2),std::max(index1,index2)));

  if (itMinAndMaxAligned == minAndMaxAligned.end())
  {
    std::cerr << "PhraseOrientation::SourceSpanIsAligned(): Error" << std::endl;
    std::exit(1);
  }
  else
  {
    if (itMinAndMaxAligned->second.first == std::numeric_limits<int>::max()) 
    {
      return false;
    }
  }
  return true;
}
Ejemplo n.º 28
0
void TwoSum::read(const char * fn) {
    std::ifstream inf (fn);
    std::string line;
    long int n;
    int count = 0;
    while (std::getline(inf, line)) {
	count++;
    };
    numbers.reserve(count);
    count = 0;
    inf.clear();
    inf.seekg(0);
    while (std::getline(inf, line)) {
	n = read_line(line);
	if( numbers.find(n) == numbers.end() ) {
	    numbers[n] = n;
	} else {
	    multi_numbers[n] = true; 
	};
	count++;
    };
};
Ejemplo n.º 29
0
std::string RippleAddress::humanAccountID () const
{
    switch (nVersion)
    {
    case VER_NONE:
        throw std::runtime_error ("unset source - humanAccountID");

    case VER_ACCOUNT_ID:
    {
        StaticScopedLockType sl (s_lock, __FILE__, __LINE__);
        boost::unordered_map< Blob , std::string >::iterator it = rncMap.find (vchData);

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

        // VFALCO NOTE Why do we throw everything out? We could keep two maps
        //             here, switch back and forth keep one of them full and clear the
        //             other on a swap - but always check both maps for cache hits.
        //
        if (rncMap.size () > 250000)
            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)));
    }
}
Ejemplo n.º 30
0
HashRouter::Entry& HashRouter::findCreateEntry (uint256 const& index, bool& created)
{
    boost::unordered_map<uint256, Entry>::iterator fit = mSuppressionMap.find (index);

    if (fit != mSuppressionMap.end ())
    {
        created = false;
        return fit->second;
    }

    created = true;

    int now = UptimeTimer::getInstance ().getElapsedSeconds ();
    int expireTime = now - mHoldTime;

    // See if any supressions need to be expired
    std::map< int, std::list<uint256> >::iterator it = mSuppressionTimes.begin ();

    if ((it != mSuppressionTimes.end ()) && (it->first <= expireTime))
    {
        BOOST_FOREACH (uint256 const & lit, it->second)
        mSuppressionMap.erase (lit);
        mSuppressionTimes.erase (it);
    }