Apache Arrow (C++)
A columnar in-memory analytics layer designed to accelerate big data.
stl.h
Go to the documentation of this file.
1 // Licensed to the Apache Software Foundation (ASF) under one
2 // or more contributor license agreements. See the NOTICE file
3 // distributed with this work for additional information
4 // regarding copyright ownership. The ASF licenses this file
5 // to you under the Apache License, Version 2.0 (the
6 // "License"); you may not use this file except in compliance
7 // with the License. You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing,
12 // software distributed under the License is distributed on an
13 // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 // KIND, either express or implied. See the License for the
15 // specific language governing permissions and limitations
16 // under the License.
17 
18 #ifndef ARROW_UTIL_STL_H
19 #define ARROW_UTIL_STL_H
20 
21 #include <vector>
22 
23 #include "arrow/util/logging.h"
24 
25 namespace arrow {
26 namespace internal {
27 
28 template <typename T>
29 inline std::vector<T> DeleteVectorElement(const std::vector<T>& values, size_t index) {
30  DCHECK(!values.empty());
31  DCHECK_LT(index, values.size());
32  std::vector<T> out;
33  out.reserve(values.size() - 1);
34  for (size_t i = 0; i < index; ++i) {
35  out.push_back(values[i]);
36  }
37  for (size_t i = index + 1; i < values.size(); ++i) {
38  out.push_back(values[i]);
39  }
40  return out;
41 }
42 
43 template <typename T>
44 inline std::vector<T> AddVectorElement(const std::vector<T>& values, size_t index,
45  const T& new_element) {
46  DCHECK_LE(index, values.size());
47  std::vector<T> out;
48  out.reserve(values.size() + 1);
49  for (size_t i = 0; i < index; ++i) {
50  out.push_back(values[i]);
51  }
52  out.push_back(new_element);
53  for (size_t i = index; i < values.size(); ++i) {
54  out.push_back(values[i]);
55  }
56  return out;
57 }
58 
59 } // namespace internal
60 } // namespace arrow
61 
62 #endif // ARROW_UTIL_STL_H
#define DCHECK_LT(val1, val2)
Definition: logging.h:82
Top-level namespace for Apache Arrow C++ API.
Definition: allocator.h:29
#define DCHECK(condition)
Definition: logging.h:78
#define DCHECK_LE(val1, val2)
Definition: logging.h:81