44 template <
bool needsDestruction,
typename T>
58 for (T* cur = begin; cur != end; ++cur)
63 template <
bool needsInitialization,
bool canInitializeWithMemset,
typename T>
66 template<
bool ignore,
typename T>
77 for (T* cur = begin; cur != end; ++cur)
87 std::memset(begin, 0,
reinterpret_cast<char *
>(end) -
reinterpret_cast<char *
>(begin));
91 template <
bool canMoveWithMemcpy,
typename T>
97 static void move(
const T* src,
const T* srcEnd, T* dst)
99 while (src != srcEnd) {
101 const_cast<T*
>(src)->~T();
109 move(src, srcEnd, dst);
111 T* dstEnd = dst + (srcEnd - src);
112 while (src != srcEnd) {
115 new (dstEnd) T(*srcEnd);
116 const_cast<T*
>(srcEnd)->~T();
125 static void move(
const T* src,
const T* srcEnd, T* dst)
127 std::memcpy(dst, src,
reinterpret_cast<const char *
>(srcEnd) -
reinterpret_cast<const char *
>(src));
131 std::memmove(dst, src,
reinterpret_cast<const char *
>(srcEnd) -
reinterpret_cast<const char *
>(src));
135 template <
bool canCopyWithMemcpy,
typename T>
143 while (src != srcEnd) {
156 std::memcpy(dst, src,
reinterpret_cast<const char *
>(srcEnd) -
reinterpret_cast<const char *
>(src));
160 template <
bool canFillWithMemset,
typename T>
168 while (dst != dstEnd) {
180 ASSERT(
sizeof(T) ==
sizeof(
char));
181 std::memset(dst, val, dstEnd - dst);
185 template<
bool canCompareWithMemcmp,
typename T>
191 static bool compare(
const T* a,
const T* b,
size_t size)
193 for (
size_t i = 0; i < size; ++i)
203 static bool compare(
const T* a,
const T* b,
size_t size)
205 return std::memcmp(a, b,
sizeof(T) * size) == 0;
222 static void move(
const T* src,
const T* srcEnd, T* dst)
242 static bool compare(
const T* a,
const T* b,
size_t size)
254 if (newCapacity > std::numeric_limits<size_t>::max() /
sizeof(T))
300 template<
typename T,
size_t inlineCapacity>
324 std::swap(m_buffer, other.m_buffer);
325 std::swap(m_capacity, other.m_capacity);
340 template<
typename T,
size_t inlineCapacity>
346 : Base(inlineBuffer(), inlineCapacity)
351 : Base(inlineBuffer(), inlineCapacity)
363 if (newCapacity > inlineCapacity)
369 if (bufferToDeallocate == inlineBuffer())
379 if (
buffer() == inlineBuffer())
388 static const size_t m_inlineBufferSize = inlineCapacity *
sizeof(T);
389 T* inlineBuffer() {
return reinterpret_cast<T*
>(&m_inlineBuffer); }
392 char m_inlineBuffer[m_inlineBufferSize];
395 template<
typename T,
size_t inlineCapacity = 0>
398 typedef VectorBuffer<T, inlineCapacity> Buffer;
399 typedef VectorTypeOperations<T> TypeOperations;
405 typedef const T* const_iterator;
425 template<
size_t otherCapacity>
429 template<
size_t otherCapacity>
432 size_t size()
const {
return m_size; }
433 size_t capacity()
const {
return m_buffer.capacity(); }
439 return m_buffer.buffer()[i];
441 const T&
at(
size_t i)
const
444 return m_buffer.buffer()[i];
450 T*
data() {
return m_buffer.buffer(); }
451 const T*
data()
const {
return m_buffer.buffer(); }
456 const_iterator
end()
const {
return begin() + m_size; }
471 template<
typename U>
void append(
const U*,
size_t);
472 template<
typename U>
void append(
const U&);
476 template<
typename U>
void insert(
size_t position,
const U*,
size_t);
477 template<
typename U>
void insert(
size_t position,
const U&);
480 template<
typename U>
void prepend(
const U*,
size_t);
481 template<
typename U>
void prepend(
const U&);
484 void remove(
size_t position);
485 void remove(
size_t position,
size_t length);
500 void fill(
const T&,
size_t);
503 template<
typename Iterator>
void appendRange(Iterator start, Iterator
end);
509 std::swap(m_size, other.m_size);
510 m_buffer.swap(other.m_buffer);
514 void expandCapacity(
size_t newMinCapacity);
515 const T* expandCapacity(
size_t newMinCapacity,
const T*);
516 template<
typename U> U* expandCapacity(
size_t newMinCapacity, U*);
522 template<
typename T,
size_t inlineCapacity>
524 : m_size(other.
size())
530 template<
typename T,
size_t inlineCapacity>
531 template<
size_t otherCapacity>
533 : m_size(other.
size())
539 template<
typename T,
size_t inlineCapacity>
554 m_size = other.
size();
559 template<
typename T,
size_t inlineCapacity>
560 template<
size_t otherCapacity>
575 m_size = other.
size();
580 template<
typename T,
size_t inlineCapacity>
583 if (
size() > newSize)
595 template<
typename T,
size_t inlineCapacity>
596 template<
typename Iterator>
599 for (Iterator it = start; it !=
end; ++it)
603 template<
typename T,
size_t inlineCapacity>
604 void Vector<T, inlineCapacity>::expandCapacity(
size_t newMinCapacity)
606 reserveCapacity(max(newMinCapacity, max(
static_cast<size_t>(16), capacity() + capacity() / 4 + 1)));
609 template<
typename T,
size_t inlineCapacity>
610 const T* Vector<T, inlineCapacity>::expandCapacity(
size_t newMinCapacity,
const T* ptr)
612 if (ptr < begin() || ptr >= end()) {
613 expandCapacity(newMinCapacity);
616 size_t index = ptr - begin();
617 expandCapacity(newMinCapacity);
618 return begin() + index;
621 template<
typename T,
size_t inlineCapacity>
template<
typename U>
622 inline U* Vector<T, inlineCapacity>::expandCapacity(
size_t newMinCapacity, U* ptr)
624 expandCapacity(newMinCapacity);
628 template<
typename T,
size_t inlineCapacity>
635 expandCapacity(
size);
643 template<
typename T,
size_t inlineCapacity>
651 template<
typename T,
size_t inlineCapacity>
656 expandCapacity(
size);
662 template<
typename T,
size_t inlineCapacity>
667 T* oldBuffer =
begin();
669 m_buffer.allocateBuffer(newCapacity);
672 m_buffer.deallocateBuffer(oldBuffer);
675 template<
typename T,
size_t inlineCapacity>
681 resize(min(m_size, newCapacity));
683 T* oldBuffer =
begin();
684 if (newCapacity > 0) {
686 m_buffer.allocateBuffer(newCapacity);
687 if (
begin() != oldBuffer)
691 m_buffer.deallocateBuffer(oldBuffer);
698 template<
typename T,
size_t inlineCapacity>
template<
typename U>
701 size_t newSize = m_size + dataSize;
703 data = expandCapacity(newSize,
data);
708 for (
size_t i = 0; i < dataSize; ++i)
709 new (&dest[i]) T(
data[i]);
713 template<
typename T,
size_t inlineCapacity>
template<
typename U>
718 ptr = expandCapacity(
size() + 1, ptr);
730 new (
end()) T(
static_cast<T
>(*ptr));
740 template<
typename T,
size_t inlineCapacity>
template<
typename U>
749 template<
typename T,
size_t inlineCapacity>
template<
typename U,
size_t c>
755 template<
typename T,
size_t inlineCapacity>
template<
typename U>
759 size_t newSize = m_size + dataSize;
761 data = expandCapacity(newSize,
data);
765 T* spot =
begin() + position;
767 for (
size_t i = 0; i < dataSize; ++i)
768 new (&spot[i]) T(
data[i]);
772 template<
typename T,
size_t inlineCapacity>
template<
typename U>
776 const U*
data = &val;
782 T* spot =
begin() + position;
788 template<
typename T,
size_t inlineCapacity>
template<
typename U,
size_t c>
794 template<
typename T,
size_t inlineCapacity>
template<
typename U>
800 template<
typename T,
size_t inlineCapacity>
template<
typename U>
806 template<
typename T,
size_t inlineCapacity>
template<
typename U,
size_t c>
812 template<
typename T,
size_t inlineCapacity>
816 T* spot =
begin() + position;
822 template<
typename T,
size_t inlineCapacity>
827 T* beginSpot =
begin() + position;
828 T* endSpot = beginSpot + length;
834 template<
typename T,
size_t inlineCapacity>
837 T* buffer = m_buffer.releaseBuffer();
838 if (inlineCapacity && !buffer && m_size) {
842 size_t bytes = m_size *
sizeof(T);
844 memcpy(buffer,
data(), bytes);
851 template<
typename T,
size_t inlineCapacity>
854 typedef typename Vector<T, inlineCapacity>::const_iterator iterator;
855 iterator end = collection.
end();
856 for (iterator it = collection.
begin(); it != end; ++it)
860 template<
typename T,
size_t inlineCapacity>
866 template<
typename T,
size_t inlineCapacity>
875 template<
typename T,
size_t inlineCapacity>
void allocateBuffer(size_t newCapacity)
VectorBufferBase(T *buffer, size_t capacity)
void deallocateBuffer(T *bufferToDeallocate)
void swap(VectorBuffer< T, 0 > &other)
VectorBuffer(size_t capacity)
void deallocateBuffer(T *bufferToDeallocate)
VectorBuffer(size_t capacity)
void allocateBuffer(size_t newCapacity)
void appendRange(Iterator start, Iterator end)
void uncheckedAppend(const U &val)
void fill(const T &, size_t)
const_iterator end() const
Vector & operator=(const Vector &)
void shrinkCapacity(size_t newCapacity)
void insert(size_t position, const U *, size_t)
void append(const U *, size_t)
Vector & operator=(const Vector< T, otherCapacity > &)
void reserveCapacity(size_t newCapacity)
const T & operator[](size_t i) const
void prepend(const U *, size_t)
const T & at(size_t i) const
const_iterator begin() const
void swap(Vector< T, inlineCapacity > &other)
Vector(size_t size, const T &val)
void remove(size_t position)
void deleteAllValues(const HashMap< T, U, V, W, X > &collection)
void * fastMalloc(size_t n)
void swap(OwnArrayPtr< T > &a, OwnArrayPtr< T > &b)
bool operator!=(const HashTableConstKeysIterator< T, U, V > &a, const HashTableConstKeysIterator< T, U, V > &b)
bool operator==(const HashTableConstKeysIterator< T, U, V > &a, const HashTableConstKeysIterator< T, U, V > &b)
static bool compare(const T *a, const T *b, size_t size)
static bool compare(const T *a, const T *b, size_t size)
static void uninitializedCopy(const T *src, const T *srcEnd, T *dst)
static void uninitializedCopy(const T *src, const T *srcEnd, T *dst)
static void destruct(T *, T *)
static void destruct(T *begin, T *end)
static void uninitializedFill(T *dst, T *dstEnd, const T &val)
static void uninitializedFill(T *dst, T *dstEnd, const T &val)
static void initialize(T *, T *)
static void initialize(T *begin, T *end)
static void initialize(T *begin, T *end)
static void move(const T *src, const T *srcEnd, T *dst)
static void moveOverlapping(const T *src, const T *srcEnd, T *dst)
static void move(const T *src, const T *srcEnd, T *dst)
static void moveOverlapping(const T *src, const T *srcEnd, T *dst)
static void destruct(T *begin, T *end)
static bool compare(const T *a, const T *b, size_t size)
static void move(const T *src, const T *srcEnd, T *dst)
static void uninitializedFill(T *dst, T *dstEnd, const T &val)
static void moveOverlapping(const T *src, const T *srcEnd, T *dst)
static void initialize(T *begin, T *end)
static void uninitializedCopy(const T *src, const T *srcEnd, T *dst)