Exemple #1
0
 bool balanceBTree(CogHandle<Tuple> h)
   {
     auto cog = h->get();
     
     if(cog->type == COG_BTREE){
       auto bcog = (BTreeCog<Tuple> *)cog.get();
       auto lhs = bcog->lhs->get();
       auto rhs = bcog->rhs->get();
       
       int lhs_size = lhs->size();
       int rhs_size = rhs->size();
       
       int diff = lhs_size > rhs_size ? lhs_size-rhs_size : rhs_size-lhs_size;
       if(diff < DEFAULT_BTREE_BALANCE_ABS_DIFF) 
         { return false; }
       if(diff * 100 < DEFAULT_BTREE_BALANCE_PCT_DIFF * (lhs_size + rhs_size))
         { return false; }
       
       if(lhs->type == COG_BTREE){
         auto blhs = (BTreeCog<Tuple> *)lhs.get();
         if(blhs->lhs->size() > rhs_size){
           h->put(CogPtr<Tuple>(new BTreeCog<Tuple>(
             blhs->lhs,
             makeHandle(CogPtr<Tuple>(new BTreeCog<Tuple>(
               blhs->rhs,
               bcog->rhs,
               bcog->sep
             ))),
             blhs->sep
           )));
           return true;
         }
       }
       if(rhs->type == COG_BTREE){
         auto brhs = (BTreeCog<Tuple> *)rhs.get();
         if(brhs->rhs->size() > lhs_size){
           h->put(CogPtr<Tuple>(new BTreeCog<Tuple>(
             makeHandle(CogPtr<Tuple>(new BTreeCog<Tuple>(
               bcog->lhs,
               brhs->lhs,
               bcog->sep
             ))),
             brhs->rhs,
             brhs->sep
           )));
           return true;
         }
       }
     }
     return false;
   }
Exemple #2
0
TInt CFsObjectIx::At(const CFsObject* anObj,TBool aLock)
//
// Return the handle from an object.
//
	{
	if(aLock)
		Lock();
	if (iHighWaterMark)
		{
		SFsObjectIxRec* pS=iObjects;
		SFsObjectIxRec* pE=pS+iHighWaterMark;
		TInt i=0;
		while(pS<pE && pS->obj!=anObj)
			pS++, i++;
		if (pS<pE)
			{
			TInt h=makeHandle(i,pS->instance);
			if(aLock)
				Unlock();	
			return(h);	
			}
		}
	if(aLock)
		Unlock();
	return KErrNotFound;
	}
Exemple #3
0
void Rocket::setTarget(WorldObject* targetObject) {
    if (targetObject) {
        m_targetHandle = makeHandle(targetObject);
        m_aiTask.reset(new DirectSuicideTask(&m_boardComputer, targetObject));
    } else {
        m_targetHandle = Handle<WorldObject>();
        m_aiTask.reset(nullptr);
    }
}
Exemple #4
0
QString QLocalServerThread::setName(const QString &name)
{
    QString pipePath = QLatin1String("\\\\.\\pipe\\");
    if (name.startsWith(pipePath))
        fullServerName = name;
    else
        fullServerName = pipePath + name;
    for (int i = pendingHandles.count(); i < maxPendingConnections; ++i)
        if (!makeHandle())
            break;
    return fullServerName;
}
Exemple #5
0
static Pothos::ProxyVector convertJObjectArrayToVector(const Pothos::Proxy &proxy)
{
    auto handle = std::dynamic_pointer_cast<JavaProxyHandle>(proxy.getHandle());
    auto jenv = std::dynamic_pointer_cast<JavaProxyEnvironment>(proxy.getEnvironment());

    auto ar = (jobjectArray) handle->value.l;
    Pothos::ProxyVector vec(jenv->env->GetArrayLength(ar));
    for (size_t i = 0; i < vec.size(); i++)
    {
        vec[i] = jenv->makeHandle(jenv->env->GetObjectArrayElement(ar, i));
    }
    return vec;
}
Exemple #6
0
TInt CFsObjectIx::AddL(CFsObject* anObj,TBool aLock)
//
// Add a new object to the index.
//
	{
	if(aLock)
		Lock();
	SFsObjectIxRec *pS=iObjects;
	SFsObjectIxRec *pE=pS+iHighWaterMark;
	TInt i=0;
	TInt inc=0;
	while(pS<pE && pS->obj)
		pS++, i++;
	if (pS==pE)
		inc=1;
	if (pS==pE && iAllocated==iHighWaterMark)
		{
		// no slots free, so reallocate array
		if (iHighWaterMark==KObjectIxMaxHandles)
			{
			if(aLock)
				Unlock();
			User::LeaveNoMemory();
			}
		TInt newAlloc=iAllocated + KObjectIxGranularity;
		SFsObjectIxRec* pA=(SFsObjectIxRec*)User::ReAlloc(iObjects, newAlloc*sizeof(SFsObjectIxRec));
		if(!pA)
			{
			if(aLock)
				Unlock();
			User::Leave(KErrNoMemory);
			}
		iObjects=pA;
		iAllocated=newAlloc;
		i=iHighWaterMark;
		pS=pA+i;
		}
	pS->obj=anObj;
	pS->uniqueID=(TUint16)anObj->UniqueID();
	pS->instance=(TUint16)instanceLimit(iNextInstance);
	iNextInstance++;
	iHighWaterMark+=inc;
	++iNumEntries;
	TInt h=makeHandle(i,pS->instance);
	if(aLock)
		Unlock();
	return(h);
	}
Exemple #7
0
/***********************************************************************
 * String
 **********************************************************************/
static Pothos::Proxy convertStringToJString(Pothos::ProxyEnvironment::Sptr env, const std::string &s)
{
    auto jenv = std::dynamic_pointer_cast<JavaProxyEnvironment>(env);
    return jenv->makeHandle(jenv->env->NewStringUTF(s.c_str()));
}
void CameraFollowHelper::setTarget(WorldObject* target) {
    m_target = makeHandle(target);
}
AiTaskFinishedPoll::AiTaskFinishedPoll(AiTask* aitask, const Callback& callback):
    EventPoll(callback),
    m_aiTask(makeHandle(aitask))
{
}