示例#1
0
		Sampler(const std::vector<TypeReaction>& reactions, const std::vector<ProbTable>& xs_container, bool normalize = true) :
            nreaction(reactions.size()),
            nenergy(getArraySize(*xs_container.begin())),
            reactions(reactions) {

			/* Allocate reaction matrix */
			reaction_matrix = new double[(nreaction - 1) * nenergy];

			/* Sanity check */
			assert(xs_container.size() == reactions.size());

			/* Once we separate the reactions from the cross sections, we need to construct the reaction matrix */
			for(int nerg = 0 ; nerg < nenergy ; ++nerg) {

				/* Check if we have to normalize the probabilities */
				double total_xs = 0.0;
				if(normalize) {
					/* First get the total cross section (of this reactions) at this energy */
					for(int nrea = 0 ; nrea < nreaction ; ++nrea)
						total_xs += getArrayIndex(nerg,xs_container[nrea]);
				}

				/* Exclusive scan, to construct the accumulated probability table at this energy */
				double partial_sum = 0;
				for(int nrea = 0 ; nrea < nreaction - 1; ++nrea) {
					partial_sum += getArrayIndex(nerg,xs_container[nrea]);
					/* Put the value on the reaction matrix */
					if(normalize)
						reaction_matrix[nerg*(nreaction - 1) + nrea] = partial_sum / total_xs;
					else
						reaction_matrix[nerg*(nreaction - 1) + nrea] = partial_sum;
				}

			}
		}
示例#2
0
	/* Convenience method */
ostream &
_TDL_TreeNodeBranch::printArrayIndexes ( ostream & theOstream ) const
{
  if ( getParent() != (_TDL_TreeNodeBranch *) NULL )
    getParent() -> printArrayIndexes( theOstream );
  if ( getArrayIndex() == _TDL_TreeNode::TOPMOST_ARRAY_INDEX )
    theOstream << ". ";    
  else
    theOstream << getArrayIndex() << " ";
  return theOstream;
}
示例#3
0
void StarContainer::loadGame()
{
	openList->clear();
	closeList->clear();

	for ( int i = 0 ; i < ROLE_NUM ; i++ )
	{
		for ( int j = 0 ;j < ROLE_NUM ; j++ )
		{
			CCString* str = CCString::createWithFormat("%d_index",getArrayIndex( i , j ) );
			int index = CCUserDefault::sharedUserDefault()->getIntegerForKey( str->getCString());
			if(index <= 0 || index >5)
			{
				m_pStars[i][j] = NULL;
				continue;
			}
			m_pStars[i][j] = new Star( index );
			CCSprite* sprite = m_pStars[i][j]->GetAvata();
			CCMoveTo* moveTo = CCMoveTo::create( 0.7f , m_pStars[i][j]->getPosition( i , j ));
			CCEaseBounceOut* easeOut = CCEaseBounceOut::create(moveTo);
			CCCallFunc* callFunc = CCCallFunc::create(this,callfunc_selector(StarContainer::PlayStartAnimOver));
			CCActionInterval* intervalAction = CCSequence::create( easeOut , callFunc , NULL );
			sprite->runAction(intervalAction);

			GameMap::GetInstance()->getSpriteBatchBode()->addChild(sprite);

			
		}
	}

	SavePreStep();
}
示例#4
0
MObject getConnectedInNode(const MObject& thisObject, const char *attrName)
{
    MObject result = MObject::kNullObj;
    MString indexStr, base;
    int index = -1;
    if (getArrayIndex(attrName, indexStr, base))
    {
        index = indexStr.asInt();
        attrName = base.asChar();
    }
    MFnDependencyNode depFn(thisObject);
    MPlug inPlug = depFn.findPlug(attrName);
    if (index > -1)
        inPlug = inPlug[index];
    MString plugname = inPlug.name();

    if (!inPlug.isConnected())
        return result;

    MPlugArray connectedPlugs;
    inPlug.connectedTo(connectedPlugs, true, false);
    if (connectedPlugs.length() == 0)
        return result;

    return connectedPlugs[0].node();
}
	/* Convenience method */
ostream &
_TDL_SpawnStatementTreeNode::printArrayIndexes ( ostream & theOstream ) const
{
  const _TDL_SpawnStatementTreeNode * targetTreeNode;

	/* Top-of-Tree case. */
  if ( getArrayIndex() == _TDL_TreeNode::TOPMOST_ARRAY_INDEX )
  {
    theOstream << "[.]";
    return theOstream;
  }

	/* If we have an array index */
  if ( hasArrayIndex() == TRUE )
  {
    theOstream << "[";
    if ( getParent() != (_TDL_TreeNodeBranch *) NULL )
      getParent() -> printArrayIndexes ( theOstream );
    theOstream  << getArrayIndex() << "]";
    return theOstream;
  }


      /* Walk up the tree, applying pre-insert With-Do/Iteration constraints */
  for ( targetTreeNode  = (const _TDL_SpawnStatementTreeNode *)
			     ( getSpawnStatementData()
			         .  getSpawnStatementTreeNodeSlist()
			         .  getFirstNode() );
	targetTreeNode != (const _TDL_SpawnStatementTreeNode *) NULL;
	targetTreeNode  = (const _TDL_SpawnStatementTreeNode *)
			     ( targetTreeNode -> _TDL_Snode::getNextNode() )
       )
  {
    if ( targetTreeNode -> hasArrayIndex() == TRUE )
      return targetTreeNode -> printArrayIndexes ( theOstream );
  }

	/* IF nothing has an array index, we are obviously a singleton case. */
  return theOstream;
}
示例#6
0
void StarContainer::SearchDelStar(int index,int type)
{
	int x , y , dx , dy , tIndex;
	x = getArrayX( index );
	y = getArrayY( index );

	// left
	dx = x - 1;
	tIndex = getArrayIndex( dx , y);
	if( IsInMap( dx , y ) && IsMatchType( m_pStars[dx][y]->GetType() , type ) && IsNotInList(tIndex) )
		openList->push_back( tIndex );

	// right
	dx = x + 1;
	tIndex = getArrayIndex( dx , y);
	if( IsInMap( dx , y ) && IsMatchType(m_pStars[dx][y]->GetType() , type )  && IsNotInList(tIndex) )
		openList->push_back( tIndex );

	// top
	dy = y - 1;
	tIndex = getArrayIndex( x , dy); 
	if( IsInMap( x , dy ) && IsMatchType(m_pStars[x][dy]->GetType() , type )  && IsNotInList(tIndex) )
		openList->push_back( tIndex );

	// buttom
	dy = y + 1;
	tIndex = getArrayIndex( x , dy); 
	if( IsInMap( x , dy )  && IsMatchType(m_pStars[x][dy]->GetType() , type)  && IsNotInList(tIndex) )
		openList->push_back( tIndex );

	closeList->push_back( index );

	if( openList->size() == 0 )  return;

	index = openList->back();
	openList->pop_back();

	SearchDelStar(index,type);
}
示例#7
0
		Sampler(const std::vector<TypeReaction>& reactions,const std::vector<ProbTable>& xs_container,const ProbTable& total_xs) :
            nreaction(reactions.size()),
            nenergy(getArraySize(*xs_container.begin())),
            reactions(reactions) {

			/* Allocate reaction matrix */
			reaction_matrix = new double[(nreaction - 1) * nenergy];

			/* Sanity check */
			assert(xs_container.size() == reactions.size());
			assert(getArraySize(total_xs) == nenergy);

			/* Once we separate the reactions from the cross sections, we need to construct the reaction matrix */
			for(int nerg = 0 ; nerg < nenergy ; ++nerg) {
				/* Exclusive scan, to construct the accumulated probability table at this energy */
				double partial_sum = 0.0;
				for(int nrea = 0 ; nrea < nreaction - 1; ++nrea) {
					partial_sum += getArrayIndex(nerg,xs_container[nrea]);
					reaction_matrix[nerg*(nreaction - 1) + nrea] = partial_sum / getArrayIndex(nerg,total_xs);
				}
			}
		}
示例#8
0
		Sampler(const std::map<TypeReaction,ProbTable>& reaction_map) :
            nreaction(reaction_map.size()),
            nenergy(getArraySize(reaction_map.begin()->second)),
            reactions(nreaction) {

			/* Allocate reaction matrix */
			reaction_matrix = new double[(nreaction - 1) * nenergy];

			/* TypeReactions */
			typename std::map<TypeReaction,ProbTable>::const_iterator it_rea = reaction_map.begin();
			int nrea = 0;
			/* Cross sections */
			std::vector<ProbTable> xs_container(nreaction);
			for(; it_rea != reaction_map.end() ; ++it_rea) {
				/* Save the reactions into the reaction container */
				reactions[nrea] = (*it_rea).first;
				/* Save the cross sections */
				xs_container[nrea] = (*it_rea).second;
				/* Count reaction */
				nrea++;
			}

			/* Once we separate the reactions from the cross sections, we need to construct the reaction matrix */
			for(int nerg = 0 ; nerg < nenergy ; ++nerg) {
				/* First get the total cross section (of this reactions) at this energy */
				double total_xs = 0.0;
				for(nrea = 0 ; nrea < nreaction ; ++nrea)
					total_xs += getArrayIndex(nerg,xs_container[nrea]);

				/* Exclusive scan, to construct the accumulated probability table at this energy */
				double partial_sum = 0;
				for(nrea = 0 ; nrea < nreaction - 1; ++nrea) {
					partial_sum += getArrayIndex(nerg,xs_container[nrea]);
					reaction_matrix[nerg*(nreaction - 1) + nrea] = partial_sum / total_xs;
				}
			}
		}
示例#9
0
void StarContainer::SaveLevel()
{
	//save config
	for ( int i = 0 ; i < ROLE_NUM ; i++ )
	{
		for ( int j = 0 ;j < ROLE_NUM ; j++ )
		{
			CCString* str = CCString::createWithFormat("%d_index",getArrayIndex( i , j ) );
			if(m_pStars[i][j] == NULL)
				CCUserDefault::sharedUserDefault()->setIntegerForKey( str->getCString(), 0 );
			else
				CCUserDefault::sharedUserDefault()->setIntegerForKey( str->getCString(), m_pStars[i][j]->GetType() );
		}
	}
}
示例#10
0
文件: symbol.c 项目: rems4e/Compiler
int getSymbolSize(symbol_t const *symbol) {
	if(symbol->type.indirectionCount > 0) {
		if((symbol->type.constMask & (1 << symbol->type.indirectionCount)) != 0) {
			dereferencedSymbol_t first = getArrayIndex(symbol->name, 0);
			if(first.symbol != NULL) {
				return getSymbolSize(first.symbol) * (symbol->address - first.symbol->address);
			}
		}

		return SIZEOF_PTR;
	}
	else if(symbol->type.baseType == BT_CHAR) {
		return 1;
	}
	else if(symbol->type.baseType == BT_INT) {
		return SIZEOF_INT;
	}

	return 0;
}
示例#11
0
/*
    Slot to recieve data updates from the base QCaObject and generate integer updates.
*/
void QEInteger::convertVariant( const QVariant &value, QCaAlarmInfo& alarmInfo, QCaDateTime& timeStamp, const unsigned int& variableIndex ) {
    if( value.type() == QVariant::List )
    {
        emit integerArrayChanged( integerFormat->formatIntegerArray( value ), alarmInfo, timeStamp, variableIndex );

        int ai = getArrayIndex();
        if( ai >= 0 && ai < value.toList().count() ) {
           // Convert this array element as a scalar update.
           emit integerChanged( integerFormat->formatInteger( value.toList().value( ai ) ), alarmInfo, timeStamp, variableIndex );
        }
    }
    else
    {
        emit integerChanged( integerFormat->formatInteger( value ), alarmInfo, timeStamp, variableIndex );

        // A scalar is also an array of one element.
        //
        QVariantList array;
        array.append (value);
        emit integerArrayChanged( integerFormat->formatIntegerArray( array ), alarmInfo, timeStamp, variableIndex );
    }
}
/**
 * Return a handler that maps the python type to a C++ type
 * @param object :: A pointer to a PyObject that represents the type
 * @returns A pointer to handler that can be used to instantiate a property
 */
const PropertyValueHandler &
PropertyWithValueFactory::lookup(PyObject *const object) {
  // Check if object is array.
  const auto ptype = isArray(object);
  if (!ptype.empty()) {
    const PyArrayIndex &arrayIndex = getArrayIndex();
    auto ait = arrayIndex.find(ptype);
    if (ait != arrayIndex.end()) {
      return *(ait->second);
    }
  }
  // Object is not array, so check primitive types
  const PyTypeIndex &typeIndex = getTypeIndex();
  auto cit = typeIndex.find(object->ob_type);
  if (cit == typeIndex.end()) {
    std::ostringstream os;
    os << "Cannot create PropertyWithValue from Python type "
       << object->ob_type->tp_name
       << ". No converter registered in PropertyWithValueFactory.";
    throw std::invalid_argument(os.str());
  }
  return *(cit->second);
}
示例#13
0
文件: symbol.c 项目: rems4e/Compiler
}

dereferencedSymbol_t createString(char const *value) {
	bool const oldGlobalScope = getGlobalScope();

	setGlobalScope(true);

	int len = strlen(value) + 1;
	char *interningName;
	asprintf(&interningName, "__internedString__%s", value);

	dereferencedSymbol_t deref = getExistingSymbol(interningName, false);
	symbol_t *tab = deref.symbol;
	if(tab == &dummy) {
		tab = createArray(interningName, (varType_t){.indirectionCount = 0, .baseType = BT_CHAR, .constMask = 1}, len);
		dereferencedSymbol_t data = getArrayIndex(interningName, 0);
		assert(data.symbol);
		for(int i = 0; i < len; ++i) {
			assemblyOutput(AFC" %d %d", data.symbol->address + i, value[i]);
		}
	}

	free(interningName);

	setGlobalScope(oldGlobalScope);

	return getExistingSymbol(interningName, true);
}

dereferencedSymbol_t getExistingSymbol(char const *name, bool failIfNotFound) {
	int const maxLevel = getGlobalScope() ? 0 : symbolTable.nestingLevel;
示例#14
0
void StarContainer::ClickStar(::cocos2d::CCPoint point)
{
	int x = (point.x - 20) / GameMap::GetInstance()->cellWidth;
	int y = ( point.y - 140 ) / GameMap::GetInstance()->cellHeight;

	// begin search star by type
	openList->clear();
	closeList->clear();

	if( !IsInMap(x,y) || GameMap::GetInstance()->GetGameState() == WAIT_START) return;

	switch (GameMap::GetInstance()->GetGameState())
	{
	case  NORMAL:
		{
			SearchDelStar( getArrayIndex( x , y ) , m_pStars[x][y]->GetType());
			if(closeList->size() <= 1) return;
			canReturn = true;
			break;
		}

	case Use_Item_Lolly:
		{
			closeList->push_back( getArrayIndex( x , y ) );
			if(GameItemManager::GetInstance()->UseItem(Item_Lolly))
			{
				if(closeList->size() < 1) return;
				canReturn = true;
			}
			else
				closeList->clear();

			GameMap::GetInstance()->SetGameStage(NORMAL);
			UIManager::GetInstance()->getUIUseItem()->deactivate();
			break;
		}
		
	case Use_Item_Candy:
		{
			if(m_pStars[x][y] == NULL) return;

			if(GameItemManager::GetInstance()->UseItem(Item_Candy))
			{
				
				GameMap::GetInstance()->getSpriteBatchBode()->removeChild( m_pStars[x][y]->GetAvata(),true );
				m_pStars[x][y] = new Star( 7 );
				m_pStars[x][y]->SetPosition( m_pStars[x][y]->getPosition( x , y));
				GameMap::GetInstance()->getSpriteBatchBode()->addChild(m_pStars[x][y]->GetAvata());
			}
			GameMap::GetInstance()->SetGameStage(NORMAL);
			UIManager::GetInstance()->getUIUseItem()->deactivate();
			return;
		}

	case Use_Item_Return:
		{
			if(canReturn && GameItemManager::GetInstance()->UseItem(Item_Return))
			{
				canReturn = false;
				GameMap::GetInstance()->UseReturn();
			}
			GameMap::GetInstance()->SetGameStage(NORMAL);
			UIManager::GetInstance()->getUIUseItem()->deactivate();
			return;
		}

	case Use_Item_Refresh:
		{
			if(GameItemManager::GetInstance()->UseItem(Item_Refresh))
			{
				canReturn = true;
				GameMap::GetInstance()->UseRefresh();
			}
			GameMap::GetInstance()->SetGameStage(NORMAL);
			UIManager::GetInstance()->getUIUseItem()->deactivate();
			return;
		}
	
	}

	SavePreStep();
	
	// play click effect sound
	std::vector<int>::iterator it = closeList->begin();
	for( ; it!= closeList->end(); it++ )
	{
		x = getArrayX( *it );
		y = getArrayY( *it );

		GameMap::GetInstance()->getSpriteBatchBode()->removeChild( m_pStars[x][y]->GetAvata() , true );
		m_pStars[x][y]->Die();

		delete m_pStars[x][y];
		m_pStars[x][y] = NULL;
	}

	GameMap::GetInstance()->PopStarSettle( closeList->size() );

	// reset  x 
	it = closeList->begin();
	for( ; it!= closeList->end(); it++ )
	{
		x = getArrayX( *it );
		y = getArrayY( *it );

		int startIndex = -1;

		for( int j = 0 ; j < ROLE_NUM ; j++ )
		{
			if(m_pStars[x][j] == NULL) 
			{
				startIndex = j;
				break;
			}
		}

		if(startIndex == -1) continue;

		for( int j = startIndex + 1; j < ROLE_NUM ; j++ )
		{
			Star* mTemp = m_pStars[x][j-1];
			m_pStars[x][j-1] = m_pStars[x][j];
			m_pStars[x][j] = mTemp; 
		}
	}

	// rest  y
	it = closeList->begin();
	for( ; it!= closeList->end(); it++ )
	{
		x = getArrayX( *it );
		y = getArrayY( *it );

		int startIndex = -1;

		for( int j = 0 ; j < ROLE_NUM ; j++ )
		{
			if(m_pStars[x][j] == NULL) 
			{
				startIndex = j;
				break;
			}
		}

		if(startIndex == -1) continue;

		for( int j = startIndex + 1; j < ROLE_NUM ; j++ )
		{
			Star* mTemp = m_pStars[x][j-1];
			m_pStars[x][j-1] = m_pStars[x][j];
			m_pStars[x][j] = mTemp; 
		}
	}

	// rest x
	it = closeList->begin();
	for( ; it!= closeList->end(); it++ )
	{
		x = getArrayX( *it );
		y = getArrayY( *it );

		int nullCount = 0;
		int startIndex = -1;

		for( int i = 0 ; i < ROLE_NUM ; i++ )
		{
			nullCount = 0;
			for( int j = 0 ; j < ROLE_NUM ; j++ )
			{
				if( m_pStars[i][j] == NULL ) 
				{
					startIndex = i;
					nullCount++;
				}
			}
			if(nullCount == ROLE_NUM) break;
		}

		if(nullCount == ROLE_NUM)
		{
			for( int i= startIndex + 1 ; i < ROLE_NUM ; i++ )
			{
				for( int j = 0; j < ROLE_NUM ; j++ )
				{
					Star* mTemp = m_pStars[i-1][j];
					m_pStars[i-1][j] = m_pStars[i][j];
					m_pStars[i][j] = mTemp; 
				}
			}
		}
	}

	

	// rest graph
	for (int i=0;i<10;i++)
	{
		for (int j=0;j<10;j++)
		{
			if(m_pStars[i][j] != NULL)
			{
				CCSprite* sprite = m_pStars[i][j]->GetAvata();
				CCMoveTo* moveTo = CCMoveTo::create( MOVE_TIME , m_pStars[i][j]->getPosition( i , j));
				CCEaseBounceOut* easeOut = CCEaseBounceOut::create(moveTo);
				sprite->runAction(easeOut);
			}
		}
	}

	bool gameOver = true;

	// check the is no star to destory
	for( int i = 0 ; i< ROLE_NUM ; i++ )
	{
		for( int j = 0 ; j < ROLE_NUM ; j++ )
		{
			if( m_pStars[i][j] == NULL ) continue;
			closeList->clear();
			SearchDelStar( getArrayIndex( i , j) , m_pStars[i][j]->GetType() );
			if (closeList->size() > 1)
			{
				gameOver = false;
				break;
			}
		}
	}

	// gameOver next stage
	if(gameOver)
		GameMap::GetInstance()->CompleteLevel();
}
示例#15
0
文件: meta.c 项目: reox/libelektra
int elektraSortTopology (KeySet * ks, Key ** array)
{
	if (ks == NULL || array == NULL) return -1;
	KeySet * done = ksNew (0, KS_END);
	ksRewind (ks);
	Key * cur;
	ssize_t size = ksGetSize (ks);
	Key * orderCounter = keyNew ("/#", KEY_CASCADING_NAME, KEY_END);
	elektraArrayIncName (orderCounter);
	_adjMatrix adjMatrix[size];
	int i = 0;
	int retVal = 1;
	int depCount = 0;
	Key ** localArray = elektraMalloc (size * sizeof (Key *));
	elektraKsToMemArray (ks, localArray);
	qsort (localArray, size, sizeof (Key *), topCmpOrder);
	for (long j = 0; j < size; ++j)
	{
		adjMatrix[j].key = localArray[j];
		adjMatrix[j].isResolved = 0;
		adjMatrix[j].deps = elektraCalloc (sizeof (unsigned long) * size);
	}
	kdb_octet_t hasOrder = 0;
	if (keyGetMeta (localArray[0], "order")) hasOrder = 1;
	unsigned int unresolved = 0;
	for (int j = 0; j < size; ++j)
	{
		cur = localArray[j];
		KeySet * deps = elektraMetaArrayToKS (cur, "dep");
		keyDel (ksLookupByName (deps, "dep", KDB_O_POP));
		Key * tmpDep;
		switch (ksGetSize (deps))
		{
		case -1:
		{
			// key has no dependencies, give it an order number and add it to list of resolved dependencies
			keySetMeta (cur, "order", keyBaseName (orderCounter));
			elektraArrayIncName (orderCounter);
			ksAppendKey (done, keyDup (cur));
			adjMatrix[j].isResolved = 1;
			ksDel (deps);
			break;
		}
		case 1:
		{
			// only 1 dependency:
			// test if it's reflexive
			tmpDep = ksHead (deps);
			if (!strcmp (keyName (cur), keyString (tmpDep)))
			{
				keySetMeta (cur, "order", keyBaseName (orderCounter));
				elektraArrayIncName (orderCounter);
				ksAppendKey (done, keyDup (cur));
				adjMatrix[j].isResolved = 1;
				ksDel (deps);
				break;
			}
			// if not, fallthrough to normal dependency handling
		}
		default:
		{
			int gotUnresolved = 0;
			while ((tmpDep = ksNext (deps)) != NULL)
			{
				if (!isValidKeyName (keyString (tmpDep)))
				{
					// invalid keyname -> ERROR
					retVal = -1;
					break;
				}
				i = getArrayIndex (tmpDep, adjMatrix, size);
				if (i == -1)
				{
					// key doesn't exist yet but has valid name, ignore it.
					continue;
				}
				else if (i == j)
				{
					// reflexiv depencency, do nothing
				}
				else
				{
					if (!adjMatrix[i].isResolved)
					{
						// unresolved dependency
						adjMatrix[j].deps[i] = 1;
						++gotUnresolved;
						// simple cycle detection
						if (adjMatrix[i].deps[j])
						{
							retVal = 0;
							break;
						}
					}
				}
			}
			if (gotUnresolved)
			{
				adjMatrix[j].isResolved = 0;
				++unresolved;
				// cound unresolved dependencies
				depCount += gotUnresolved;
			}
			ksDel (deps);
			break;
		}
		}
		if (retVal <= 0) break;
	}
	if (retVal <= 0)
	{
		// error or cycle: goto cleanup
		goto TopSortCleanup;
	}

	// resolve all dependencies that can be resolved immediately
	for (int j = 0; j < size; ++j)
	{
		if (adjMatrix[j].isResolved) depCount -= resolveDep (j, adjMatrix, size);
	}

	ssize_t resolved = ksGetSize (done);
	if (((depCount + resolved) >= size) && (unresolved))
	{
		// more dependencies dependencies than keys:
		//  cycle found !
		retVal = 0;
		goto TopSortCleanup;
	}

	if (unresolved)
	{
		int found = 1;
		// we have unresolved dependencies
		for (int j = 0; j < size + 1; ++j)
		{
			// loop until no dependency can be resolved anymore
			if (j == size)
			{
				if (found)
				{
					found = 0;
					j = -1;
					unresolved = 0;
					continue;
				}
				else
					break;
			}
			if (adjMatrix[j].isResolved) continue;
			++unresolved;
			if (hasOrder)
			{
				// resolve by order
				int ret = resolveDeps (j, adjMatrix, size, done, orderCounter);
				if (ret == -1) break;
				j = -1;
				found = 1;
				continue;
			}
			else
			{
				// resolve next possible dependency in keyset
				if (!hasUnresolvedDependencies (j, adjMatrix, size))
				{
					adjMatrix[j].isResolved = 1;
					resolveDep (j, adjMatrix, size);
					keySetMeta (localArray[j], "order", keyBaseName (orderCounter));
					elektraArrayIncName (orderCounter);
					ksAppendKey (done, keyDup (localArray[j]));
					found = 1;
				}
			}
		}
	}
	if (unresolved == 0)
	{
		// everything resolved
		// add dependencies in topological order to array
		elektraKsToMemArray (ks, array);
		qsort (array, size, sizeof (Key *), topCmpOrder);
		retVal = 1;
	}
	else
	{
		// still unresolved dependencies left:
		// there must be a cycle somewhere
		retVal = 0;
	}
TopSortCleanup:
	ksDel (done);
	keyDel (orderCounter);
	elektraFree (localArray);
	for (ssize_t j = 0; j < size; ++j)
	{
		elektraFree (adjMatrix[j].deps);
	}
	return retVal;
}