20#ifndef CLICK_VECTOR_CC
21#define CLICK_VECTOR_CC
22#include <click/glue.hh>
27template <
typename AM,
size_t ALIGNMENTM>
28vector_memory<AM,ALIGNMENTM>::~vector_memory()
31 CLICK_LFREE(l_, capacity_ *
sizeof(type));
34template <
typename AM,
size_t ALIGNMENTM>
35void vector_memory<AM,ALIGNMENTM>::assign(
const vector_memory<AM,ALIGNMENTM> &x)
39 AM::mark_noaccess(l_, n_);
41 if (reserve_and_push_back(x.n_, 0)) {
43 AM::mark_undefined(l_, n_);
44 AM::copy(l_, x.l_, n_);
49template <
typename AM,
size_t ALIGNMENTM>
50void vector_memory<AM,ALIGNMENTM>::assign(size_type n,
const type *vp)
52 if (unlikely(need_argument_copy(vp))) {
54 return assign(n, &v_copy);
61template <
typename AM,
size_t ALIGNMENTM>
62typename vector_memory<AM,ALIGNMENTM>::iterator vector_memory<AM,ALIGNMENTM>::insert(iterator it,
const type *vp)
64 assert(it >= begin() && it <= end());
65 if (unlikely(need_argument_copy(vp))) {
67 return insert(it, &v_copy);
70 if (n_ == capacity_) {
71 size_type pos = it - begin();
72 if (!reserve_and_push_back(-1, 0))
76 AM::mark_undefined(l_ + n_, 1);
77 AM::move(it + 1, it, end() - it);
78 AM::mark_undefined(it, 1);
84template <
typename AM,
size_t ALIGNMENTM>
85typename vector_memory<AM,ALIGNMENTM>::iterator vector_memory<AM,ALIGNMENTM>::erase(iterator a, iterator b)
88 assert(a >= begin() && b <= end());
89 AM::move_onto(a, b, end() - b);
91 AM::destroy(end(), b - a);
92 AM::mark_noaccess(end(), b - a);
98template <
typename AM,
size_t ALIGNMENTM>
99bool vector_memory<AM,ALIGNMENTM>::reserve_and_push_back(size_type want,
const type *push_vp)
101 if (unlikely(push_vp && need_argument_copy(push_vp))) {
102 type push_v_copy(*push_vp);
103 return reserve_and_push_back(want, &push_v_copy);
107 want = (capacity_ > 0 ? capacity_ * 2 : 4);
109 if (want > capacity_) {
110 type *new_l = (type *) CLICK_ALIGNED_ALLOC_T(want *
sizeof(type),ALIGNMENTM);
113 AM::mark_noaccess(new_l + n_, want - n_);
114 AM::move(new_l, l_, n_);
115 CLICK_ALIGNED_FREE(l_, capacity_ *
sizeof(type));
120 if (unlikely(push_vp))
125template <
typename AM,
size_t ALIGNMENTM>
126void vector_memory<AM,ALIGNMENTM>::resize(size_type n,
const type *vp)
128 if (unlikely(need_argument_copy(vp))) {
130 return resize(n, &v_copy);
133 if (n <= capacity_ || reserve_and_push_back(n, 0)) {
136 AM::destroy(l_ + n, n_ - n);
137 AM::mark_noaccess(l_ + n, n_ - n);
140 AM::mark_undefined(l_ + n_, n - n_);
141 AM::fill(l_ + n_, n - n_, vp);
147template <
typename AM,
size_t ALIGNMENTM>
148void vector_memory<AM,ALIGNMENTM>::swap(vector_memory<AM,ALIGNMENTM> &x)
158 size_type capacity = capacity_;
159 capacity_ = x.capacity_;
160 x.capacity_ = capacity;
Click's vector container template.