Пример #1
0
int main()
{
   const char *colFmts[] = {" %-5.5s"," %-5.5s"," %-9.9s"};
   String r1[] = { "a101", "red",  "Java" };
   String r2[] = { "ab40", "gren", "Smalltalk" };
   String r3[] = { "ab9",  "blue", "Fortran" };
   String r4[] = { "ab09", "ylow", "Python" };
   String r5[] = { "ab1a", "blak", "Factor" };
   String r6[] = { "ab1b", "brwn", "C Sharp" };
   String r7[] = { "Ab1b", "pink", "Ruby" };
   String r8[] = { "ab1",  "orng", "Scheme" };

   String *rows[] = { r1, r2, r3, r4, r5, r6, r7, r8 };
   struct sTable table;
   table.rows = rows;
   table.n_rows = 8;
   table.n_cols = 3;

   sortTable(&table, "");
   printf("sort on col 0, ascending\n");
   printTable(&table, stdout, colFmts);

   sortTable(&table, "ro", 1, &cmprStrgs);
   printf("sort on col 0, reverse.special\n");
   printTable(&table, stdout, colFmts);

   sortTable(&table, "c", 1);
   printf("sort on col 1, ascending\n");
   printTable(&table, stdout, colFmts);

   sortTable(&table, "cr", 2, 1);
   printf("sort on col 2, reverse\n");
   printTable(&table, stdout, colFmts);
   return 0;
}
Пример #2
0
int StocksListCtrl::initVirtualListControl(int id, int col, bool asc)
{
    stock_panel_->updateHeader();
    /* Clear all the records */
    DeleteAllItems();

    wxListItem item;
    item.SetMask(wxLIST_MASK_IMAGE);
    item.SetImage(asc ? 3 : 2);
    SetColumn(col, item);

    m_stocks = Model_Stock::instance().find(Model_Stock::HELDAT(stock_panel_->accountID_));
    sortTable();

    int cnt = 0, selected_item = -1;
    for (const auto& stock: m_stocks)
    {
        if (id == stock.STOCKID)
        {
            selected_item = cnt;
            break;
        }
        ++cnt;
    }

    SetItemCount(m_stocks.size());
    return selected_item;
}
void mgcStatusTblTabOut(struct mgcStatusTbl *mst, FILE *f)
/* Write the table to a tab file */
{
struct mgcStatus *mgcStatus;
for (mgcStatus = sortTable(mst); mgcStatus != NULL;
     mgcStatus = mgcStatus->next)
    mgcStatusTabOut(mgcStatus, f);
}
void mgcStatusTblFullTabOut(struct mgcStatusTbl *mst, FILE *f)
/* Write the full-length clones in the table to a tab file */
{
struct mgcStatus *mgcStatus;
for (mgcStatus = sortTable(mst); mgcStatus != NULL;
     mgcStatus = mgcStatus->next)
    if (mgcStatus->status->state == MGC_STATE_FULL_LENGTH)
        mgcStatusTabOut(mgcStatus, f);
}
int mmBillsDepositsPanel::initVirtualListControl(int id)
{
    listCtrlAccount_->DeleteAllItems();

    wxListItem item;
    item.SetMask(wxLIST_MASK_IMAGE);
    item.SetImage(listCtrlAccount_->m_asc ? 4 : 3);
    listCtrlAccount_->SetColumn(listCtrlAccount_->m_selected_col, item);

    bills_.clear();
    const auto split = Model_Budgetsplittransaction::instance().get_all();
    for (const Model_Billsdeposits::Data& data
        : Model_Billsdeposits::instance().all(Model_Billsdeposits::COL_NEXTOCCURRENCEDATE))
    {
        if (transFilterActive_ && !transFilterDlg_->checkAll(data, split))
            continue;

        Model_Billsdeposits::Full_Data r(data);

        const Model_Payee::Data* payee = Model_Payee::instance().get(r.PAYEEID);
        if (payee) r.PAYEENAME = payee->PAYEENAME;
        const Model_Account::Data* account = Model_Account::instance().get(r.ACCOUNTID);
        if (account)
        {
            r.ACCOUNTNAME = account->ACCOUNTNAME;
            if (Model_Billsdeposits::type(r.TRANSCODE) == Model_Billsdeposits::TRANSFER)
            {
                Model_Account::Data* to_account = Model_Account::instance().get(r.TOACCOUNTID);
                if (to_account)
                    r.PAYEENAME = to_account->ACCOUNTNAME;
            }
        }

        if (Model_Attachment::NrAttachments(Model_Attachment::reftype_desc(Model_Attachment::BILLSDEPOSIT), r.BDID))
            r.NOTES = r.NOTES.Prepend(mmAttachmentManage::GetAttachmentNoteSign());
        bills_.push_back(r);
    }

    sortTable();

    int cnt = 0, selected_item = -1;
    for (const auto& entry: bills_)
    {
        if (id == entry.BDID)
        {
            selected_item = cnt;
            break;
        }
        ++cnt;
    }

    listCtrlAccount_->SetItemCount(static_cast<long>(bills_.size()));
    return selected_item;
}
//interpret the team status into my vareables
void Soccer_league::interpretGamesToTeamsStatus(vector<Team*>_team ,Game* game)
{
	//League::interpretGamesToTeamsStatus(_team,game);

	/*
	interpret game score to teame status
	*/
	for (int i=0 ; i<_team.size(); i++)
	{

		if (game->get_home().compare(_team[i]->get_teamName())==0)
		{
			/*
			home team
			update team status
			*/
			_team[i]->increment_gameCounter(1);
			_team[i]->set_fail(game->get_finalScoreGUEST());
			_team[i]->set_success(game->get_finalScoreHOME());
			if (game->get_finalScoreHOME()>game->get_finalScoreGUEST())
				_team[i]->increment_leaguePoints(3);
			else _team[i]->increment_leaguePoints(0);
			if (game->get_finalScoreHOME()==game->get_finalScoreGUEST())
			_team[i]->increment_leaguePoints(1);
		}
		if (game->get_guest().compare(_team[i]->get_teamName())==0)
		{
			/*
			guest team
			update team status
			*/
			_team[i]->increment_gameCounter(1);
			_team[i]->set_fail(game->get_finalScoreHOME());
			_team[i]->set_success(game->get_finalScoreGUEST());
			if (game->get_finalScoreHOME()<game->get_finalScoreGUEST())
				_team[i]->increment_leaguePoints(3);
			else _team[i]->increment_leaguePoints(0);
			if (game->get_finalScoreHOME()==game->get_finalScoreGUEST())
				_team[i]->increment_leaguePoints(1);
		}
		
		
	}
	sortTable(_team);
}
Пример #7
0
//-------------------------------------------------------------------------------------------------
bool Huffman::createTable(std::vector<unsigned int> symbols, std::vector<unsigned int> counts)
{
	HuffmanTree tree; // Tree for creating the table
	
	// Build the tree
	tree.buildTree(symbols, counts);
	
	// Get the table from the tree
	if(! tree.getTable((*m_pSymbols), (*m_pCodes)))
	{
		std::cerr << "Error in createTable: tree is empty" << std::cout;
		return false;
	}

	//Sort the table by code length for faster average lookup
	sortTable();

	return true;
}
Пример #8
0
int ReportTableBase::getData(ostream &ss, const ReportTableData &reportTableData, char fieldSep, char rowSep)
{
  // load table
  if(loadTable() == ERROR)
    return ERROR;

  m_sortColumn = reportTableData.sortColumn;
  m_direction  = reportTableData.direction;

  // sort the table, if needed
  if(m_sortColumn >= 0 &&  m_cells.size() && m_sortColumn < m_cells[0].size() )
    sortTable();

  // filter table, for a subset of rows
  applyFilter(reportTableData.filterCol, reportTableData.filterText);

  // iterate data
  bool first = true;
  TableIterator ti = begin();
  // move to desired item
  ti += reportTableData.startRow;
  int rows = reportTableData.rows;
  // cycle thru all rows
  for(; ti != end() && (rows > 0 || rows == -1); ti++, (rows != -1 ? rows-- : rows) ) {
    // put row separator if not the first row
    if(!first)
      ss << rowSep;
    // get the row
    vector<string> &row = **ti;

    // process the row, for the required items
    for(int i = 0 ; i < row.size() ; i++) {
      // output col separator if not the first item
      if(i) ss << fieldSep;
      // output the cell contents
      ss << row[i];
    }
    // tell it's not the first row
    first = false;
  }
}
Пример #9
0
void find_apt(COMMAND cmd, ApartmentTable db) {
    /*
     * find_apt
     * Printing the apartments that matched the cmd->kwargs filter
     */

    // Pre sorting the array tto enable sorting view
    BOOL isAllocated = FALSE;
    ApartmentTable ptr = db;
    if (isKeyExists("s", cmd.kwargs)) {
        // ASC - low to high
        ptr = sortTable(db, FALSE);
        isAllocated = TRUE;
    } else if (isKeyExists("sr", cmd.kwargs)) {
        // DESC - high to low
        ptr = sortTable(db, TRUE);
        isAllocated = TRUE;
    }

    for (int i = 0; i < db.size; i++) {
        Apartment tmp = ptr.arr[i];
        time_t d1, d2;
        char *pt;
        // if apartment not match the filter, we continue to the next

        pt = getValueByKey("MaxPrice", cmd.kwargs);
        int price = (int) (pt ? atoi(pt) : NULL);
        if (price && tmp.price > price)
            continue;

        pt = getValueByKey("MinNumRooms", cmd.kwargs);
        int rooms = (int) (pt ? atoi(pt) : NULL);
        if (rooms && tmp.rooms < rooms)
            continue;

        pt = getValueByKey("MaxNumRooms", cmd.kwargs);
        rooms = (int) (pt ? atoi(pt) : NULL);
        if (rooms && tmp.rooms > rooms)
            continue;


        // return all apartments that was inserted @dayBack ago
        pt = getValueByKey("Enter", cmd.kwargs);
        int dayBack = (int) (pt ? atoi(pt) : NULL);
        if (dayBack > 0) {
            struct tm entryDate;
            int now = (int) time(NULL);
            now = now - (84600 * dayBack);

            entryDate.tm_hour = 23;
            entryDate.tm_min = 59;
            entryDate.tm_sec = 59;
            entryDate.tm_year = tmp.entry_year + 100;
            entryDate.tm_mon = tmp.entry_month - 1;
            entryDate.tm_mday = tmp.entry_day;

            d1 = mktime(&entryDate);
            if (now - d1  > 0)
                continue;
        }

        char* date = getValueByKey("Date", cmd.kwargs);
        if (date != NULL) {
            struct tm endDate;
            struct tm startDate;
            endDate.tm_hour = 23;
            endDate.tm_min = 59;
            endDate.tm_sec = 59;
            endDate.tm_year = atoi(substring(date, 5 , 4)) - 1900;
            endDate.tm_mon = atoi(substring(date, 3 , 2)) - 1;
            endDate.tm_mday = atoi(substring(date, 1 , 2));

            startDate.tm_hour = 23;
            startDate.tm_min = 59;
            startDate.tm_sec = 59;
            startDate.tm_year = tmp.entry_year + 100;
            startDate.tm_mon = tmp.entry_month - 1;
            startDate.tm_mday = tmp.entry_day;

            d1 = mktime(&endDate);
            d2 = mktime(&startDate);
            if (d2 - d1 > 0)
                continue;
        }

        printApartment(tmp);
    }

    if (isAllocated == TRUE) {
        // free the memory that allocated if the array is sorted
        //free(ptr.arr);
    }
}
Пример #10
0
/* 
 * Compile the typing data from each of the given files into  a single file.
 * 
 * outfileName: The file to which the new typing data will be written.
 * filenames: The names of each file to be read.
 * multipliers: The multipliers corresponding with the filenames.
 * length: Length of filenames and multipliers.
 * unit: The unit size of the strings to be read (characters=1, digraphs=2, etc).
 * max: The maximum number of strings that can be put into the file.
 * 
 * Return Codes
 * 1: Null file.
 */
int compileTypingData(char *const outfileName,
                        char *const filenames[],
                        const int multipliers[],
                        const size_t length,
                        const int unit,
                        const size_t max)
{
	int aMultiplier;
	char *aFilename;
	Keystroke aKey;
	char *aValueString;
	int aValue;
	void outputTypingData(const KeystrokeValueTable *table, FILE *outfile, const size_t max);
	const int linelen = 100;
	char line[linelen];
    void includeKeyInTable(Keystroke aKey, Value aValue, KeystrokeValueTable *table);	

	FILE *outfile = fopen(outfileName, "w");
	if (outfile == NULL) {
		fprintf(stderr, "Error: null file %s.\n", outfileName);
		return 1;
	}
	KeystrokeValueTable *kvTable = createTable();
	if (kvTable == NULL) {
		internalError(014);
		fclose(outfile);
		return 1;
	}

	size_t i;
	for (i = 0; i < length; ++i) {
		aMultiplier = multipliers[i];
		aFilename = filenames[i];
		printf("file %s,  multiplier %d\n", aFilename, aMultiplier);

		
		if (aMultiplier == 0)
			continue;
		
		FILE *file = fopen(aFilename, "r");
		if (file == NULL) {
			fprintf(stderr, "Error: null file %s.\n", aFilename);
			fclose(outfile);
			free(kvTable->kvt_table);
			kvTable->kvt_table = NULL;
			free(kvTable);
			return 1;
		}
		
		while (fgets(line, linelen-1, file)) {			
			line[linelen-1] = '\0';
			line[unit] = 0;
			aKey = line;
			aValueString = line + unit + 1;
			aValue = atoi(aValueString);
			includeKeyInTable(aKey, aValue, kvTable);
		}
		
		fclose(file);
	}

	sortTable(kvTable, kvReverseComparingValues);
	outputTypingData(kvTable, outfile, max);
	fclose(outfile);
	free(kvTable);
	
	return 0;
}
Пример #11
0
/* Reads typing data from allChars.txt and allDigraphs.txt.
 * 
 * Produces monographs and digraphs involving backspace by assuming that all 
 * characters are equally mistyped.
 */
void initTypingData()
{
	uint64_t i;
	FILE *file;
	
	file = fopen("allDigraphs.txt", "r");

	if( file == NULL ) {
		internalError( 7 );
		return;
	}
	if( digraphs == NULL ) {
		digraphs = createTable();
		if( digraphs == NULL ) {
			return;
		}
	}
	if( monographs == NULL ) {
		monographs = createTable();
		if( monographs == NULL ) {
			return;
		}
	}
	char key1;
	char key2;
	Value value;
	int c = '\0';
	i = 0;
	totalDi = 0;
	while (TRUE) {
		/* Skip any extra newlines. */
		while ((c = getc(file)) == '\n')
			;
		if (c == EOF) break;

		if (c == '\\') c = convertEscapeChar(getc(file));
		if (c == 0) {
			fprintf(stderr, "Error: In digraph file, unknown escape character \\%c.\n", c);
			fclose(file);
			return;
		}
		key1 = c;

		c = getc(file);
		if (c == '\\') c = convertEscapeChar(getc(file));
		if (c == 0) {
			fprintf(stderr, "Error: In digraph file, unknown escape character \\%c.\n", c);
			fclose(file);
			return;
		}
		key2 = c;
		
		c = getc(file); /* Skip the space between the digraph and the value. */
		
		if (strchr(keysToInclude, key1) && 
				strchr(keysToInclude, key2)) {
			value = 0;
			while ((c = getc(file)) != EOF && c >= '0' && c <= '9') {
				value *= 10;
				value += c - '0';
			}
			
			value /= DIVISOR;
			totalDi += value;

			char keys[3] = { key1, key2, '\0' };

			includeKeyInTable( keys, value, digraphs );
		}

		/* Skip all extra characters. */
		while (c != EOF && c != '\n')
			c = getc(file);
	}
	fclose(file);
	

	file = fopen("allChars.txt", "r");
	if( file == NULL ) {
		internalError( 8 );
		return;
	}
	c = '\0';
	i = 0;
	totalMon = 0;
	while (TRUE) {
		/* Skip any extra newlines. */
		while ((c = getc(file)) == '\n')
			;
		if (c == EOF) break;
		
		if (c == '\\') c = convertEscapeChar(getc(file));
		if (c == 0) {
			fprintf(stderr, "Error: In monograph file, unknown escape character \\%c.\n", c);
			return;
		}
		key1 = c;
		
		c = getc(file); /* Skip the space between the char and the value. */
		
		if (strchr(keysToInclude, key1)) {
			value = 0;
			while ((c = getc(file)) != EOF && c >= '0' && c <= '9') {
				value *= 10;
				value += c - '0';
			}
			
			value /= DIVISOR;
			totalMon += value;

			char keys[2] = { key1, '\0' };

			includeKeyInTable( keys, value, monographs );
		}

		/* Skip all extra characters. */
		while (c != EOF && c != '\n')
			c = getc(file);
	}
	
	fclose(file);
	
	/* If necessary, add the stats for backspace. */
	if (strchr(keysToInclude, '\b')) {
		const uint64_t used = monographs->kvt_used;
		KeystrokeValue *theTable = monographs->kvt_table;
		KeystrokeValue kv;
		Value theValue;
		Keystroke theStroke;
		char theStrokeToAdd[3] = { '\0', '\0', '\0' };
		char theKey;

		/* Add backpace to the digraph list. */
		for (i = 0; i < used; ++i) {
			kv = theTable[i];
			theValue = kv.theValue;
			theStroke = kv.theStroke;
			theKey = theStroke[0];
			value = theValue * ERROR_RATE_PERCENT / 100;
			theStrokeToAdd[0] = '\b';
			theStrokeToAdd[1] = theKey;
			includeKeyInTable(theStrokeToAdd, value, digraphs);
			theStrokeToAdd[0] = theKey;
			theStrokeToAdd[1] = '\b';
			includeKeyInTable(theStrokeToAdd, value, digraphs);
		}
	 
		/* Add backspace to the monograph list. */
   		theStrokeToAdd[0] = '\b';
   		theStrokeToAdd[1] = '\0';
		value = totalMon * ERROR_RATE_PERCENT / 100;
   		includeKeyInTable(theStrokeToAdd, value, monographs);
	}
	
	sortTable(digraphs, kvComparingValues);
	sortTable(monographs, kvComparingValues);
}