Exemple #1
0
 bool it_should_calculate_the_original_cost ()
 {
   bool answ;
   unsigned int set_size = 12;
   ElementSet original_set ("", set_size, 100);
   bool * is_fixed = new bool[set_size];
   for (unsigned int i = 0; i < set_size; i++)
     if (i < 5)
       is_fixed[i] = true;
     else
       is_fixed[i] = false;
   Partition part (&original_set, is_fixed);
   delete[] is_fixed;
   ElementSet * fixed_set = part.get_fixed_elm_set ();
   ElementSubset part_subset ("", fixed_set);
   part_subset.add_element (0);
   part_subset.add_element (2);
   part_subset.add_element (4);
   PartitionNode P (&part, &part_subset);
   SubsetSum orig_f (&original_set);
   PartCost P_f (&orig_f, &P);
   ElementSubset X ("", part.get_unfixed_elm_set ());
   X.add_element (0);
   X.add_element (2);
   X.add_element (3);
   ElementSubset * orig_X = P.get_original_subset (&X);
   answ = orig_f.cost (orig_X) == P_f.cost (&X);
   delete orig_X;
   return answ;
 }
Exemple #2
0
bool PartitionTable::getUnallocatedRange(const Device& d, PartitionNode& parent, qint64& start, qint64& end)
{
    if (d.type() == Device::Disk_Device) {
        const DiskDevice& device = dynamic_cast<const DiskDevice&>(d);
        if (!parent.isRoot()) {
            Partition* extended = dynamic_cast<Partition*>(&parent);

            if (extended == nullptr) {
                qWarning() << "extended is null. start: " << start << ", end: " << end << ", device: " << device.deviceNode();
                return false;
            }

            // Leave a track (cylinder aligned) or sector alignment sectors (sector based) free at the
            // start for a new partition's metadata
            start += device.partitionTable()->type() == PartitionTable::msdos ? device.sectorsPerTrack() : PartitionAlignment::sectorAlignment(device);

            // .. and also at the end for the metadata for a partition to follow us, if we're not
            // at the end of the extended partition
            if (end < extended->lastSector())
                end -= device.partitionTable()->type() == PartitionTable::msdos ? device.sectorsPerTrack() : PartitionAlignment::sectorAlignment(device);
        }

        return end - start + 1 >= PartitionAlignment::sectorAlignment(device);
    } else if (d.type() == Device::LVM_Device) {
        if (end - start + 1 > 0) {
            return true;
        }
    }
    return false;
}
QModelIndex
PartitionModel::index( int row, int column, const QModelIndex& parent ) const
{
    PartitionNode* parentPartition = parent.isValid()
                                     ? static_cast< PartitionNode* >( partitionForIndex( parent ) )
                                     : static_cast< PartitionNode* >( m_device->partitionTable() );
    if ( !parentPartition )
        return QModelIndex();
    auto lst = parentPartition->children();
    if ( row < 0 || row >= lst.count() )
        return QModelIndex();
    if ( column < 0 || column >= ColumnCount )
        return QModelIndex();
    Partition* partition = parentPartition->children().at( row );
    return createIndex( row, column, partition );
}
void
PartitionIterator::operator++()
{
    if ( !m_current )
        return;
    if ( m_current->hasChildren() )
    {
        // Go to the first child
        m_current = static_cast< Partition* >( m_current->children().first() );
        return;
    }
    PartitionNode* parent = m_current->parent();
    Partition* successor = parent->successor( *m_current );
    if ( successor )
    {
        // Go to the next sibling
        m_current = successor;
        return;
    }
    if ( parent->isRoot() )
    {
        // We reached the end
        m_current = nullptr;
        return;
    }
    // Try to go to the next sibling of our parent

    PartitionNode* grandParent = parent->parent();
    Q_ASSERT( grandParent );
    // If parent is not root, then it's not a PartitionTable but a
    // Partition, we can static_cast it.
    m_current = grandParent->successor( *static_cast< Partition* >( parent ) );
}