Bin Class Reference

A Bin is a collection of items/files (a "volume"). More...

#include <Optimizer.h>

Collaboration diagram for Bin:

Collaboration graph
[legend]

List of all members.

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 SizeNameItem (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 SizeNameoperator[] (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.


Detailed Description

A Bin is a collection of items/files (a "volume").

Constructor & Destructor Documentation

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().


Member Function Documentation

unsigned Bin::Count (  )  const [inline]

Returns the number of items.

References m_items.

Referenced by AddAllItems(), Intersect(), operator<(), and operator==().

const SizeName* Bin::Item ( int  i  )  const [inline]

Returns the ith item.

References m_items.

std::vector<const SizeName*>& Bin::Items (  )  [inline]

Returns all items (vector of items).

References m_items.

const std::vector<const SizeName*>& Bin::Items (  )  const [inline]

Returns all items (vector of items); const version.

References m_items.

Params::Size_t Bin::Used (  )  const [inline]

Returns the total space occupied by the items.

References m_sum_sizes.

Referenced by Bin(), and Free().

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]

Replace the ith item with a new item.

References m_items, m_sum_sizes, and SizeName::Size().

void Bin::DelItem ( int  i  )  [inline]

Remove the ith item.

References m_items, and m_sum_sizes.

void Bin::AddAllItems ( Bin b  )  [inline]

Add all items of a given bin.

References AddItem(), and Count().

void Bin::DelAllItems (  )  [inline]

Remove all items of the current bin.

References m_items, and m_sum_sizes.

const SizeName* Bin::operator[] ( int  i  )  const [inline]

Returns the ith item.

References m_items.

bool Bin::operator< ( const Bin bin  )  const [inline]

Overloaded operator <.

It compares the bins regarding the free space; the most filled bin comes first. It they have the same amount of free space, then the bin having smaller number of items is considered the smaller one.

References Count(), and Free().

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().


Friends And Related Function Documentation

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.

Parameters:
[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.


Member Data Documentation

std::vector<const SizeName*> Bin::m_items [private]

Total occupied size by the items.

Referenced by AddItem(), DelAllItems(), DelItem(), ReplaceItem(), and Used().

Bin's capacity.

Referenced by Bin(), and Capacity().


The documentation for this class was generated from the following file: