{
allocated = o.allocated;
length = o.length;
- arrayZ_ = o.arrayZ_;
+ arrayZ = o.arrayZ;
o.init ();
}
~hb_vector_t () { fini (); }
- unsigned int length;
private:
int allocated; /* == -1 means allocation failed. */
- Type *arrayZ_;
public:
+ unsigned int length;
+ public:
+ Type *arrayZ;
void init ()
{
allocated = length = 0;
- arrayZ_ = nullptr;
+ arrayZ = nullptr;
}
void fini ()
{
- if (arrayZ_)
- free (arrayZ_);
+ free (arrayZ);
init ();
}
void fini_deep ()
{
- Type *array = arrayZ();
unsigned int count = length;
for (unsigned int i = 0; i < count; i++)
- array[i].fini ();
+ arrayZ[i].fini ();
fini ();
}
fini ();
allocated = o.allocated;
length = o.length;
- arrayZ_ = o.arrayZ_;
+ arrayZ = o.arrayZ;
o.init ();
return *this;
}
hb_bytes_t as_bytes () const
- { return hb_bytes_t ((const char *) arrayZ(), length * item_size); }
+ { return hb_bytes_t ((const char *) arrayZ, length * item_size); }
bool operator == (const hb_vector_t &o) const { return as_array () == o.as_array (); }
uint32_t hash () const { return as_array ().hash (); }
- const Type * arrayZ () const { return arrayZ_; }
- Type * arrayZ () { return arrayZ_; }
-
Type& operator [] (int i_)
{
unsigned int i = (unsigned int) i_;
if (unlikely (i >= length))
return Crap (Type);
- return arrayZ()[i];
+ return arrayZ[i];
}
const Type& operator [] (int i_) const
{
unsigned int i = (unsigned int) i_;
if (unlikely (i >= length))
return Null(Type);
- return arrayZ()[i];
+ return arrayZ[i];
}
Type& tail () { return (*this)[length - 1]; }
template <typename T>
hb_vector_t& operator << (T&& v) { push (hb_forward<T> (v)); return *this; }
- hb_array_t< Type> as_array () { return hb_array (arrayZ(), length); }
- hb_array_t<const Type> as_array () const { return hb_array (arrayZ(), length); }
+ hb_array_t< Type> as_array () { return hb_array (arrayZ, length); }
+ hb_array_t<const Type> as_array () const { return hb_array (arrayZ, length); }
/* Iterator. */
typedef hb_array_t<const Type> iter_t;
{ return as_array ().sub_array (start_offset, count);}
hb_sorted_array_t<Type> as_sorted_array ()
- { return hb_sorted_array (arrayZ(), length); }
+ { return hb_sorted_array (arrayZ, length); }
hb_sorted_array_t<const Type> as_sorted_array () const
- { return hb_sorted_array (arrayZ(), length); }
+ { return hb_sorted_array (arrayZ, length); }
- template <typename T> explicit operator T * () { return arrayZ(); }
- template <typename T> explicit operator const T * () const { return arrayZ(); }
+ template <typename T> explicit operator T * () { return arrayZ; }
+ template <typename T> explicit operator const T * () const { return arrayZ; }
- Type * operator + (unsigned int i) { return arrayZ() + i; }
- const Type * operator + (unsigned int i) const { return arrayZ() + i; }
+ Type * operator + (unsigned int i) { return arrayZ + i; }
+ const Type * operator + (unsigned int i) const { return arrayZ + i; }
Type *push ()
{
if (unlikely (!resize (length + 1)))
return &Crap(Type);
- return &arrayZ()[length - 1];
+ return &arrayZ[length - 1];
}
template <typename T>
Type *push (T&& v)
(new_allocated < (unsigned) allocated) ||
hb_unsigned_mul_overflows (new_allocated, sizeof (Type));
if (likely (!overflows))
- new_array = (Type *) realloc (arrayZ_, new_allocated * sizeof (Type));
+ new_array = (Type *) realloc (arrayZ, new_allocated * sizeof (Type));
if (unlikely (!new_array))
{
return false;
}
- arrayZ_ = new_array;
+ arrayZ = new_array;
allocated = new_allocated;
return true;
return false;
if (size > length)
- memset (arrayZ() + length, 0, (size - length) * sizeof (*arrayZ()));
+ memset (arrayZ + length, 0, (size - length) * sizeof (*arrayZ));
length = size;
return true;
Type pop ()
{
if (!length) return Null(Type);
- return hb_move (arrayZ()[--length]); /* Does this move actually work? */
+ return hb_move (arrayZ[--length]); /* Does this move actually work? */
}
void remove (unsigned int i)
{
if (unlikely (i >= length))
return;
- Type *array = arrayZ();
- memmove (static_cast<void *> (&array[i]),
- static_cast<void *> (&array[i + 1]),
+ memmove (static_cast<void *> (&arrayZ[i]),
+ static_cast<void *> (&arrayZ[i + 1]),
(length - i - 1) * sizeof (Type));
length--;
}
template <typename T>
Type *find (T v)
{
- Type *array = arrayZ();
for (unsigned int i = 0; i < length; i++)
- if (array[i] == v)
- return &array[i];
+ if (arrayZ[i] == v)
+ return &arrayZ[i];
return nullptr;
}
template <typename T>
const Type *find (T v) const
{
- const Type *array = arrayZ();
for (unsigned int i = 0; i < length; i++)
- if (array[i] == v)
- return &array[i];
+ if (arrayZ[i] == v)
+ return &arrayZ[i];
return nullptr;
}
template <typename Type>
struct hb_sorted_vector_t : hb_vector_t<Type>
{
- hb_sorted_array_t< Type> as_array () { return hb_sorted_array (this->arrayZ(), this->length); }
- hb_sorted_array_t<const Type> as_array () const { return hb_sorted_array (this->arrayZ(), this->length); }
+ hb_sorted_array_t< Type> as_array () { return hb_sorted_array (this->arrayZ, this->length); }
+ hb_sorted_array_t<const Type> as_array () const { return hb_sorted_array (this->arrayZ, this->length); }
/* Iterator. */
typedef hb_sorted_array_t<const Type> const_iter_t;