PNS_NODE::~PNS_NODE()
{
    TRACE( 0, "PNS_NODE::delete %p", this );

    if( !m_children.empty() )
    {
        TRACEn( 0, "attempting to free a node that has kids.\n" );
        assert( false );
    }

#ifdef DEBUG
    if( allocNodes.find( this ) == allocNodes.end() )
    {
        TRACEn( 0, "attempting to free an already-free'd node.\n" );
        assert( false );
    }

    allocNodes.erase( this );
#endif

    for( PNS_INDEX::ITEM_SET::iterator i = m_index->begin(); i != m_index->end(); ++i )
    {
        if( (*i)->BelongsTo( this ) )
            delete *i;
    }


    releaseGarbage();
    unlinkParent();

    delete m_index;
}
Esempio n. 2
0
void VNode::collect_vnodes(boost::unordered_set<Node*>& nodes,uint& total)
{
	total++;
	boost::unordered_set<Node*>::iterator it = nodes.find(this);
	if(it==nodes.end())
		nodes.insert(this);
}
Esempio n. 3
0
void cluster_machine::dfs(const size_t curr, boost::unordered_set<size_t> &vis)
{
    vis.insert(curr);
    for (size_t e = first_[curr]; e != -1; e = next_[e]) {
        if ( vis.find(v_[e]) == vis.end() )
            dfs(v_[e], vis);
    }
}
Esempio n. 4
0
		void update(const key_type& inKey, const boost::unordered_set<value_type>& inValues)
			{
				{
				boost::unordered_set<value_type> curValues(getValues(inKey));
				for (auto it = curValues.begin(); it != curValues.end(); ++it)
					if (inValues.find(*it) == inValues.end())
						drop(inKey, *it);
				}

			insert(inKey, inValues);
			}
Esempio n. 5
0
static bool collectShortcuts(const std::string & str, StringVector & vs) 
{
	static boost::unordered_set<std::string> commonFilters;
	if(commonFilters.empty()) {
#if RULE_KEY_HASH_LENGTH==7 // 7
		commonFilters.insert("http://");
		commonFilters.insert("ttp://w");
		commonFilters.insert("tp://ww");
		commonFilters.insert("p://www");
		commonFilters.insert("://www.");
#elif RULE_KEY_HASH_LENGTH==8 // 8
		commonFilters.insert("http://w");
		commonFilters.insert("ttp://ww");
		commonFilters.insert("tp://www");
		commonFilters.insert("p://www.");
#elif RULE_KEY_HASH_LENGTH==9 // 9
		commonFilters.insert("http://ww");
		commonFilters.insert("ttp://www");
		commonFilters.insert("tp://www.");
#endif
	}

	int i = 0;
	bool isFindShoutcut = false;
	while (i < abpmin(str.length() - RULE_KEY_HASH_LENGTH,80)) 
	{
		unsigned int j = i;
		for (; j < str.length(); j++) {
			if ((str[j] == '*' || str[j] == '^'))
			{
				break;
			}
		}
		for (unsigned int k = i; j - k >= RULE_KEY_HASH_LENGTH; k++) 
		{
			std::string key = str.substr(k, RULE_KEY_HASH_LENGTH);
			if(commonFilters.find(key)!=commonFilters.end())
				continue;
			isFindShoutcut = true;
			vs.push_back(key); //append(key);
		}
		i = j + 1;
	}
	return isFindShoutcut;
}
Esempio n. 6
0
int PNS_NODE::QueryColliding( const PNS_ITEM* aItem,
        PNS_NODE::Obstacles& aObstacles, int aKindMask, int aLimitCount )
{
    obstacleVisitor visitor( aObstacles, aItem, aKindMask );

    assert( allocNodes.find( this ) != allocNodes.end() );

    visitor.SetCountLimit( aLimitCount );
    visitor.SetWorld( this, NULL );

    // first, look for colliding items ourselves
    m_index->Query( aItem, m_maxClearance, visitor );

    // if we haven't found enough items, look in the root branch as well.
    if( !isRoot() && ( visitor.m_matchCount < aLimitCount || aLimitCount < 0) )
    {
        visitor.SetWorld( m_root, this );
        m_root->m_index->Query( aItem, m_maxClearance, visitor );
    }

    return aObstacles.size();
}
Esempio n. 7
0
    bool isLocalSipUri( const string& requestUri ) {

        static bool initialized = false ;
        static boost::unordered_set<string> setLocalUris ;

        if( !initialized ) {
            initialized = true ;

            nta_agent_t* agent = theOneAndOnlyController->getAgent() ;
            tport_t *t = nta_agent_tports( agent ) ;
            for (tport_t* tport = t; tport; tport = tport_next(tport) ) {
                const tp_name_t* tpn = tport_name( tport );
                if( 0 == strcmp( tpn->tpn_host, "*") ) 
                    continue ;

                string localUri = tpn->tpn_host ;
                localUri += ":" ;
                localUri += (tpn->tpn_port ? tpn->tpn_port : "5060");

                setLocalUris.insert( localUri ) ;

                if( 0 == strcmp(tpn->tpn_host,"127.0.0.1") ) {
                    localUri = "localhost:" ;
                    localUri += (tpn->tpn_port ? tpn->tpn_port : "5060");
                    setLocalUris.insert( localUri ) ;
                }
            }
       }

        url_t *url = url_make(theOneAndOnlyController->getHome(), requestUri.c_str() ) ;
        string uri = url->url_host ;
        uri += ":" ;
        uri += ( url->url_port ? url->url_port : "5060") ;

        return setLocalUris.end() != setLocalUris.find( uri ) ;
    }
Esempio n. 8
0
PNS_NODE::~PNS_NODE()
{
    if( !m_children.empty() )
    {
        TRACEn( 0, "attempting to free a node that has kids.\n" );
        assert( false );
    }

    if( allocNodes.find( this ) == allocNodes.end() )
    {
        TRACEn( 0, "attempting to free an already-free'd node.\n" );
        assert( false );
    }

    allocNodes.erase( this );

    for( PNS_INDEX::ItemSet::iterator i = m_index->begin();
         i != m_index->end(); ++i )
        if( (*i)->BelongsTo( this ) )
            delete *i;

    unlinkParent();
    delete m_index;
}
Esempio n. 9
0
void Grid::processDiscoveredCells(Player &player, std::vector<SharedCell> &playerCells, const boost::unordered_set<CellID> &discoveredCells)
{
    playerCells.push_back(SharedCell(new Cell()));;
    if (player.enabledItems[STREAMER_TYPE_OBJECT])
    {
        boost::unordered_map<int, Item::SharedObject>::iterator o = player.visibleCell->objects.begin();
        while (o != player.visibleCell->objects.end())
        {
            boost::unordered_set<CellID>::iterator d = discoveredCells.find(o->second->cell->cellID);
            if (d != discoveredCells.end())
            {
                o = player.visibleCell->objects.erase(o);
            }
            else
            {
                ++o;
            }
        }
        playerCells.back()->objects.swap(player.visibleCell->objects);
    }
    if (player.enabledItems[STREAMER_TYPE_CP])
    {
        boost::unordered_map<int, Item::SharedCheckpoint>::iterator c = player.visibleCell->checkpoints.begin();
        while (c != player.visibleCell->checkpoints.end())
        {
            boost::unordered_set<CellID>::iterator d = discoveredCells.find(c->second->cell->cellID);
            if (d != discoveredCells.end())
            {
                c = player.visibleCell->checkpoints.erase(c);
            }
            else
            {
                ++c;
            }
        }
        playerCells.back()->checkpoints.swap(player.visibleCell->checkpoints);
    }
    if (player.enabledItems[STREAMER_TYPE_RACE_CP])
    {
        boost::unordered_map<int, Item::SharedRaceCheckpoint>::iterator t = player.visibleCell->raceCheckpoints.begin();
        while (t != player.visibleCell->raceCheckpoints.end())
        {
            boost::unordered_set<CellID>::iterator d = discoveredCells.find(t->second->cell->cellID);
            if (d != discoveredCells.end())
            {
                t = player.visibleCell->raceCheckpoints.erase(t);
            }
            else
            {
                ++t;
            }
        }
        playerCells.back()->raceCheckpoints.swap(player.visibleCell->raceCheckpoints);
    }
    if (player.enabledItems[STREAMER_TYPE_MAP_ICON])
    {
        boost::unordered_map<int, Item::SharedMapIcon>::iterator m = player.visibleCell->mapIcons.begin();
        while (m != player.visibleCell->mapIcons.end())
        {
            boost::unordered_set<CellID>::iterator d = discoveredCells.find(m->second->cell->cellID);
            if (d != discoveredCells.end())
            {
                m = player.visibleCell->mapIcons.erase(m);
            }
            else
            {
                ++m;
            }
        }
        playerCells.back()->mapIcons.swap(player.visibleCell->mapIcons);
    }
    if (player.enabledItems[STREAMER_TYPE_3D_TEXT_LABEL])
    {
        boost::unordered_map<int, Item::SharedTextLabel>::iterator t = player.visibleCell->textLabels.begin();
        while (t != player.visibleCell->textLabels.end())
        {
            boost::unordered_set<CellID>::iterator d = discoveredCells.find(t->second->cell->cellID);
            if (d != discoveredCells.end())
            {
                t = player.visibleCell->textLabels.erase(t);
            }
            else
            {
                ++t;
            }
        }
        playerCells.back()->textLabels.swap(player.visibleCell->textLabels);
    }
    if (player.enabledItems[STREAMER_TYPE_AREA])
    {
        boost::unordered_map<int, Item::SharedArea>::iterator a = player.visibleCell->areas.begin();
        while (a != player.visibleCell->areas.end())
        {
            boost::unordered_set<CellID>::iterator d = discoveredCells.find(a->second->cell->cellID);
            if (d != discoveredCells.end())
            {
                a = player.visibleCell->areas.erase(a);
            }
            else
            {
                ++a;
            }
        }
        playerCells.back()->areas.swap(player.visibleCell->areas);
    }
}
Esempio n. 10
0
void Object::remove_live_object(Object* o) {
  IMP_INTERNAL_CHECK(live_.find(o) != live_.end(),
                     "Object " << o->get_name() << " not found in live list.");
  live_.erase(o);
}
Esempio n. 11
0
// Make sure an offer is still valid. If not, mark it unfunded.
bool OfferCreateTransactor::bValidOffer (
    SLE::ref            sleOfferDir,
    uint256 const&      uOfferIndex,
    const uint160&      uOfferOwnerID,
    const STAmount&     saOfferPays,
    const STAmount&     saOfferGets,
    const uint160&      uTakerAccountID,
    boost::unordered_set<uint256>&  usOfferUnfundedFound,
    boost::unordered_set<uint256>&  usOfferUnfundedBecame,
    boost::unordered_set<uint160>&  usAccountTouched,
    STAmount&           saOfferFunds)                       // <--
{
    bool    bValid;

    if (sleOfferDir->isFieldPresent (sfExpiration) && sleOfferDir->getFieldU32 (sfExpiration) <= mEngine->getLedger ()->getParentCloseTimeNC ())
    {
        // Offer is expired. Expired offers are considered unfunded. Delete it.
        WriteLog (lsINFO, OfferCreateTransactor) << "bValidOffer: encountered expired offer";

        usOfferUnfundedFound.insert (uOfferIndex);

        bValid  = false;
    }
    else if (uOfferOwnerID == uTakerAccountID)
    {
        // Would take own offer. Consider old offer expired. Delete it.
        WriteLog (lsINFO, OfferCreateTransactor) << "bValidOffer: encountered taker's own old offer";

        usOfferUnfundedFound.insert (uOfferIndex);

        bValid  = false;
    }
    else if (!saOfferGets.isPositive () || !saOfferPays.isPositive ())
    {
        // Offer has bad amounts. Consider offer expired. Delete it.
        WriteLog (lsWARNING, OfferCreateTransactor) << boost::str (boost::format ("bValidOffer: BAD OFFER: saOfferPays=%s saOfferGets=%s")
                % saOfferPays % saOfferGets);

        usOfferUnfundedFound.insert (uOfferIndex);
    }
    else
    {
        WriteLog (lsTRACE, OfferCreateTransactor) << "bValidOffer: saOfferPays=" << saOfferPays.getFullText ();

        saOfferFunds    = mEngine->getNodes ().accountFunds (uOfferOwnerID, saOfferPays);

        if (!saOfferFunds.isPositive ())
        {
            // Offer is unfunded, possibly due to previous balance action.
            WriteLog (lsDEBUG, OfferCreateTransactor) << "bValidOffer: offer unfunded: delete";

            boost::unordered_set<uint160>::iterator account = usAccountTouched.find (uOfferOwnerID);

            if (account != usAccountTouched.end ())
            {
                // Previously touched account.
                usOfferUnfundedBecame.insert (uOfferIndex); // Delete unfunded offer on success.
            }
            else
            {
                // Never touched source account.
                usOfferUnfundedFound.insert (uOfferIndex);  // Delete found unfunded offer when possible.
            }

            bValid  = false;
        }
        else
        {
            bValid  = true;
        }
    }

    return bValid;
}
Esempio n. 12
0
bool set_contains(const boost::unordered_set<K,H,C,A>& s, const T& x) {
    return s.find(x) != s.end();
}