#include <Optimizer.h>
Public Member Functions | |
Bin (Params::Size_t capacity) | |
Bin's constructor. | |
Bin (const std::vector< const SizeName * > &sn) | |
Adds items from a given vector of SizeName and sets the capacity as the sum of the sizes. | |
unsigned | Count () const |
Returns the number of items. | |
const SizeName * | Item (int i) const |
Returns the ith item. | |
std::vector< const SizeName * > & | Items () |
Returns all items (vector of items). | |
const std::vector< const SizeName * > & | Items () const |
Returns all items (vector of items); const version. | |
Params::Size_t | Used () const |
Returns the total space occupied by the items. | |
Params::Size_t | Free () const |
Returns the total space available. | |
Params::Size_t | Capacity () const |
Returns the bin's capacity. | |
void | AddItem (const SizeName *i) |
Add an item to the current bin. | |
void | ReplaceItem (int i, const SizeName *item) |
Replace the ith item with a new item. | |
void | DelItem (int i) |
Remove the ith item. | |
void | AddAllItems (Bin &b) |
Add all items of a given bin. | |
void | DelAllItems () |
Remove all items of the current bin. | |
const SizeName * | operator[] (int i) const |
Returns the ith item. | |
bool | operator< (const Bin &bin) const |
Overloaded operator <. | |
bool | operator== (const Bin &bin) const |
Compares two bins in a relaxed fashion. | |
std::vector< const SizeName * > ::iterator | begin () |
Pointer (iterator) to the first item of m_items (begin()). | |
std::vector< const SizeName * > ::iterator | end () |
Pointer (iterator) to the last item plus one of m_items (end()). | |
Private Attributes | |
std::vector< const SizeName * > | m_items |
Params::Size_t | m_sum_sizes |
Params::Size_t | m_capacity |
Friends | |
bool | Intersect (Bin &a, std::vector< Bin >::iterator g1, std::vector< Bin >::iterator g2, std::vector< const SizeName * > &unassigned) |
Verify if a bin contains items in common with a set of bins, and fill unassigned with the non-duplicate (non-common) items. |
Bin::Bin | ( | Params::Size_t | capacity | ) | [inline] |
Bin's constructor.
Bin::Bin | ( | const std::vector< const SizeName * > & | sn | ) | [inline] |
Adds items from a given vector of SizeName and sets the capacity as the sum of the sizes.
References AddItem(), m_capacity, and Used().
unsigned Bin::Count | ( | ) | const [inline] |
Returns the number of items.
References m_items.
Referenced by AddAllItems(), Intersect(), operator<(), and operator==().
std::vector<const SizeName*>& Bin::Items | ( | ) | [inline] |
const std::vector<const SizeName*>& Bin::Items | ( | ) | const [inline] |
Params::Size_t Bin::Used | ( | ) | const [inline] |
Params::Size_t Bin::Free | ( | ) | const [inline] |
Returns the total space available.
References Capacity(), and Used().
Referenced by operator<(), and operator==().
Params::Size_t Bin::Capacity | ( | ) | const [inline] |
Returns the bin's capacity.
Likely, the bin's capacity is the same as m_params::m_target. However, gaffitter can be adapted to support variable bin capacity, and so different bins might report different capacity.
References m_capacity.
Referenced by Free().
void Bin::AddItem | ( | const SizeName * | i | ) | [inline] |
Add an item to the current bin.
References m_items, m_sum_sizes, and SizeName::Size().
Referenced by AddAllItems(), Bin(), Split::Evolve(), and BestFit::Evolve().
void Bin::ReplaceItem | ( | int | i, | |
const SizeName * | item | |||
) | [inline] |
void Bin::DelItem | ( | int | i | ) | [inline] |
void Bin::AddAllItems | ( | Bin & | b | ) | [inline] |
void Bin::DelAllItems | ( | ) | [inline] |
bool Bin::operator< | ( | const Bin & | bin | ) | const [inline] |
bool Bin::operator== | ( | const Bin & | bin | ) | const [inline] |
Compares two bins in a relaxed fashion.
To achieve better performance, this function only compares the free space (Free()) and the number of bins (Count()).
For a complete comparison, this function should also verify if the two bins contain exactly the same items.
References AlmostEqual(), Count(), and Free().
std::vector<const SizeName*>::iterator Bin::begin | ( | ) | [inline] |
Pointer (iterator) to the first item of m_items (begin()).
References m_items.
Referenced by Intersect().
std::vector<const SizeName*>::iterator Bin::end | ( | ) | [inline] |
Pointer (iterator) to the last item plus one of m_items (end()).
References m_items.
Referenced by Intersect().
bool Intersect | ( | Bin & | a, | |
std::vector< Bin >::iterator | g1, | |||
std::vector< Bin >::iterator | g2, | |||
std::vector< const SizeName * > & | unassigned | |||
) | [friend] |
Verify if a bin contains items in common with a set of bins, and fill unassigned
with the non-duplicate (non-common) items.
[in] | a | Bin to verify |
[in] | g1 | First bin of the set of bins |
[in] | g2 | Last bin of the set of bins |
[out] | unassigned | List where the non-common items will be put. |
std::vector<const SizeName*> Bin::m_items [private] |
Vector of items.
Referenced by AddItem(), begin(), Count(), DelAllItems(), DelItem(), end(), Item(), Items(), operator[](), and ReplaceItem().
Params::Size_t Bin::m_sum_sizes [private] |
Total occupied size by the items.
Referenced by AddItem(), DelAllItems(), DelItem(), ReplaceItem(), and Used().
Params::Size_t Bin::m_capacity [private] |
Bin's capacity.
Referenced by Bin(), and Capacity().