Debian Codegraph @

lib/dat/vector.hpp

raw symbols SCIP
1 /*
2 Copyright(C) 2011-2016 Brazil
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 #pragma once
20
21 #include "dat.hpp"cxx . . $ `<file>/lib/dat/dat.hpp`/
22
23 #include <new>
24
25 namespace grncxx . . $ grn/ {
26 namespace datcxx . . $ grn/dat/ {
27
28 template <typename T>
29 class GRN_DAT_APIcxx . . $ `lib/dat/dat.hpp:44:12`! Vectorcxx . . $ grn/dat/Vector# {
30 public:
31 Vectorcxx . . $ grn/dat/Vector#`Vector<T>`(49f6e7a06ebc5aa8).() : buf_cxx . . $ grn/dat/Vector#buf_.(NULLcxx . . $ `<external>/16391990256953433862/stddef.h:416:9`!), size_cxx . . $ grn/dat/Vector#size_.(0), capacity_cxx . . $ grn/dat/Vector#capacity_.(0) {}
32 ~cxx . . $ grn/dat/Vector#`~Vector<T>`(49f6e7a06ebc5aa8).Vector() {
33 for (UInt32cxx . . $ grn/dat/UInt32# i = 0; i <cxx . . $ grn/dat/`operator<`(d92c12cfb095b7ec). sizecxx . . $ grn/dat/Vector#size(ddd8539a2fcdd4ce).(); ++i) {
34 buf_cxx . . $ grn/dat/Vector#buf_.[i].~T();
35 }
36 delete [] reinterpret_cast<char *>(buf_cxx . . $ grn/dat/Vector#buf_.);
37 }
38
39 const T &operatorcxx . . $ grn/dat/Vector#`operator[]`(324713ecd9036b86).[](UInt32cxx . . $ grn/dat/UInt32# i) const {
40 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(i >= size());
41 return buf_cxx . . $ grn/dat/Vector#buf_.[i];
42 }
43 T &operatorcxx . . $ grn/dat/Vector#`operator[]`(cbb7c2c208bf2972).[](UInt32cxx . . $ grn/dat/UInt32# i) {
44 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(i >= size());
45 return buf_cxx . . $ grn/dat/Vector#buf_.[i];
46 }
47
48 const T &frontcxx . . $ grn/dat/Vector#front(ea465e50d690edfe).() const {
49 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(empty());
50 return buf_cxx . . $ grn/dat/Vector#buf_.[0];
51 }
52 T &frontcxx . . $ grn/dat/Vector#front(19b2b6f17af048b).() {
53 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(empty());
54 return buf_cxx . . $ grn/dat/Vector#buf_.[0];
55 }
56
57 const T &backcxx . . $ grn/dat/Vector#back(ea465e50d690edfe).() const {
58 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(empty());
59 return buf_cxx . . $ grn/dat/Vector#buf_.[sizecxx . . $ grn/dat/Vector#size(ddd8539a2fcdd4ce).() - 1];
60 }
61 T &backcxx . . $ grn/dat/Vector#back(19b2b6f17af048b).() {
62 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(empty());
63 return buf_cxx . . $ grn/dat/Vector#buf_.[sizecxx . . $ grn/dat/Vector#size(ddd8539a2fcdd4ce).() - 1];
64 }
65
66 const T *begincxx . . $ grn/dat/Vector#begin(1016ee5406d91ab9).() const {
67 return buf_cxx . . $ grn/dat/Vector#buf_.;
68 }
69 T *begincxx . . $ grn/dat/Vector#begin(155dc7f103cdb9db).() {
70 return buf_cxx . . $ grn/dat/Vector#buf_.;
71 }
72
73 const T *endcxx . . $ grn/dat/Vector#end(1016ee5406d91ab9).() const {
74 return buf_cxx . . $ grn/dat/Vector#buf_. + size_cxx . . $ grn/dat/Vector#size_.;
75 }
76 T *endcxx . . $ grn/dat/Vector#end(155dc7f103cdb9db).() {
77 return buf_cxx . . $ grn/dat/Vector#buf_. + size_cxx . . $ grn/dat/Vector#size_.;
78 }
79
80 void push_backcxx . . $ grn/dat/Vector#push_back(49f6e7a06ebc5aa8).() {
81 reservecxx . . $ grn/dat/Vector#reserve(cb2f890c2fdad230).(sizecxx . . $ grn/dat/Vector#size(ddd8539a2fcdd4ce).() + 1);
82 new (&buf_cxx . . $ grn/dat/Vector#buf_.[sizecxx . . $ grn/dat/Vector#size(ddd8539a2fcdd4ce).()]) T;
83 ++size_cxx . . $ grn/dat/Vector#size_.;
84 }
85 void push_backcxx . . $ grn/dat/Vector#push_back(77d9f17553126ecb).(const T &x) {
86 reservecxx . . $ grn/dat/Vector#reserve(cb2f890c2fdad230).(sizecxx . . $ grn/dat/Vector#size(ddd8539a2fcdd4ce).() + 1);
87 new (&buf_cxx . . $ grn/dat/Vector#buf_.[sizecxx . . $ grn/dat/Vector#size(ddd8539a2fcdd4ce).()]) T(x);
88 ++size_cxx . . $ grn/dat/Vector#size_.;
89 }
90
91 void pop_backcxx . . $ grn/dat/Vector#pop_back(49f6e7a06ebc5aa8).() {
92 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(empty());
93 backcxx . . $ grn/dat/Vector#back(ea465e50d690edfe).().~T();
94 --size_cxx . . $ grn/dat/Vector#size_.;
95 }
96
97 void clearcxx . . $ grn/dat/Vector#clear(49f6e7a06ebc5aa8).() {
98 resizecxx . . $ grn/dat/Vector#resize(cb2f890c2fdad230).(0);
99 }
100
101 void resizecxx . . $ grn/dat/Vector#resize(cb2f890c2fdad230).(UInt32cxx . . $ grn/dat/UInt32# new_size) {
102 if (new_size >cxx . . $ grn/dat/`operator>`(d92c12cfb095b7ec). capacitycxx . . $ grn/dat/Vector#capacity(ddd8539a2fcdd4ce).()) {
103 reservecxx . . $ grn/dat/Vector#reserve(cb2f890c2fdad230).(new_size);
104 }
105 for (UInt32cxx . . $ grn/dat/UInt32# i = sizecxx . . $ grn/dat/Vector#size(ddd8539a2fcdd4ce).(); i < new_size; ++i) {
106 new (&buf_cxx . . $ grn/dat/Vector#buf_.[i]) T;
107 }
108 for (UInt32cxx . . $ grn/dat/UInt32# i = new_size; i <cxx . . $ grn/dat/`operator<`(d92c12cfb095b7ec). sizecxx . . $ grn/dat/Vector#size(ddd8539a2fcdd4ce).(); ++i) {
109 buf_cxx . . $ grn/dat/Vector#buf_.[i].~T();
110 }
111 size_cxx . . $ grn/dat/Vector#size_. = new_size;
112 }
113 template <typename U>
114 void resizecxx . . $ grn/dat/Vector#resize(67785e711ef512ca).(UInt32cxx . . $ grn/dat/UInt32# new_size, const U &value) {
115 if (new_size >cxx . . $ grn/dat/`operator>`(d92c12cfb095b7ec). capacitycxx . . $ grn/dat/Vector#capacity(ddd8539a2fcdd4ce).()) {
116 reservecxx . . $ grn/dat/Vector#reserve(cb2f890c2fdad230).(new_size);
117 }
118 for (UInt32cxx . . $ grn/dat/UInt32# i = sizecxx . . $ grn/dat/Vector#size(ddd8539a2fcdd4ce).(); i < new_size; ++i) {
119 new (&buf_cxx . . $ grn/dat/Vector#buf_.[i]) T(value);
120 }
121 for (UInt32cxx . . $ grn/dat/UInt32# i = new_size; i <cxx . . $ grn/dat/`operator<`(d92c12cfb095b7ec). sizecxx . . $ grn/dat/Vector#size(ddd8539a2fcdd4ce).(); ++i) {
122 buf_cxx . . $ grn/dat/Vector#buf_.[i].~T();
123 }
124 size_cxx . . $ grn/dat/Vector#size_. = new_size;
125 }
126
127 void reservecxx . . $ grn/dat/Vector#reserve(cb2f890c2fdad230).(UInt32cxx . . $ grn/dat/UInt32# new_capacity) {
128 if (new_capacity <=cxx . . $ grn/dat/`operator<=`(d92c12cfb095b7ec). capacitycxx . . $ grn/dat/Vector#capacity(ddd8539a2fcdd4ce).()) {
129 return;
130 } else if ((new_capacity / 2) <cxx . . $ grn/dat/`operator<`(d92c12cfb095b7ec). capacitycxx . . $ grn/dat/Vector#capacity(ddd8539a2fcdd4ce).()) {
131 if (capacitycxx . . $ grn/dat/Vector#capacity(ddd8539a2fcdd4ce).() <cxx . . $ grn/dat/`operator<`(d92c12cfb095b7ec). (MAX_UINT32cxx . . $ grn/dat/MAX_UINT32. / 2)) {
132 new_capacity = capacitycxx . . $ grn/dat/Vector#capacity(ddd8539a2fcdd4ce).() * 2;
133 } else {
134 new_capacity = MAX_UINT32cxx . . $ grn/dat/MAX_UINT32.;
135 }
136 }
137
138 T *new_buf = reinterpret_cast<T *>(
139 new (std::nothrowcxx . . $ std/nothrow.) char[sizeof(new_capacity) * new_capacity]);
140 GRN_DAT_THROW_IFcxx . . $ `lib/dat/dat.hpp:232:9`!(MEMORY_ERROR, new_buf == NULLcxx . . $ `<external>/16391990256953433862/stddef.h:416:9`!);
141
142 for (UInt32cxx . . $ grn/dat/UInt32# i = 0; i <cxx . . $ grn/dat/`operator<`(d92c12cfb095b7ec). sizecxx . . $ grn/dat/Vector#size(ddd8539a2fcdd4ce).(); ++i) {
143 new (&new_buf[i]) T(buf_cxx . . $ grn/dat/Vector#buf_.[i]);
144 }
145 for (UInt32cxx . . $ grn/dat/UInt32# i = 0; i <cxx . . $ grn/dat/`operator<`(d92c12cfb095b7ec). sizecxx . . $ grn/dat/Vector#size(ddd8539a2fcdd4ce).(); ++i) {
146 buf_cxx . . $ grn/dat/Vector#buf_.[i].~T();
147 }
148
149 T *old_buf = buf_cxx . . $ grn/dat/Vector#buf_.;
150 buf_cxx . . $ grn/dat/Vector#buf_. = new_buf;
151 delete [] reinterpret_cast<char *>(old_buf);
152
153 capacity_cxx . . $ grn/dat/Vector#capacity_. = new_capacity;
154 }
155
156 void swapcxx . . $ grn/dat/Vector#swap(31b4a4301f47d369).(Vector *rhs) {
157 T * const temp_buf = buf_cxx . . $ grn/dat/Vector#buf_.;
158 buf_cxx . . $ grn/dat/Vector#buf_. = rhs->buf_cxx . . $ grn/dat/Vector#buf_.;
159 rhs->buf_cxx . . $ grn/dat/Vector#buf_. = temp_buf;
160
161 const UInt32cxx . . $ grn/dat/UInt32# temp_size = size_cxx . . $ grn/dat/Vector#size_.;
162 size_cxx . . $ grn/dat/Vector#size_. = rhs->size_cxx . . $ grn/dat/Vector#size_.;
163 rhs->size_cxx . . $ grn/dat/Vector#size_. = temp_size;
164
165 const UInt32cxx . . $ grn/dat/UInt32# temp_capacity = capacity_cxx . . $ grn/dat/Vector#capacity_.;
166 capacity_cxx . . $ grn/dat/Vector#capacity_. = rhs->capacity_cxx . . $ grn/dat/Vector#capacity_.;
167 rhs->capacity_cxx . . $ grn/dat/Vector#capacity_. = temp_capacity;
168 }
169
170 bool emptycxx . . $ grn/dat/Vector#empty(50ce9a9e25b4a850).() const {
171 return size_cxx . . $ grn/dat/Vector#size_. == 0;
172 }
173 UInt32cxx . . $ grn/dat/UInt32# sizecxx . . $ grn/dat/Vector#size(ddd8539a2fcdd4ce).() const {
174 return size_cxx . . $ grn/dat/Vector#size_.;
175 }
176 UInt32cxx . . $ grn/dat/UInt32# capacitycxx . . $ grn/dat/Vector#capacity(ddd8539a2fcdd4ce).() const {
177 return capacity_cxx . . $ grn/dat/Vector#capacity_.;
178 }
179
180 private:
181 T *buf_cxx . . $ grn/dat/Vector#buf_.;
182 UInt32cxx . . $ grn/dat/UInt32# size_cxx . . $ grn/dat/Vector#size_.;
183 UInt32cxx . . $ grn/dat/UInt32# capacity_cxx . . $ grn/dat/Vector#capacity_.;
184
185 // Disallows copy and assignment.
186 Vectorcxx . . $ grn/dat/Vector#`Vector<T>`(9817f1f72f2ac1bb).(const Vector &);
187 Vector &operatorcxx . . $ grn/dat/Vector#`operator=`(b064f8bedd6c7c17).=(const Vector &);
188 };
189
190 } // namespace dat
191 } // namespace grn