14 #ifndef OR_TOOLS_BASE_PROTOBUF_UTIL_H_
15 #define OR_TOOLS_BASE_PROTOBUF_UTIL_H_
17 #include "google/protobuf/repeated_field.h"
25 inline void Truncate(RepeatedPtrField<T>* array,
int new_size) {
26 const int size = array->size();
28 array->DeleteSubrange(new_size, size - new_size);
39 template <
typename RepeatedType,
typename IndexContainer = std::vector<
int>>
40 int RemoveAt(RepeatedType* array,
const IndexContainer& indices) {
41 if (indices.size() == 0) {
44 const int num_indices = indices.size();
45 const int num_elements = array->size();
47 if (num_indices == num_elements) {
52 typename IndexContainer::const_iterator remove_iter = indices.begin();
53 int write_index = *(remove_iter++);
54 for (
int scan = write_index + 1; scan < num_elements; ++scan) {
55 if (remove_iter != indices.end() && *remove_iter == scan) {
58 array->SwapElements(scan, write_index++);
61 DCHECK_EQ(write_index, num_elements - num_indices);
69 #endif // OR_TOOLS_BASE_PROTOBUF_UTIL_H_