Ejemplo n.º 1
0
void Test4()
{
	SListNode* list1 = NULL;
	PushBack(list1, 1);
	PushBack(list1, 2);
	PushBack(list1, 3);
	PushBack(list1, 4);
	PushBack(list1, 5);
	PushBack(list1, 6);
	PrintSList(list1);
	SListNode* ret = FindMidNode2(list1);
	PrintSList(ret);
}
Ejemplo n.º 2
0
int TItemList::Cat(const BYTE* pData, int length)
{
	int remain = length;

	while(remain > 0)
	{
		TItem* pItem = Back();

		if(pItem == nullptr || pItem->IsFull())
			pItem = PushBack(itPool.PickFreeItem());

		int cat  = pItem->Cat(pData, remain);

		pData	+= cat;
		remain	-= cat;
	}

	return length;
}
Ejemplo n.º 3
0
void CodeList::InsertAfter(StmtBase *toInsert, StmtBase *stmt)
{
	nbASSERT(stmt != NULL, "Trying to insert a null statement!");
	nbASSERT(Head != NULL && Tail == NULL, "Empty List");

	StmtBase *nextItem = stmt->Next;

	if (nextItem == NULL)
	{
		PushBack(stmt);
		return;
	}

	nextItem->Prev = toInsert;
	toInsert->Next = nextItem;
	stmt->Next =  toInsert;
	toInsert->Prev = stmt;
	NumStatements++;
}
Ejemplo n.º 4
0
void ValuesTable::Move(const Interval &in) {
	if (in.End() < 0 || in.Start() >= (int)m_values.size()) {
		m_values.resize(0);
		m_values.resize(in.End() - in.Start() + 1);
		return;
	}

	while ((in.End() + 1) < (int)m_values.size())
		PopBack();

	for (int i = 0; i < in.Start(); ++i)
		PopFront();

	for (int i = 0; i > in.Start(); --i)
		PushFront();

	for (int i = m_values.size(); i <= in.End() - in.Start(); ++i) 
		PushBack();
}
Ejemplo n.º 5
0
BOOL CWndGuideSystem::LoadGuide( LPCTSTR lpszFileName )
{
	CScript script;
	if( script.Load( lpszFileName ) == FALSE )
		return FALSE;

	GUIDE_STRUCT guidestruct;
	
	m_listGuide.clear();
	m_listGuideChart.clear();
	
	script.tok = 0;
	
	while( script.tok != FINISHED )
	{
		guidestruct.m_nEventMsg = script.GetNumber();

		script.GetToken(); // {
		if( *script.token  == '{' )
		{
			script.GetToken(); // BEGINNER
			guidestruct.m_bBeginner = script.GetNumber();
			script.GetToken(); // SHOWLEVEL
			guidestruct.m_nShowLevel = script.GetNumber();
			script.GetToken(); // FLAG
			guidestruct.m_bFlag      = script.GetNumber();
			script.GetToken(); // KEY
			guidestruct.m_nkey = script.GetNumber();
			guidestruct.m_str = "";
			script.GetToken();
			guidestruct.m_str	= script.Token;
			script.GetToken();	// }
			PushBack(guidestruct);
		}
		else
			script.GetToken();
	}
	
	m_bIsLoad = TRUE;
	
	return TRUE;
}
Ejemplo n.º 6
0
void Test3()
{
	Seq seq;
	InitSeqList(&seq);
	PushBack(&seq, 1);
	PushBack(&seq, 5);
	PushBack(&seq, 2);
	PushBack(&seq, 5);
	PushBack(&seq, 3);
	PushBack(&seq, 4);
	PushBack(&seq, 5);
    
//	Remove(&seq, 5);
//	Remove(&seq, 6);
//	RemoveAll(&seq, 5);
	RemoveAll(&seq, 6);
	PrintSeqList(&seq);
}
Ejemplo n.º 7
0
// Get next token that must be identifier
Token* SqlParser::GetNextIdentToken(int expected_type, int scope)
{
	Token *token = GetNextToken();

	if(token == NULL)
		return NULL;

	// If it is a word token, convert identifier
	if(token->type == TOKEN_WORD || token->type == TOKEN_IDENT)
		ConvertIdentifier(token, expected_type, scope);

	// Must not be a single char token (non-alpabetical)
	if(token->chr != 0 || token->wchr != 0)
	{
		PushBack(token);
		return NULL;
	}

	return token;
}
Ejemplo n.º 8
0
FileNameDatabaseHeader::FndbOffset
FndbManager::PushBack (/*[in]*/ const char * lpsz)
{
  if (enableStringPooling)
    {
      StringMap::const_iterator it = stringMap.find(lpsz);
      if (it != stringMap.end())
	{
	  return (it->second);
	}
    }
  FileNameDatabaseHeader::FndbOffset ret = GetMemTop();
  MIKTEX_ASSERT (lpsz != 0);
  PushBack (lpsz, strlen(lpsz));
  FastPushBack (null_byte);
  if (enableStringPooling)
    {
      stringMap[lpsz] = ret;
    }
  return (ret);
}
Ejemplo n.º 9
0
void Lexer::ScanIdentifierOrKeyword()
{
	m_tokenType = NameConst;
	ScanName();
	if (m_tokenType == NameConst && m_cc == '.' && isLetter(PeekAtChar()))
		ScanQualifiedRef();
	else
	{
		// It might be a Keyword terminated with a ':' (but not :=)
		// in which case we need to include it.
		if (m_cc == ':' && PeekAtChar() != '=')
		{
			*tp++ = m_cc;
			m_tokenType = NameColon;
		}
		else
		{
			PushBack(m_cc);
		}
	}
}
Ejemplo n.º 10
0
// Parse Teradata CREATE TABLE storage clause
bool SqlParser::ParseTeradataStorageClause(int obj_scope, Token *last_colname, Token *last_colend)
{
	bool exists = false;

	while(true)
	{
		Token *next = GetNextToken();

		if(next == NULL)
			break;

		// UNIQUE PRIMARY INDEX hash partitioning clause
		if(next->Compare("UNIQUE", L"UNIQUE", 6) == true)
		{
			Token *primary = GetNext("PRIMARY", L"PRIMARY", 7);

			if(primary != NULL)
				ParseTeradataPrimaryIndex(next, primary, obj_scope, last_colname, last_colend);

			exists = true;
			continue;
		}
		else
		// PRIMARY INDEX hash partitioning clause
		if(next->Compare("PRIMARY", L"PRIMARY", 7) == true)
		{
			ParseTeradataPrimaryIndex(NULL, next, obj_scope, last_colname, last_colend);

			exists = true;
			continue;
		}

		// Not a storage clause
		PushBack(next);
		break;
	}

	return exists;
}
Ejemplo n.º 11
0
static void test1()
{
	auto vec1 = std::make_unique<CloneableContainers::Vector<std::string>>();

	auto token1_1 = vec1->PushBack("item1");
	auto token1_2 = vec1->PushBack("item2");

	std::cout << "==" << std::endl;
	std::cout << "token1_1 = " << vec1->Get(token1_1) << std::endl;
	std::cout << "token1_2 = " << vec1->Get(token1_2) << std::endl;

	for (auto it = vec1->GetFirst(); !vec1->ReachedEnd(it); vec1->StepNext(it)) {
		std::cout << "Iterated vec1: " << vec1->Get(it) << std::endl;
	}

	std::cout << "==" << std::endl;
	auto vec2 = *vec1;
	auto token2_1 = token1_1;
	auto token2_2 = token1_2;
	std::cout << "token1_1 = " << vec1->Get(token1_1) << std::endl;
	std::cout << "token1_2 = " << vec1->Get(token1_2) << std::endl;
	std::cout << "token2_1 = " << vec2.Get(token2_1) << std::endl;
	std::cout << "token2_2 = " << vec2.Get(token2_2) << std::endl;
	for (auto it = vec1->GetFirst(); !vec1->ReachedEnd(it); vec1->StepNext(it)) {
		std::cout << "Iterated vec1: " << vec1->Get(it) << std::endl;
	}
	for (auto it = vec2.GetFirst(); !vec2.ReachedEnd(it); vec2.StepNext(it)) {
		std::cout << "Iterated vec2: " << vec2.Get(it) << std::endl;
	}

	std::cout << "==" << std::endl;
	vec1.reset();
	std::cout << "token2_1 = " << vec2.Get(token2_1) << std::endl;
	std::cout << "token2_2 = " << vec2.Get(token2_2) << std::endl;
	for (auto it = vec2.GetFirst(); !vec2.ReachedEnd(it); vec2.StepNext(it)) {
		std::cout << "Iterated vec2: " << vec2.Get(it) << std::endl;
	}

}
Ejemplo n.º 12
0
// Parse SQL Server CREATE TABLE storage clause
bool SqlParser::ParseSqlServerStorageClause()
{
	bool exists = false;

	while(true)
	{
		Token *next = GetNext();

		if(next == NULL)
			break;

		// ON filegroup_name
		if(next->Compare("ON", L"ON", 2) == true)
		{
			// File group name
			Token *name = GetNext();
			
			if(_target != SQL_SQL_SERVER)
			{
				// Remove clause if it is the default PRIMARY file group
				if(Token::Compare(name, "PRIMARY", L"PRIMARY", 7) == true ||
					Token::Compare(name, "[PRIMARY]", L"[PRIMARY]", 9) == true)
				{
					Token::Remove(next, name);
				}
			}

			exists = true;
		}
		else
		{
			PushBack(next);
			break;
		}
	}

	return exists;
}
Ejemplo n.º 13
0
        void Rotate(int nRotate)
        {
            // quick fix
            // need optimization

            if(!Empty()){
                if(auto nCount = std::abs(nRotate)){
                    if(nRotate > 0){
                        for(auto nIndex = 0; nIndex < nCount; ++nIndex){
                            auto stHead = Head();
                            PopHead();
                            PushBack(stHead);
                        }
                    }else{
                        for(auto nIndex = 0; nIndex < nCount; ++nIndex){
                            auto stBack = Back();
                            PopBack();
                            PushHead(stBack);
                        }
                    }
                }
            }
        }
Ejemplo n.º 14
0
void CMyList::PushIndex(int idx, void *tagData)
{

    if (idx <= 0)
    {
        PushHead(tagData);
        return;
    }
    if (idx >= m_NodeCount)
    {
        PushBack(tagData);
        return;
    }

    MYLIST_NODE *pNewNode = (MYLIST_NODE *) GetMem(sizeof(MYLIST_NODE));
    pNewNode->pData = tagData;
    pNewNode->pNext = NULL;

    Lock();
    MYLIST_NODE *pPrev = NULL, *pCurr = m_MyListHead;
    for (int i=0; i<idx; i++)
    {
        pPrev = pCurr;
        pCurr = pCurr->pNext;
    }
    if (pPrev)
    {
        pPrev->pNext = pNewNode;
        pNewNode->pNext = pCurr;
    }
    else
    {
        m_MyListHead = pNewNode;
    }
    m_NodeCount++;
    UnLock();
}
Ejemplo n.º 15
0
  inline bool HasNext() {
    static const IterType end;
    if ( !cache_.empty() )
      return(true);
    if ( iter_ == end )
      return(false);

    /*
    Must ReadLine() in case padding is such that all remaining elements
      in a file vaporize.
    Example:
       chr1	20	100
       chr1	30	50
       chr2	5	8

      bedops -u --pad -5:-10
    */
    BedType* tmp = ReadLine();
    if ( tmp != static_cast<BedType*>(0) ) {
      PushBack(tmp);
      return(true);
    }
    return(false);
  }
Ejemplo n.º 16
0
void SimpleTrainTest() {
  std::cout << "============================================================================" << std::endl;
  std::cout << "SIMPLE TRAIN TEST" << std::endl;

  // create a train with 6 dynamically-allocated cars in a doubly-linked list structure
  TrainCar* simple = NULL;
  PushBack(simple, TrainCar::MakeEngine()); 
  PushBack(simple, TrainCar::MakePassengerCar());
  PushBack(simple, TrainCar::MakePassengerCar());
  PushBack(simple, TrainCar::MakeDiningCar());
  PushBack(simple, TrainCar::MakePassengerCar());
  PushBack(simple, TrainCar::MakeSleepingCar());

  // inspect the cars, the links, the links, and sequential IDs...
  assert (simple->isEngine());
  assert (simple->prev == NULL);
  assert (simple->next->isPassengerCar());
  assert (simple->next->prev->isEngine());
  assert (simple->next->next->isPassengerCar());
  assert (simple->next->next->next->isDiningCar());
  assert (simple->next->next->next->next->isPassengerCar());
  assert (simple->next->next->next->next->next->isSleepingCar());
  assert (simple->next->next->next->next->next->next == NULL);
  assert (simple->next->getID() == simple->getID()+1);
  assert (simple->next->next->getID() == simple->next->getID()+1);
  assert (simple->next->next->next->getID() == simple->next->next->getID()+1);
  assert (simple->next->next->next->next->getID() == simple->next->next->next->getID()+1);
  assert (simple->next->next->next->next->next->getID() == simple->next->next->next->next->getID()+1);

  // helper routine sanity check & print the results
  SanityCheck(simple);
  PrintTrain(simple);

  // fully delete all TrainCar nodes to prevent a memory leak
  DeleteAllCars(simple);
}
Ejemplo n.º 17
0
// Parse Oracle CREATE TABLE, CREATE INDEX, PARTITION definition storage clause
bool SqlParser::ParseOracleStorageClause(int stmt_scope)
{
	bool exists = false;

	while(true)
	{
		Token *next = GetNextToken();

		if(next == NULL)
			break;

		// SEGMENT CREATION IMMEDIATE | DEFERRED
		if(next->Compare("SEGMENT", L"SEGMENT", 7) == true)
		{
			Token *creation = GetNextWordToken("CREATION", L"CREATION", 8);
			Token *value = GetNextToken();

			if(_target != SQL_ORACLE && creation != NULL)
				Token::Remove(next, value);

			exists = true;
			continue;
		}
		else
		// PCTFREE num
		if(next->Compare("PCTFREE", L"PCTFREE", 7) == true)
		{
			Token *value = GetNextNumberToken();

			if(_target != SQL_ORACLE && value != NULL)
				Token::Remove(next, value);

			exists = true;
			continue;
		}
		else
		// PCTUSED num
		if(next->Compare("PCTUSED", L"PCTUSED", 7) == true)
		{
			Token *value = GetNextNumberToken();

			if(_target != SQL_ORACLE && value != NULL)
				Token::Remove(next, value);

			exists = true;
			continue;
		}
		else
		// INITRANS num
		if(next->Compare("INITRANS", L"INITRANS", 8) == true)
		{
			Token *value = GetNextNumberToken();

			if(_target != SQL_ORACLE && value != NULL)
				Token::Remove(next, value);

			exists = true;
			continue;
		}
		else
		// MAXTRANS num
		if(next->Compare("MAXTRANS", L"MAXTRANS", 8) == true)
		{
			Token *value = GetNextNumberToken();

			if(_target != SQL_ORACLE && value != NULL)
				Token::Remove(next, value);

			exists = true;
			continue;
		}
		else
		// COMPRESS [BASIC] or COMPRESS num (for index-orginized tables and indexes)
		if(next->Compare("COMPRESS", L"COMPRESS", 8) == true)
		{
			// Optional BASIC keyword
			Token *basic = GetNextWordToken("BASIC", L"BASIC", 5);
			Token *num = NULL;

			// Check for a number
			if(basic == NULL)
				num = GetNextNumberToken();

			if(_target != SQL_ORACLE)
			{
				Token::Remove(next);
				Token::Remove(basic);
				Token::Remove(num);
			}

			exists = true;
			continue;
		}
		else
		// NOCOMPRESS 
		if(next->Compare("NOCOMPRESS", L"NOCOMPRESS", 10) == true)
		{
			if(_target != SQL_ORACLE)
				Token::Remove(next);

			exists = true;
			continue;
		}
		else
		// NOCACHE 
		if(next->Compare("NOCACHE", L"NOCACHE", 7) == true)
		{
			if(_target != SQL_ORACLE)
				Token::Remove(next);

			exists = true;
			continue;
		}
		else
		// LOGGING 
		if(next->Compare("LOGGING", L"LOGGING", 7) == true)
		{
			if(_target != SQL_ORACLE)
				Token::Remove(next);

			exists = true;
			continue;
		}
		else
		// NOLOGGING 
		if(next->Compare("NOLOGGING", L"NOLOGGING", 9) == true)
		{
			if(_target != SQL_ORACLE)
				Token::Remove(next);

			exists = true;
			continue;
		}
		else
		// NOPARALLEL 
		if(next->Compare("NOPARALLEL", L"NOPARALLEL", 10) == true)
		{
			if(_target != SQL_ORACLE)
				Token::Remove(next);

			exists = true;
			continue;
		}
		else
		// PARALLEL num
		if(next->Compare("PARALLEL", L"PARALLEL", 8) == true)
		{
			Token *value = GetNextNumberToken();

			if(_target != SQL_ORACLE && value != NULL)
				Token::Remove(next, value);

			exists = true;
			continue;
		}
		else
		// NOMONITORING 
		if(next->Compare("NOMONITORING", L"NOMONITORING", 12) == true)
		{
			if(_target != SQL_ORACLE)
				Token::Remove(next);

			exists = true;
			continue;
		}
		else
		// TABLESPACE name 
		if(next->Compare("TABLESPACE", L"TABLESPACE", 10) == true)
		{
			Token *name = GetNextIdentToken();

			// ON name
			if(_target == SQL_SQL_SERVER)
				Token::Change(next, "ON", L"ON", 2);
			else
			// IN name
			if(_target == SQL_DB2)
				Token::Change(next, "IN", L"IN", 2);
			else
				Token::Remove(next, name);

			exists = true;
			continue;
		}
		else
		// STORAGE () clause 
		if(next->Compare("STORAGE", L"STORAGE", 7) == true)
		{
			exists = ParseOracleStorageClause(next);
			continue;
		}
		else
		// LOB (column) STORE AS (params)
		if(next->Compare("LOB", L"LOB", 3) == true)
		{
			if(ParseOracleLobStorageClause(next) == true)
			{
				exists = true;
				continue;
			}
		}
		else
		// Oracle partitioning clauses
		if(ParseOraclePartitions(next, stmt_scope) == true)
		{
			exists = true;
			continue;
		}
		else
		// COMPUTE STATISTICS 
		if(next->Compare("COMPUTE", L"COMPUTE", 7) == true)
		{
			Token *statistics = GetNextWordToken("STATISTICS", L"STATISTICS", 10);

			// Remove if not Oracle
			if(_target != SQL_ORACLE)
				Token::Remove(next, statistics);

			exists = true;
			continue;
		}
		else
		// ENABLE ROW MOVEMENT 
		if(next->Compare("ENABLE", L"ENABLE", 6) == true)
		{
			Token *row = GetNextWordToken("ROW", L"ROW", 3);

			if(row != NULL)
			{
				Token *movement = GetNextWordToken("MOVEMENT", L"MOVEMENT", 8);
			
				// Remove if not Oracle
				if(_target != SQL_ORACLE)
					Token::Remove(next, movement);

				exists = true;
				continue;
			}
		}
		else
		// REVERSE index or primary key storage attribute 
		if(next->Compare("REVERSE", L"REVERSE", 7) == true)
		{
			// Remove if not Oracle
			if(_target != SQL_ORACLE)
				Token::Remove(next);

			exists = true;
			continue;
		}
		
		// Not an Oracle storage clause
		PushBack(next);
		break;
	}

	return exists;
}
Ejemplo n.º 18
0
// Parse MySQL CREATE TABLE storage clause
bool SqlParser::ParseMysqlStorageClause(Token *table_name, Token **id_start, Token **comment_out)
{
	bool exists = false;

	// Auto_increment start value
	Token *auto_start = NULL;

	while(true)
	{
		Token *next = GetNextToken();

		if(next == NULL)
			break;

		// ENGINE = type
		if(next->Compare("ENGINE", L"ENGINE", 6) == true)
		{
			// Equal sign = is optional in the clause
			Token *equal = GetNextCharToken('=', L'=');
			Token *type = GetNextToken();

			if(_target != SQL_MYSQL)
			{
				Token::Remove(next);
				Token::Remove(equal);
				Token::Remove(type);
			}

			exists = true;
			continue;
		}
		else
		// AUTO_INCREMENT = start table option
		if(next->Compare("AUTO_INCREMENT", L"AUTO_INCREMENT", 14) == true)
		{
			// Equal sign = is optional in the clause
			Token *equal = GetNextCharToken('=', L'=');
			auto_start = GetNextNumberToken();

			if(_target != SQL_MYSQL)
			{
				Token::Remove(next);
				Token::Remove(equal);
				Token::Remove(auto_start);
			}

			exists = true;
			continue;
		}
		else
		// DEFAULT CHARSET
		if(next->Compare("DEFAULT", L"DEFAULT", 7) == true)
		{
			Token *option = GetNextToken();

			if(option == NULL)
				break;

			// CHARSET
			if(option->Compare("CHARSET", L"CHARSET", 7) == true)
			{
				Token *equal = GetNextCharToken('=', L'=');
				Token *value = GetNextIdentToken();

				if(_target != SQL_MYSQL)
					Token::Remove(next, value);
			}
			else
			// CHARACTER SET
			if(option->Compare("CHARACTER", L"CHARACTER", 9) == true)
			{
				Token *set = GetNextWordToken("SET", L"SET", 3);
				Token *equal = GetNextCharToken('=', L'=');
				Token *value = GetNextIdentToken();

				if(_target != SQL_MYSQL)
					Token::Remove(next, value);
			}

			exists = true;
			continue;
		}
		else
		// COLLATE = value
		if(next->Compare("COLLATE", L"COLLATE", 7) == true)
		{
			Token *equal = GetNextCharToken('=', L'=');
			Token *value = GetNextIdentToken();

			if(_target != SQL_MYSQL)
				Token::Remove(next, value);

			exists = true;
			continue;
		}
		else
		// COMMENT = 'table comment'
		if(next->Compare("COMMENT", L"COMMENT", 7) == true)
		{
			// Equal sign = is optional in the clause
			Token *equal = GetNextCharToken('=', L'=');
			Token *text = GetNextToken();

			if(comment_out != NULL)
				*comment_out = text;

			// Remove from CREATE TABLE
			if(_target != SQL_MYSQL)
				Token::Remove(next, text);

			exists = true;
			continue;
		}
		else
		// PACK_KEYS = 0 | 1 | DEFAULT
		if(next->Compare("PACK_KEYS", L"PACK_KEYS", 9) == true)
		{
			// Optional = 
			Token *equal = GetNextCharToken('=', L'=');
			Token *value = GetNextToken();

			if(_target != SQL_MYSQL)
				Token::Remove(next, value);

			exists = true;
			continue;
		}
		else
		// ROW_FORMAT = type | DEFAULT
		if(next->Compare("ROW_FORMAT", L"ROW_FORMAT", 10) == true)
		{
			// Optional = 
			Token *equal = GetNextCharToken('=', L'=');
			Token *value = GetNextToken();

			if(_target != SQL_MYSQL)
				Token::Remove(next, value);

			exists = true;
			continue;
		}

		// Not a MySQL stoage clause
		PushBack(next);

		break;
	}

	if(id_start != NULL)
		*id_start = auto_start;

	// Restart sequence for PostgreSQL and Greenplum
	if(auto_start != NULL && (_target == SQL_POSTGRESQL || _target == SQL_GREENPLUM))
	{
		// Try to get ;
		Token *semi = GetNextCharToken(';', L';');

		Token *last = (semi != NULL) ? semi : GetLastToken();

		// Append ALTER SEQUENCE command
		Append(last, "\n\nALTER SEQUENCE ", L"\n\nALTER SEQUENCE ", 17);

		// Add sequence name
		Token *seq_name = AppendIdentifier(table_name, "_seq", L"_seq", 4);
		Append(last, seq_name);

		Append(last, " RESTART WITH ", L" RESTART WITH ", 14);
		AppendCopy(last, auto_start);
		Append(last, ";", L";", 1);
	}

	return exists;
}
Ejemplo n.º 19
0
// Temporary table options
bool SqlParser::ParseTempTableOptions(Token *table_name, Token **start_out, Token **end_out, bool *no_data)
{
	bool exists = false;

	Token *start = NULL;

	while(true)
	{
		Token *next = GetNextToken();

		if(next == NULL)
			break;

		if(start == NULL)
			start = next;

		// ON COMMIT PRESERVE | DELETE ROWS in Oracle, DB2; ON ROLLBACK PRESERVE | DELETE ROWS in DB2   
		if(next->Compare("ON", L"ON", 2) == true)
		{
			Token *commit = GetNextWordToken("COMMIT", L"COMMIT", 6);
			Token *rollback = NULL;

			if(commit == NULL)
				rollback = GetNextWordToken("ROLLBACK", L"ROLLBACK", 8);

			if(commit == NULL && rollback == NULL)
				break;

			Token *delete_ = GetNextWordToken("DELETE", L"DELETE", 6);
			Token *preserve = NULL;

			if(delete_ == NULL)
				preserve = GetNextWordToken("PRESERVE", L"PRESERVE", 8);

			Token *rows = GetNextWordToken("ROWS", L"ROWS", 4);

			if(_target == SQL_SQL_SERVER)
				Token::Remove(next, rows);
			else
			// Oracle does not support ON ROLLBACK, but DELETE ROWS in default on rollback
			if(_target == SQL_ORACLE && rollback != NULL) 
			{
				if(delete_ != NULL)
					Token::Remove(next, rows);
				else
					Comment(next, rows);
			}
			
			exists = true;
			continue;
		}
		else
		// NOT LOGGED in DB2   
		if(next->Compare("NOT", L"NOT", 3) == true)
		{
			Token *logged = GetNextWordToken("LOGGED", L"LOGGED", 6);

			if(logged != NULL)
			{
				if(_target == SQL_ORACLE) 
					Token::Remove(next, logged);

				exists = true;
				continue;
			}
		}
		else
		// WITH REPLACE, WITH NO DATA in DB2   
		if(next->Compare("WITH", L"WITH", 4) == true)
		{
			Token *replace = GetNextWordToken("REPLACE", L"REPLACE", 7);
			Token *no = NULL;

			if(replace == NULL)
				no = GetNextWordToken("NO", L"NO", 2);

			// WITH REPLACE in DB2
			if(replace != NULL)
			{
				if(Target(SQL_DB2) == false) 
					Token::Remove(next, replace);

				_spl_declared_tables_with_replace.Add(table_name);

				exists = true;
				continue;
			}
			else
			// WITH NO DATA in DB2
			if(no != NULL)
			{
				Token *data = GetNextWordToken("DATA", L"DATA", 4);

				if(data != NULL)
				{
					if(_target == SQL_ORACLE) 
						Token::Remove(next, data);

					if(no_data != NULL)
						*no_data = true;

					exists = true;
					continue;
				}
			}
		}
		else
		// DEFINITION ONLY in DB2   
		if(next->Compare("DEFINITION", L"DEFINITION", 10) == true)
		{
			Token *only = GetNextWordToken("ONLY", L"ONLY", 4);

			if(only != NULL)
			{
				if(_target == SQL_ORACLE) 
					Token::Remove(next, only);

				if(no_data != NULL)
					*no_data = true;

				exists = true;
				continue;
			}
		}
		else
		// IN tablespace in DB2   
		if(next->Compare("IN", L"IN", 2) == true)
		{
			Token *tablespace_name = GetNextToken();

			if(tablespace_name != NULL)
			{
				if(_target == SQL_ORACLE) 
					Token::Remove(next, tablespace_name);

				exists = true;
				continue;
			}
		}
				
		// Not a temporary table clause
		PushBack(next);
		break;
	}

	if(exists == true)
	{
		if(start_out != NULL)
			*start_out = start;

		if(end_out != NULL)
			*end_out = GetLastToken();
	}

	return exists;
}
Ejemplo n.º 20
0
// Parse DB2 CREATE TABLE storage clause
bool SqlParser::ParseDb2StorageClause()
{
	bool exists = false;

	while(true)
	{
		Token *next = GetNextToken();

		if(next == NULL)
			break;

		// IN tablespace
		if(next->Compare("IN", L"IN", 2) == true)
		{
			// Get tablespace name (can include database name: dbname.tbsname)
			Token *name = GetNextIdentToken();

			// TABLESPACE name in Oracle
			if(_target == SQL_ORACLE)
			{
				Token::Change(next, "TABLESPACE", L"TABLESPACE", 10);

				// Name can contain database name, remove it
				ConvertIdentRemoveLeadingPart(name);
			}
			else
			if(_target != SQL_DB2)
				Token::Remove(next, name);

			exists = true;
			continue;
		}
		else
		// INDEX IN tablespace
		if(next->Compare("INDEX", L"INDEX", 5) == true)
		{
			Token *in = GetNextWordToken("IN", L"IN", 2);
			Token *name = GetNextIdentToken();

			if(_target != SQL_DB2)
				Token::Remove(next, name);

			exists = true;
			continue;
		}
		else
		// COMPRESS YES | NO clause
		if(next->Compare("COMPRESS", L"COMPRESS", 8) == true)
		{
			Token *yesno = GetNextToken();
			
			if(_target != SQL_DB2)
				Token::Remove(next, yesno);

			exists = true;
			continue;
		}
		else
		// CCSID ASCII | UNICODE | EBCDIC
		if(next->Compare("CCSID", L"CCSID", 5) == true)
		{
			Token *encoding = GetNextToken();
			
			if(_target != SQL_DB2)
				Token::Remove(next, encoding);

			exists = true;
			continue;
		}
		else
		// DATA CAPTURE CHANGES | NONE
		if(next->Compare("DATA", L"DATA", 4) == true)
		{
			Token *capture = GetNextWordToken("CAPTURE", L"CAPTURE", 7);
			Token *option = NULL;
			
			if(capture != NULL)
			{
				option = GetNextToken();
			
				if(_target != SQL_DB2)
					Token::Remove(next, option);

				exists = true;
				continue;
			}
		}
		else
		// DB2 z/OS AUDIT CHANGES | NONE | ALL
		if(next->Compare("AUDIT", L"AUDIT", 5) == true)
		{
			Token *option = GetNextToken();
			
			if(_target != SQL_DB2)
				Token::Remove(next, option);

			exists = true;
			continue;
		}
		else
		// DB2 z/OS WITH RESTRICT ON DROP  
		if(next->Compare("WITH", L"WITH", 4) == true)
		{
			Token *restrict = GetNextWordToken("RESTRICT", L"RESTRICT", 8);
			Token *on = NULL;
			Token *drop = NULL;

			if(restrict != NULL)
			{
				on = GetNextWordToken("ON", L"ON", 2);

				if(on != NULL)
					drop = GetNextWordToken("DROP", L"DROP", 4);

				if(_target != SQL_DB2)
					Token::Remove(next, drop);

				exists = true;
				continue;
			}
		}
		else
		// DB2 z/OS NOT VOLATILE  
		if(next->Compare("NOT", L"NOT", 3) == true)
		{
			Token *volatile_ = GetNextWordToken("VOLATILE", L"VOLATILE", 8);

			if(volatile_ != NULL)
			{
				if(_target != SQL_DB2)
					Token::Remove(next, volatile_);

				exists = true;
				continue;
			}
		}
		else
		// DB2 z/OS VOLATILE  
		if(next->Compare("VOLATILE", L"VOLATILE", 8) == true)
		{
			if(_target != SQL_DB2)
				Token::Remove(next);

			exists = true;
			continue;
		}
		else
		// DB2 z/OS APPEND NO | YES  
		if(next->Compare("APPEND", L"APPEND", 6) == true)
		{
			Token *value = GetNextToken();

			if(value != NULL)
			{
				if(_target != SQL_DB2)
					Token::Remove(next, value);

				exists = true;
				continue;
			}
		}
		else
		// PARTITION BY SIZE EVERY n G 
		if(next->Compare("PARTITION", L"PARTITION", 9) == true)
		{
			Token *by = GetNextWordToken("BY", L"BY", 2);
			Token *size = GetNextWordToken(by, "SIZE", L"SIZE", 4);

			// Partition by size
			if(size != NULL)
			{
				// Optional EVERY n G
				Token *every = GetNextWordToken("EVERY", L"EVERY", 5);
				Token *num = GetNextToken(every);
				Token *g = GetNextWordToken("G", L"G", 1);

				if(_target != SQL_DB2)
				{
					Token::Remove(next, size);
					Token::Remove(every, num);
					Token::Remove(g);
				}

				exists = true;
				continue;
			}
			else
			if(ParseDb2PartitioningClause(next, by) == true)
			{
				exists = true;
				continue;
			}
		}

		// Not a DB2 storage clause
		PushBack(next);

		break;
	}

	return exists;
}
Ejemplo n.º 21
0
// Parse Informix CREATE TABLE storage clause
bool SqlParser::ParseInformixStorageClause()
{
	bool exists = false;

	while(true)
	{
		Token *next = GetNextToken();

		if(next == NULL)
			break;

		// EXTENT SIZE num
		if(next->Compare("EXTENT", L"EXTENT", 6) == true)
		{
			Token *size = GetNextWordToken("SIZE", L"SIZE", 4);
			Token *num = GetNextToken(size);

			if(_target != SQL_INFORMIX && num != NULL)
				Token::Remove(next, num);

			exists = true;
			continue;
		}
		else
		// FRAGMENT BY partitioning clause
		if(next->Compare("FRAGMENT", L"FRAGMENT", 8) == true)
		{
			ParseInformixFragmentBy(next);

			exists = true;
			continue;
		}
		else
		// IN dbspace
		if(next->Compare("IN", L"IN", 2) == true)
		{
			// Get database space name
			Token *name = GetNextToken();

			// TABLESPACE name in Oracle
			if(_target == SQL_ORACLE)
				Token::Change(next, "TABLESPACE", L"TABLESPACE", 10);
			else
			// DB2 also uses IN keyword to specify a tablespace
			if(Target(SQL_DB2, SQL_INFORMIX) == false)
				Token::Remove(next, name);

			exists = true;
			continue;
		}
		else
		// LOCK MODE PAGE | ROW | TABLE
		if(next->Compare("LOCK", L"LOCK", 4) == true)
		{
			Token *mode = GetNextWordToken("MODE", L"MODE", 4);
			Token *type = GetNextToken(mode);

			if(_target != SQL_INFORMIX && type != NULL)
				Token::Remove(next, type);

			exists = true;
			continue;
		}
		else
		// NEXT SIZE num
		if(next->Compare("NEXT", L"NEXT", 4) == true)
		{
			Token *size = GetNextWordToken("SIZE", L"SIZE", 4);
			Token *num = GetNextToken(size);

			if(_target != SQL_INFORMIX && num != NULL)
				Token::Remove(next, num);

			exists = true;
			continue;
		}

		// Not a storage clause
		PushBack(next);
		break;
	}

	return exists;
}
Ejemplo n.º 22
0
 namespace internal
 {
         const std::function<rapidjsonValue_ptr(const IReader* obj,Allocator& allocator)>vectorConverter
         = [](const IReader* obj,Allocator& allocator)
         {
             const auto value = static_cast<const ReaderVector*>(obj);
             auto valueResult = rapidjsonValue_ptr(new rapidjsonValue(rapidjson::Type::kArrayType));
             valueResult->Reserve((rapidjson::SizeType)value->size(), allocator);
             for (auto it = value->begin(), end = value->end(); it != end; ++it)
             {
                 auto element = *it;
                 auto elementResult = convert(element, allocator);
                 valueResult->PushBack(*elementResult, allocator);
             }
             return valueResult;
         };
     
     
     const std::function<rapidjsonValue_ptr(const IReader* obj,Allocator& allocator)>mapConverter
     = [](const IReader* obj,Allocator& allocator)
     {
         const auto value = static_cast<const ReaderMap*>(obj);
         auto valueResult = rapidjsonValue_ptr(new rapidjsonValue(rapidjson::Type::kObjectType));
         //valueResult->Reserve((rapidjson::SizeType)value->size(), allocator);
         for (auto it = value->begin(), end = value->end(); it != end; ++it)
         {
             auto element = it->second;
             auto elementResult = convert(element, allocator);
             valueResult->AddMember(it->first.c_str(), *elementResult, allocator);
         }
         return valueResult;
     };
     
     const std::function<rapidjsonValue_ptr(const IReader* obj,Allocator& allocator)> stringConverter
     = [](const IReader* obj,Allocator& allocator)
     {
         const auto value = static_cast<const ReaderString*>(obj);
         auto valueResult = rapidjsonValue_ptr(new rapidjsonValue());
         valueResult->SetString(value->getValue().data(), static_cast<rapidjson::SizeType>(value->getValue().length()), allocator);
         return valueResult;
     };
     
 
     const std::array<std::function<rapidjsonValue_ptr(const IReader* obj,Allocator& allocator)>,(int)InternalType::STRING64+1> typeConverter =
     {
         [](const IReader* /*obj*/,Allocator& /*allocator*/)
         {
             auto value = rapidjsonValue_ptr(new rapidjsonValue());
             value->SetNull();
             return value;
         },
         //ints
         [](const IReader* obj,Allocator& /*allocator*/)
         {
             const auto value = static_cast<const ReaderInt8*>(obj);
             return rapidjsonValue_ptr(new rapidjsonValue(value->getValue()));
         }
         ,
         [](const IReader* obj,Allocator& /*allocator*/)
         {
             const auto value = static_cast<const ReaderInt16*>(obj);
             return rapidjsonValue_ptr(new rapidjsonValue(value->getValue()));
         }
         ,
         [](const IReader* obj,Allocator& /*allocator*/)
         {
             const auto value = static_cast<const ReaderInt32*>(obj);
             return rapidjsonValue_ptr(new rapidjsonValue(value->getValue()));
         }
         ,
         [](const IReader* obj,Allocator& /*allocator*/)
         {
             const auto value = static_cast<const ReaderInt64*>(obj);
             return rapidjsonValue_ptr(new rapidjsonValue(value->getValue()));
         },
         //uints
         [](const IReader* obj,Allocator& /*allocator*/)
         {
             const auto value = static_cast<const ReaderUInt8*>(obj);
             return rapidjsonValue_ptr(new rapidjsonValue(value->getValue()));
         }
         ,
         [](const IReader* obj,Allocator& /*allocator*/)
         {
             const auto value = static_cast<const ReaderUInt16*>(obj);
             return rapidjsonValue_ptr(new rapidjsonValue(value->getValue()));
         }
         ,
         [](const IReader* obj,Allocator& /*allocator*/)
         {
             const auto value = static_cast<const ReaderUInt32*>(obj);
             return rapidjsonValue_ptr(new rapidjsonValue(value->getValue()));
         }
         ,
         [](const IReader* obj,Allocator& /*allocator*/)
         {
             const auto value = static_cast<const ReaderUInt64*>(obj);
             return rapidjsonValue_ptr(new rapidjsonValue(value->getValue()));
         },
         //float
         [](const IReader* obj,Allocator& /*allocator*/)
         {
             const auto value = static_cast<const ReaderFloat*>(obj);
             return rapidjsonValue_ptr(new rapidjsonValue(value->getValue()));
         },
         //double
         [](const IReader* obj,Allocator& /*allocator*/)
         {
             const auto value = static_cast<const ReaderDouble*>(obj);
             return rapidjsonValue_ptr(new rapidjsonValue(value->getValue()));
         },
         //bool
         [](const IReader* obj,Allocator& /*allocator*/)
         {
             const auto value = static_cast<const ReaderBool*>(obj);
             return rapidjsonValue_ptr(new rapidjsonValue(value->getValue()));
         },
         //vector
         vectorConverter,
         vectorConverter,
         vectorConverter,
         vectorConverter,
         //map
         mapConverter,
         mapConverter,
         mapConverter,
         mapConverter,
         //string
         stringConverter,
         stringConverter,
         stringConverter,
         stringConverter
     };
 }
Ejemplo n.º 23
0
/*static*/ void wxArtProvider::InitNativeProvider()
{
    PushBack(new wxGTK2ArtProvider);
}
Ejemplo n.º 24
0
    GenExpTLVec*
    CFGEnumeratorSingle::PopulateExpsOfGNCost(const GrammarNode* GN, uint32 Cost, bool Complete)
    {
        auto Retval = new GenExpTLVec();
        GNCostPair Key(GN, Cost);
        Done = false;
        auto Type = GN->GetType();
        PushExpansion(GN->ToString());
        auto const ExpansionTypeID = GetExpansionTypeID();

        auto FPVar = GN->As<GrammarFPVar>();
        // The base cases
        if (FPVar != nullptr) {
            return MakeBaseExpression<GenFPExpression>(Retval, FPVar->GetOp(), Type,
                                                       ExpansionTypeID, Cost, Key, Complete);
        }

        auto LetVar = GN->As<GrammarLetVar>();
        if (LetVar != nullptr) {
            return MakeBaseExpression<GenLetVarExpression>(Retval, LetVar->GetOp(), Type,
                                                           ExpansionTypeID, Cost, Key, Complete);
        }

        auto Const = GN->As<GrammarConst>();
        if (Const != nullptr) {
            return MakeBaseExpression<GenConstExpression>(Retval, Const->GetOp(), Type,
                                                          ExpansionTypeID, Cost, Key, Complete);
        }

        auto Func = GN->As<GrammarFunc>();

        if (Func != nullptr) {
            auto const& Args = Func->GetChildren();
            auto Op = Func->GetOp();
            const uint32 OpCost = Op->GetCost();
            const uint32 Arity = Op->GetArity();

            if (Cost < Arity + OpCost) {
                Retval->Freeze();
                ExpRepository[Key] = Retval;
                PopExpansion();
                return Retval;
            }
            PartitionGenerator* PG;
            if (Op->IsSymmetric() && Args[0] == Args[1]) {
                PG = new SymPartitionGenerator(Cost - OpCost);
            } else {
                PG = new PartitionGenerator(Cost - OpCost, Arity);
            }

            const uint32 NumPartitions = PG->Size();
            for (uint32 i = 0; i < NumPartitions; ++i) {

                auto Feasible = true;
                vector<const GenExpTLVec*> ArgExpVecs(Arity, nullptr);
                auto CurPartition = (*PG)[i];
                vector<GenExpTLVec::ConstIterator> Begins(Arity);
                vector<GenExpTLVec::ConstIterator> Ends(Arity);

                for (uint32 j = 0; j < Arity; ++j) {
                    auto CurVec = GetVecForGNCost(Args[j], CurPartition[j]);
                    if (CurVec == nullptr) {
                        CurVec = PopulateExpsOfGNCost(Args[j], CurPartition[j], false);
                    }
                    if (CurVec->Size() == 0) {
                        Feasible = false;
                        break;
                    } else {
                        ArgExpVecs[j] = CurVec;
                        Begins[j] = CurVec->Begin();
                        Ends[j] = CurVec->End();
                    }
                }

                if (!Feasible) {
                    continue;
                }

                // Iterate over the cross product
                auto CPGen = new CrossProductGenerator(Begins, Ends, GetPoolForSize(Arity));

                for (auto CurArgs = CPGen->GetNext();
                     CurArgs != nullptr;
                     CurArgs = CPGen->GetNext()) {

                    auto CurExp = new (FuncExpPool->malloc())
                        GenFuncExpression(static_cast<const InterpretedFuncOperator*>(Op), CurArgs);

                    auto Status =
                        (Complete ?
                         Solver->ExpressionCallBack(CurExp, Type, ExpansionTypeID, Index) :
                         Solver->SubExpressionCallBack(CurExp, Type, ExpansionTypeID));

                    if ((Status & DELETE_EXPRESSION) == 0) {
                        CPGen->RelinquishOwnerShip();
                        Retval->PushBack(CurExp);
                        NumExpsCached++;
                    } else {
                        FuncExpPool->free(CurExp);
                    }
                    if ((Status & STOP_ENUMERATION) != 0) {
                        Done = true;
                        break;
                    }
                }
                delete CPGen;
                if (Done) {
                    break;
                }
            }
            delete PG;

            Retval->Freeze();
            ExpRepository[Key] = Retval;
            PopExpansion();
            return Retval;
        }

        auto Let = GN->As<GrammarLet>();

        // We handle this in similar spirit as functions
        if (Let != nullptr) {
            auto const& Bindings = Let->GetBindings();
            const uint32 NumBindings = Bindings.size();
            const uint32 Arity = NumBindings + 1;
            auto BoundNode = Let->GetBoundExpression();
            const uint32 NumLetBoundVars = TheGrammar->GetNumLetBoundVars();

            if (Cost < Arity + 1) {
                Retval->Freeze();
                ExpRepository[Key] = Retval;
                PopExpansion();
                return Retval;
            }

            // Making a let binding incurs a cost of 1!
            auto PG = new PartitionGenerator(Cost - 1, Arity);
            const uint32 NumPartitions = PG->Size();
            for (uint32 i = 0; i < NumPartitions; ++i) {
                auto Feasible = true;
                vector<const GenExpTLVec*> ArgExpVecs(Arity, nullptr);
                auto CurPartition = (*PG)[i];
                vector<GenExpTLVec::ConstIterator> Begins(Arity);
                vector<GenExpTLVec::ConstIterator> Ends(Arity);

                uint32 j = 0;
                uint32* Positions = new uint32[NumBindings];

                for (auto it = Bindings.begin(); it != Bindings.end(); ++it) {
                    auto CurVec = GetVecForGNCost(it->second, CurPartition[j]);
                    if (CurVec == nullptr) {
                        CurVec = PopulateExpsOfGNCost(it->second, CurPartition[j], false);
                    }
                    if (CurVec->Size() == 0) {
                        Feasible = false;
                        break;
                    } else {
                        ArgExpVecs[j] = CurVec;
                        Begins[j] = CurVec->Begin();
                        Ends[j] = CurVec->End();
                    }
                    Positions[j] = it->first->GetOp()->GetPosition();
                    ++j;
                }

                if (!Feasible) {
                    delete[] Positions;
                    continue;
                }

                // Finally, the expression set for the bound expression
                auto BoundVec = GetVecForGNCost(BoundNode, CurPartition[j]);
                if (BoundVec == nullptr) {
                    BoundVec = PopulateExpsOfGNCost(BoundNode, CurPartition[j], false);
                }
                if (BoundVec->Size() == 0) {
                    // cross product is empty not feasible
                    delete[] Positions;
                    continue;
                } else {
                    ArgExpVecs[NumBindings] = BoundVec;
                    Begins[NumBindings] = BoundVec->Begin();
                    Ends[NumBindings] = BoundVec->End();
                }


                // Iterate over the cross product of expressions
                // The bindings object will be of size of the NUMBER
                // of let bound vars for the whole grammar
                auto CPGen = new CrossProductGenerator(Begins, Ends,
                                                       GetPoolForSize(Arity));
                GenExpressionBase const** BindVec = nullptr;
                auto BindVecPool = GetPoolForSize(NumLetBoundVars);

                for (auto CurArgs = CPGen->GetNext(); CurArgs != nullptr; CurArgs = CPGen->GetNext()) {
                    // We need to build the binding vector based on the position
                    if (BindVec == nullptr) {
                        BindVec = (GenExpressionBase const**)BindVecPool->malloc();
                        memset(BindVec, 0, sizeof(GenExpressionBase const*) * NumLetBoundVars);
                    }
                    for (uint32 k = 0; k < NumBindings; ++k) {
                        BindVec[Positions[k]] = CurArgs[k];
                    }

                    auto CurExp = new (LetExpPool->malloc())
                        GenLetExpression(BindVec, CurArgs[NumBindings], NumLetBoundVars);
                    auto Status =
                        (Complete ?
                         Solver->ExpressionCallBack(CurExp, Type, ExpansionTypeID, Index) :
                         Solver->SubExpressionCallBack(CurExp, Type, ExpansionTypeID));

                    if ((Status & DELETE_EXPRESSION) == 0) {
                        BindVec = nullptr;
                        Retval->PushBack(CurExp);
                        NumExpsCached++;
                    } else {
                        LetExpPool->free(CurExp);
                    }
                    if ((Status & STOP_ENUMERATION) != 0) {
                        Done = true;
                        break;
                    }
                }

                delete CPGen;
                delete[] Positions;

                if (Done) {
                    break;
                }
            }

            delete PG;

            Retval->Freeze();
            ExpRepository[Key] = Retval;
            PopExpansion();
            return Retval;
        }

        auto NT = GN->As<GrammarNonTerminal>();
        if (NT != nullptr) {
            const vector<GrammarNode*>& Expansions = TheGrammar->GetExpansions(NT);
            for (auto const& Expansion : Expansions) {
                auto CurVec = GetVecForGNCost(Expansion, Cost);
                if (CurVec == nullptr) {
                    CurVec = PopulateExpsOfGNCost(Expansion, Cost, Complete);
                }
                Retval->Merge(*CurVec);
                if (Done) {
                    break;
                }
            }
            Retval->Freeze();
            ExpRepository[Key] = Retval;
            PopExpansion();
            return Retval;
        }

        // Should NEVER get here
        throw InternalError((string)"You probably subclassed GrammarNode and forgot to change " +
                            "CFGEnumerator.cpp.\nAt: " + __FILE__ + ":" + to_string(__LINE__));
    }
Ejemplo n.º 25
0
void Test4()
{
	Seq seq;
	InitSeqList(&seq);
	PushBack(&seq, 10);
	PushBack(&seq, 5);
	PushBack(&seq, 2);
	PushBack(&seq, 5);
	PushBack(&seq, 3);
	PushBack(&seq, 10);
	PushBack(&seq, 5);
	PushBack(&seq, 6);
	PushBack(&seq, 8);
	PushBack(&seq, 7);
	PushBack(&seq, 9);
	PushBack(&seq, 1);

	PrintSeqList(&seq);
//	BubbleSort(&seq);
	InsertSort(&seq);
//	SelectSort(&seq);
	PrintSeqList(&seq);

}
Ejemplo n.º 26
0
Archivo: Linklist.cpp Proyecto: LLZK/C
int main()
{
  int input = -1;
  int x = 0;
  int pos = 0;
  int k = 0;
  LinkList mylist;
  pListNode tmp = NULL;
  	pListNode ret = NULL;
  InitLinklist(&mylist);
  menu();
  while(1)
  {
	  printf("请输入选项:\n");
	scanf("%d",&input);
    switch(input)
	{
	case POPB:
		Popback(&mylist);
		break;
	case POPF:
		Popfront(&mylist);
		break;
	case PUSB:
		printf("请输入要插入的数据:\n");
		scanf("%d",&x);
		PushBack(&mylist,x);
		break;
	case PUSF:
		printf("请输入要插入的数据:\n");
		scanf("%d",&x);
		Pushfront(&mylist,x);
		break;
	case INSE:
		printf("请输入要插入的数据:\n");
		scanf("%d",&x);
		printf("请输入要插入的位置(哪个数据之前):\n");
		scanf("%d",&pos);
		Insert(&mylist,FindNode(&mylist,pos),x);
		break;
	case REMO:
		printf("请输入要删除的数据:\n");
		scanf("%d",&x);
		Remove(&mylist,x);
		break;
	case REMOA:
		RemoveALL(&mylist);
		break;
	case PRINT:
		Printlist(&mylist);
		break;
	case ERASE:
		printf("请输入要擦除的位置(哪一个数字):\n");
		scanf("%d",&pos);
		Erase(&mylist,FindNode(&mylist,pos));
		break;
	case BUBBL:
		BubbleSort(&mylist);
		break;
	case FIND:
		printf("请输入要查找的数字:");
		scanf("%d",&pos);
		FindNode(&mylist,pos);
		printf("%p",FindNode(&mylist,pos));
	case REVERSE:
		Reverselist(&mylist);
		break;
	case INSEF:
		printf("请输入要插入的数据:\n");
		scanf("%d",&x);
		printf("请输入要插入的位置(哪个数据之前):\n");
		scanf("%d",&pos);
		InsertFrontNode(FindNode(&mylist,pos),x);
		break;
	case FINDM:
		ret = FindMid(&mylist);
		printf("中间结点为 %d\n",ret->data);
		break;
	case DELB:
		printf("请输入k的值:");
		scanf("%d",&k);
		Delbackn(&mylist,k);
		break;
	case EXIT:
		return 0;
		break;
	default:
		printf("输入错误!\n");
		break;
	}
  }
  system("pause");
  return 0;
}
Ejemplo n.º 27
0
void Hand::AddCard( Card* pCard )
{
	PushBack(pCard);
}
Ejemplo n.º 28
0
descriptor_allocation_t DescriptorAllocator::AllocateTemporary(u32 num) {
	if (!Size(TemporaryBlocks)) {
		ScopeLock lock(&TemporaryBlocksCS);
		if (!Size(TemporaryBlocks)) {
			PushBack(TemporaryBlocks, AllocateBlock());
			CurrentTemporaryBlockIndex = 0;
		}
	}

	descriptor_allocation_t allocation = {};
	allocation.allocator = this;
	allocation.size = num;

	u16 currentTmpBlockIndex;
	u16 blockToTry;
	u32 blockNextAllocation;
	//{
	//	ScopeLock lock(&TemporaryBlocksCS);
	//	currentTmpBlockIndex = CurrentTemporaryBlockIndex.load();
	//	blockToTry = TemporaryBlocks[currentTmpBlockIndex];
	//	blockNextAllocation = Blocks[blockToTry].next_allocation_offset.load();
	//}

	currentTmpBlockIndex = CurrentTemporaryBlockIndex.load();
	blockToTry = TemporaryBlocks[currentTmpBlockIndex];
	blockNextAllocation = Blocks[blockToTry].next_allocation_offset.load();

	while (true) {
		if (blockNextAllocation + num <= BlockSize) {
			auto expected = blockNextAllocation;
			if (Blocks[blockToTry].next_allocation_offset.compare_exchange_strong(expected, blockNextAllocation + num)) {
				allocation.heap_offset = blockToTry * BlockSize + blockNextAllocation;
				break;
			}
			blockNextAllocation = expected;
		}
		else {
			Check(currentTmpBlockIndex <= Size(TemporaryBlocks));
			if (currentTmpBlockIndex + 1 == Size(TemporaryBlocks)) {
				while (CurrentTemporaryBlockIndex + 1 == Size(TemporaryBlocks)) {
					if (TemporaryBlocksCS.TryLock()) {
						PushBack(TemporaryBlocks, AllocateBlock());
						TemporaryBlocksCS.Unlock();
					}
					else {
						_mm_pause();
					}
				}
			}

			auto expected = currentTmpBlockIndex;
			if (CurrentTemporaryBlockIndex.compare_exchange_strong(expected, currentTmpBlockIndex + 1)) {
				currentTmpBlockIndex = currentTmpBlockIndex + 1;
			}
			else {
				currentTmpBlockIndex = expected;
			}
			Check(currentTmpBlockIndex < Size(TemporaryBlocks));

			blockToTry = TemporaryBlocks[currentTmpBlockIndex];
			blockNextAllocation = Blocks[blockToTry].next_allocation_offset.load();
		}
	}

	return allocation;
}
Ejemplo n.º 29
0
void CUpdateSystem::AddComponent(CComponent* _comp)
{
	CUpdateComponent* ucmp = (CUpdateComponent*)_comp;
	
	PushBack(ucmp);
}
Ejemplo n.º 30
0
void Test1()
{
	SListNode* list1 = NULL;
	PushBack(list1, 1);
	PushBack(list1, 2);
	PushBack(list1, 1);
	PushBack(list1, 13);
	PushBack(list1, 1);
	PushBack(list1, 12);
	PushBack(list1, 13);
	PushBack(list1, 1);

	PushBack(list1, 3);
	PushBack(list1, 4);
	PushBack(list1, 5);
	PushBack(list1, 1);
	PushBack(list1, 1);
	PushBack(list1, 5);
	PushBack(list1, 5);
	PushBack(list1, 5);
	PushBack(list1, 1);
	PushBack(list1, 1);
	PushBack(list1, 5);
	PushBack(list1, 5);
	PushBack(list1, 5);
	PushBack(list1, 1);
	PushBack(list1, 1);

	PrintSList(list1);
	SListNode* ret= ListParation2(list1, 5);
	PrintSList(ret);
}