Esempio n. 1
0
void Letterbox::loadFile()
{
	if (m_filename.isEmpty())
		return;

	QString filename(m_filename.right(m_filename.length() - m_filename.lastIndexOf("/") - 1));
	statusBar()->showMessage(tr("Loading %1...").arg(filename));
	qApp->processEvents();
	
	m_list.clear();
	m_answers.clear();
	m_clueResults.clear();

	QFile file(m_filename);
	if (!file.exists())
	{
		QMessageBox::critical(this, tr("Error Loading Letterbox List - Quackle Letterbox"), tr("Filename %1 does not exist").arg(m_filename));
		return;
	}

	if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
	{
		QMessageBox::critical(this, tr("Error Loading Letterbox List - Quackle Letterbox"), tr("%1 cannot be opened.").arg(filename));
		return;
	}

	int startAt = 0;

	QTextStream stream(&file);
	QString line;

	m_initializationChuu = true;

	bool firstLine = true;

	while (!stream.atEnd())
	{
		line = stream.readLine().trimmed().toUpper();

		if (firstLine)
		{
			if (line.left(10) == "\" RESUME: ")
				startAt = line.right(line.length() - 10).toInt();

			firstLine = false;
		}

		line.remove('#');

		QString letters = line;
		QString comment;

		int quoteMarkIndex = line.indexOf("\"");
		if (quoteMarkIndex >= 0)
		{
			letters = line.left(quoteMarkIndex).trimmed();
			comment = line.right(line.length() - quoteMarkIndex - 1).trimmed();
		}

		if (letters.isEmpty())
			continue;

		m_list += letters;

		m_clueResults.append(parseComment(comment));
		m_clueResults.last().clue = clueFor(letters);
	}

	file.close();

	if (!dictCheck())
		return;

	jumpTo(startAt);

	statusBar()->showMessage(tr("Loaded list `%1' of length %2.").arg(filename).arg(m_clueResults.count()));
	setCaption(filename);

	m_initializationChuu = false;
	setModified(false);

	prepareQuiz();
	pause(true);
}
Esempio n. 2
0
void dictHashSummary(FICL_VM *pVM)
{
    FICL_DICT *dp = vmGetDict(pVM);
    FICL_HASH *pFHash;
    FICL_WORD **pHash;
    unsigned size;
    FICL_WORD *pFW;
    unsigned i;
    int nMax = 0;
    int nWords = 0;
    int nFilled;
    double avg = 0.0;
    double best;
    int nAvg, nRem, nDepth;

    dictCheck(dp, pVM, 0);

    pFHash = dp->pSearch[dp->nLists - 1];
    pHash  = pFHash->table;
    size   = pFHash->size;
    nFilled = size;

    for (i = 0; i < size; i++)
    {
        int n = 0;
        pFW = pHash[i];

        while (pFW)
        {
            ++n;
            ++nWords;
            pFW = pFW->link;
        }

        avg += (double)(n * (n+1)) / 2.0;

        if (n > nMax)
            nMax = n;
        if (n == 0)
            --nFilled;
    }

    /* Calc actual avg search depth for this hash */
    avg = avg / nWords;

    /* Calc best possible performance with this size hash */
    nAvg = nWords / size;
    nRem = nWords % size;
    nDepth = size * (nAvg * (nAvg+1))/2 + (nAvg+1)*nRem;
    best = (double)nDepth/nWords;

    sprintf(pVM->pad, 
        "%d bins, %2.0f%% filled, Depth: Max=%d, Avg=%2.1f, Best=%2.1f, Score: %2.0f%%", 
        size,
        (double)nFilled * 100.0 / size, nMax,
        avg, 
        best,
        100.0 * best / avg);

    ficlTextOut(pVM, pVM->pad, 1);

    return;
}