Пример #1
0
void PartialSolver::boundaryFinder()
{
    for(list<Puzzle>::iterator it = solved.begin(); it!=solved.end(); it++)
    {
        stringstream boundkey, temp;
        for(int x=0; x<number; x++)
        {
            boundkey << (*it).visableScore((*it).getColumn(x));
            temp << (*it).visableScore((*it).getColumn(x, true));
        }
        boundkey <<","<< temp.str() <<",";
        temp.str("");
        for(int y=0; y<number; y++)
        {
            boundkey << (*it).visableScore((*it).getRow(y));
            temp << (*it).visableScore((*it).getRow(y, true));
        }
        boundkey <<","<< temp.str();
        string key = boundkey.str();
        if(boundMap.find(key )!=boundMap.end())
        {
            boundMap[key]++;
        }
        else
        {
            boundMap[key] = 1;
        }
    }

    int totalKeys(0), totalNum(0), totalUnique(0), upperLimit(0);
    ofstream file("BoundaryKeys.csv"), uniqueFile("UniqueKeys.csv");
    file<<"Top,Bottom,Left,Right,#"<<endl;
    map<string,int>::iterator it = boundMap.begin();
    for(; it!=boundMap.end(); it++)
    {
        int num = (*it).second;
        file<<(*it).first<<", "<<num<<endl;
        totalNum += num;
        totalKeys++;
        if(num==1)
        {
            totalUnique++;
            uniqueFile<<(*it).first<<endl;
        }
        if(num>upperLimit)
            upperLimit = num;

    }
    file.close();
    file.open("BoundaryStats.csv");
    file<<"Total Number of Latin Squares, "<<totalNum<<endl
        <<"Total Number of Boundaries, "<<totalKeys<<endl
        <<"Total Unique Boundaries, "<<totalUnique<<endl
        <<"Upper Limit of Branching, "<<upperLimit<<endl;
    file.close();
}
Пример #2
0
static KLockFile::LockResult lockFile(const QString &lockFile, KDE_struct_stat &st_buf,
        bool &linkCountSupport, const KComponentData &componentData)
{
  QByteArray lockFileName = QFile::encodeName( lockFile );
  int result = KDE_lstat( lockFileName, &st_buf );
  if (result == 0)
     return KLockFile::LockFail;

  KTemporaryFile uniqueFile(componentData);
  uniqueFile.setFileTemplate(lockFile);
  if (!uniqueFile.open())
     return KLockFile::LockError;
  uniqueFile.setPermissions(QFile::ReadUser|QFile::WriteUser|QFile::ReadGroup|QFile::ReadOther);

  char hostname[256];
  hostname[0] = 0;
  gethostname(hostname, 255);
  hostname[255] = 0;
  QString componentName = componentData.componentName();

  QTextStream stream(&uniqueFile);
  stream << QString::number(getpid()) << endl
      << componentName << endl
      << hostname << endl;
  stream.flush();

  QByteArray uniqueName = QFile::encodeName( uniqueFile.fileName() );

  // Create lock file
  result = ::link( uniqueName, lockFileName );
  if (result != 0)
     return KLockFile::LockError;

  if (!linkCountSupport)
     return KLockFile::LockOK;

  KDE_struct_stat st_buf2;
  result = KDE_lstat( uniqueName, &st_buf2 );
  if (result != 0)
     return KLockFile::LockError;

  result = KDE_lstat( lockFileName, &st_buf );
  if (result != 0)
     return KLockFile::LockError;

  if (st_buf != st_buf2 || S_ISLNK(st_buf.st_mode) || S_ISLNK(st_buf2.st_mode))
  {
     // SMBFS supports hardlinks by copying the file, as a result the above test will always fail
     // cifs increases link count artifically but the inodes are still different
     if ((st_buf2.st_nlink > 1 ||
         ((st_buf.st_nlink == 1) && (st_buf2.st_nlink == 1))) && (st_buf.st_ino != st_buf2.st_ino))
     {
        linkCountSupport = testLinkCountSupport(uniqueName);
        if (!linkCountSupport)
           return KLockFile::LockOK; // Link count support is missing... assume everything is OK.
     }
     return KLockFile::LockFail;
  }

  return KLockFile::LockOK;
}