added BinaryHeap::setCapacity()

This commit is contained in:
hyung-hwan 2020-09-09 09:15:13 +00:00
parent e5aabf7d56
commit 1c39537b44
2 changed files with 23 additions and 19 deletions

View File

@ -340,37 +340,37 @@ protected:
}
public:
bool isEmpty () const
bool isEmpty () const QSE_CPP_NOEXCEPT
{
return this->count == 0;
}
qse_size_t getSize () const
qse_size_t getSize () const QSE_CPP_NOEXCEPT
{
return this->count;
}
qse_size_t getCapacity () const
qse_size_t getCapacity () const QSE_CPP_NOEXCEPT
{
return this->capacity;
}
operator T* ()
operator T* () QSE_CPP_NOEXCEPT
{
return this->buffer;
}
operator const T* () const
operator const T* () const QSE_CPP_NOEXCEPT
{
return this->buffer;
}
T* getBuffer ()
T* getBuffer () QSE_CPP_NOEXCEPT
{
return this->buffer;
}
const T* getBuffer () const
const T* getBuffer () const QSE_CPP_NOEXCEPT
{
return this->buffer;
}
@ -387,7 +387,7 @@ public:
/// const int& t = a[2];
/// printf ("%lu\n", (unsigned long int)a.getIndex(t)); // print 2
/// \endcode
qse_size_t getIndex (const T& v) const
qse_size_t getIndex (const T& v) const QSE_CPP_NOEXCEPT
{
if (&v >= &this->buffer[0] && &v < &this->buffer[this->count])
{
@ -397,25 +397,25 @@ public:
return INVALID_INDEX;
}
T& operator[] (qse_size_t index)
T& operator[] (qse_size_t index) QSE_CPP_NOEXCEPT
{
QSE_ASSERT (index < this->count);
return this->buffer[index];
}
const T& operator[] (qse_size_t index) const
const T& operator[] (qse_size_t index) const QSE_CPP_NOEXCEPT
{
QSE_ASSERT (index < this->count);
return this->buffer[index];
}
T& getValueAt (qse_size_t index)
T& getValueAt (qse_size_t index) QSE_CPP_NOEXCEPT
{
QSE_ASSERT (index < this->count);
return this->buffer[index];
}
const T& getValueAt (qse_size_t index) const
const T& getValueAt (qse_size_t index) const QSE_CPP_NOEXCEPT
{
QSE_ASSERT (index < this->count);
return this->buffer[index];
@ -433,12 +433,12 @@ public:
}
#endif
const T& getFirst () const
const T& getFirst () const QSE_CPP_NOEXCEPT
{
return this->getValueAt(0);
}
const T& getLast () const
const T& getLast () const QSE_CPP_NOEXCEPT
{
return this->getValueAt(this->getSize() - 1);
}

View File

@ -157,18 +157,22 @@ public:
/// The isEmpty() function returns true if the binary heap contains no
/// item and false otherwise.
bool isEmpty() const { return ParentType::isEmpty(); }
bool isEmpty() const QSE_CPP_NOEXCEPT{ return ParentType::isEmpty(); }
/// The getSize() function returns the number of items in the binary heap.
qse_size_t getSize() const { return ParentType::getSize(); }
qse_size_t getSize() const QSE_CPP_NOEXCEPT{ return ParentType::getSize(); }
/// The getCapacity() function returns the capacity of the internal buffer
/// of the binary heap.
qse_size_t getCapacity() const { return ParentType::getCapacity(); }
qse_size_t getCapacity() const QSE_CPP_NOEXCEPT { return ParentType::getCapacity(); }
/// The getIndex() function returns the index of an item reference \a v.
qse_size_t getIndex (const T& v) const { return ParentType::getIndex(v); }
/// The setCapacity() function resizes the capacity of the internal buffer.
/// If the given capacity is smaller than the current capacity, it skips resizing.
void setCapacity (qse_size_t capa) { if (capa > ParentType::getCapacity()) ParentType::setCapacity (capa); }
/// The clear() function returns all items.
void clear (bool purge_buffer = false) { ParentType::clear (purge_buffer); }
@ -178,14 +182,14 @@ public:
/// The operator[] function returns the constant reference to the item
/// at the specified \a index.
const T& operator[] (qse_size_t index) const
const T& operator[] (qse_size_t index) const QSE_CPP_NOEXCEPT
{
return ParentType::getValueAt (index);
}
/// The getValueAt() function returns the constant reference to the item
/// at the specified \a index.
const T& getValueAt (qse_size_t index) const
const T& getValueAt (qse_size_t index) const QSE_CPP_NOEXCEPT
{
return ParentType::getValueAt (index);
}