QVector<quint8> EncryptorPrivate::mergeSort(const QVector<quint8> &array, quint32 salt, quint64 k)
{
    int length = array.size();

    if (length <= 1) {
        return array;
    }

    int middle = length / 2;
    QVector<quint8> left = array.mid(0, middle);
    QVector<quint8> right = array.mid(middle);

    left = mergeSort(left, salt, k);
    right = mergeSort(right, salt, k);

    int leftptr = 0;
    int rightptr = 0;

    QVector<quint8> sorted;
    sorted.fill(0, length);
    for (int i = 0; i < length; ++i) {
        if (rightptr == right.size() || (leftptr < left.size() && randomCompare(left[leftptr], right[rightptr], salt, k) <= 0)) {
            sorted[i] = left[leftptr++];
        } else if (leftptr == left.size() || (rightptr < right.size() && randomCompare(right[rightptr], left[leftptr], salt, k) <= 0)) {
            sorted[i] = right[rightptr++];
        }
    }
    return sorted;
}
Esempio n. 2
0
QVector<double> mergesort(QVector<double> &v){
    int size = v.size();
    if (size > 1) {
        QVector<double> v1 = v.mid(0, size/2);
        QVector<double> v2 = v.mid(size/2, size-(size/2));
        QVector<double> r1 = mergesort(v1);
        QVector<double> r2 = mergesort(v2);
        QVector<double> r = merge(r1, r2);
        return r;
    }
    else return v;

}
Esempio n. 3
0
QgsLineString::QgsLineString( const QVector<double> &x, const QVector<double> &y, const QVector<double> &z, const QVector<double> &m )
{
  mWkbType = QgsWkbTypes::LineString;
  int pointCount = std::min( x.size(), y.size() );
  if ( x.size() == pointCount )
  {
    mX = x;
  }
  else
  {
    mX = x.mid( 0, pointCount );
  }
  if ( y.size() == pointCount )
  {
    mY = y;
  }
  else
  {
    mY = y.mid( 0, pointCount );
  }
  if ( !z.isEmpty() && z.count() >= pointCount )
  {
    mWkbType = QgsWkbTypes::addZ( mWkbType );
    if ( z.size() == pointCount )
    {
      mZ = z;
    }
    else
    {
      mZ = z.mid( 0, pointCount );
    }
  }
  if ( !m.isEmpty() && m.count() >= pointCount )
  {
    mWkbType = QgsWkbTypes::addM( mWkbType );
    if ( m.size() == pointCount )
    {
      mM = m;
    }
    else
    {
      mM = m.mid( 0, pointCount );
    }
  }
}
Esempio n. 4
0
void ServerWidget::ping(){
    textEdit->append("\nPING");

    QStringList adressList = getAdressList();
    QVector<int> portList = getPortList();

    adressList = adressList.mid(0, nbRoles);
    portList = portList.mid(0, nbRoles);

    QMetaObject::invokeMethod(server, "setupPlayers", Qt::AutoConnection,
                              Q_ARG(QStringList, adressList),
                              Q_ARG(QVector<int>, portList));
    QMetaObject::invokeMethod(server, "ping", Qt::AutoConnection);

    // Direct calls like this would execute the function in the current thread
//    server->setupPlayers(adressList, portList);
//    server->ping();
}