int CountTree(int n)
{
	if(n <= 1)
		return 1 ;
	int sum = 0 ;
	int root , left , right ;
	for(root = 1 ; root <= n ; root++)
	{
		left = CountTree(root - 1) ;
		right = CountTree(n - root) ;
		sum = sum + left*right ;
	}
	return sum ;
}
예제 #2
0
void ImageScanThread<DBFS>::CountFiles(const QStringList &paths)
{
    // Get exclusions as comma-seperated list using glob chars * and ?
    QString excPattern = gCoreContext->GetSetting("GalleryIgnoreFilter", "");

    // Combine into a single regexp
    excPattern.replace(".", "\\."); // Preserve "."
    excPattern.replace("*", ".*");  // Convert glob wildcard "*"
    excPattern.replace("?", ".");   // Convert glob wildcard "?"
    excPattern.replace(",", "|");   // Convert list to OR's

    QString pattern = QString("^(%1)$").arg(excPattern);
    m_exclusions = REGEXP(pattern);

    LOG(VB_FILE, LOG_DEBUG, QString("Exclude regexp is \"%1\"").arg(pattern));

    // Lock counts until counting complete
    QMutexLocker locker(&m_mutexProgress);
    m_progressCount       = 0;
    m_progressTotalCount  = 0;

    // Use global image filters
    QDir dir = m_dir;
    foreach(const QString &sgDir, paths)
    {
        // Ignore missing dirs
        if (dir.cd(sgDir))
            CountTree(dir);
    }
    // 0 signifies a scan start
    Broadcast(0);
}
예제 #3
0
/*!
 \brief Counts images in a list of subtrees
 \param paths List of dirs
*/
void ImageScanThread::CountFiles(QStringList paths)
{
    // Get exclusions as comma-seperated list using glob chars * and ?
    QString excPattern = gCoreContext->GetSetting("GalleryIgnoreFilter", "");

    // Combine into a single regexp
    excPattern.replace(".", "\\."); // Preserve "."
    excPattern.replace("*", ".*");  // Convert glob wildcard "*"
    excPattern.replace("?", ".");  // Convert glob wildcard "?"
    excPattern.replace(",", "|");   // Convert list to OR's

    QString pattern = QString("^(%1)$").arg(excPattern);
    m_exclusions = QRegExp(pattern);

    LOG(VB_FILE, LOG_DEBUG, QString("%1: Exclude regexp is \"%2\"")
        .arg(objectName(), pattern));

    QMutexLocker locker(&m_mutexProgress);
    m_progressCount       = 0;
    m_progressTotalCount  = 0;

    // Release lock to broadcast
    locker.unlock();
    BroadcastStatus("SCANNING");
    locker.relock();

    // Use global image filters
    QDir dir = m_dir;
    foreach(const QString &sgDir, paths)
    {
        dir.cd(sgDir);
        CountTree(dir);
    }
예제 #4
0
void ImageScanThread<DBFS>::CountTree(QDir &dir)
{
    QFileInfoList files = dir.entryInfoList();

    foreach(const QFileInfo &fileInfo, files)
    {
        if (fileInfo.isFile())
            ++m_progressTotalCount;
        // Ignore excluded dirs and missing dirs
        else if (!m_exclusions.match(fileInfo.fileName()).hasMatch()
                 && dir.cd(fileInfo.fileName()))
        {
            CountTree(dir);
            dir.cdUp();
        }
    }
}
예제 #5
0
/*!
 \brief Counts images in a dir subtree
 \details Ignores files/dirs that match exclusions regexp
 \param dir Parent of subtree
*/
void ImageScanThread::CountTree(QDir &dir)
{
    QFileInfoList files = dir.entryInfoList();

    foreach(const QFileInfo &fileInfo, files)
    {
        if (fileInfo.isFile())
            ++m_progressTotalCount;
        else if (m_exclusions.exactMatch(fileInfo.fileName()))
            LOG(VB_GENERAL, LOG_INFO, QString("%1: Excluding %2")
                .arg(objectName(), fileInfo.filePath()));
        else
        {
            dir.cd(fileInfo.fileName());
            CountTree(dir);
            dir.cdUp();
        }
    }
}
예제 #6
0
void ImageScanThread<DBFS>::CountTree(QDir &dir)
{
    QFileInfoList files = dir.entryInfoList();

    foreach(const QFileInfo &fileInfo, files)
    {
        // Ignore excluded dirs/files
        if (MATCHES(m_exclusions, fileInfo.fileName()))
            continue;

        if (fileInfo.isFile())
            ++m_progressTotalCount;
        // Ignore missing dirs
        else if (dir.cd(fileInfo.fileName()))
        {
            CountTree(dir);
            dir.cdUp();
        }
    }
}
int main()
{
	int n = CountTree(9) ;
	printf("%d is the number of trees\n", n );
}