Google OR-Tools v9.14
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
util_intops Namespace Reference

Detailed Description

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. This file provides the StrongVector container that wraps around the STL vector. The wrapper restrict indexing to a pre-specified type-safe integer type or StrongInt (see util/intops/strong_int.h). It prevents accidental indexing by different "logical" integer-like types (e.g. another StrongInt) or native integer types. The wrapper is useful as C++ and the standard template library allows the user to mix "logical" integral indices that might have a different role.

The container can only be indexed by an instance of an StrongInt class, which can be declared as:

DEFINE_STRONG_INT_TYPE(type_name, value_type);
#define DEFINE_STRONG_INT_TYPE(type_name, value_type)

where type_name is the desired name for the "logical" integer-like type and the value_type is a supported native integer type such as int or uint64_t (see util/intops/strong_int.h for details).

The wrapper exposes all public methods of STL vector and behaves mostly as pass-through. The only methods modified to ensure type-safety are the operator [] and the at() methods.

EXAMPLES -----------------------------------------------------------------—

DEFINE_STRONG_INT_TYPE(PhysicalChildIndex, int32_t);
PhysicalChildIndex physical_index;
vec[physical_index] = ...; <-- index type match: compiles properly.
vec.at(physical_index) = ...; <-- index type match: compiles properly.
int32_t physical_index;
vec[physical_index] = ...; <-- fails to compile.
vec.at(physical_index) = ...; <-- fails to compile.
DEFINE_STRONG_INT_TYPE(LogicalChildIndex, int32_t);
LogicalChildIndex logical_index;
vec[logical_index] = ...; <-- fails to compile.
vec.at(logical_index) = ...; <-- fails to compile.
trees with all degrees equal to

NB: Iterator arithmetic bypasses strong typing for the index.

OVERFLOW BEHAVIOR

This class ONLY guards against growing the size beyond the range indexable by the index type in debug mode. In optimized mode the user can CHECK IsValidSize() when deemed important.

Copyright 2025 Francesco Cavaliere Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Note
It may be unexpected, but views provide a subscript operator that directly accesses the underlying original container using the original indices. This behavior is particularly relevant in the context of the Set Cover problem, where we often work with subsets of columns or rows. Despite this, each column or row still contains the original indices, which are used for referring to other columns/rows.

This design abstracts access to the underlying container, ensuring consistent behavior across the following scenarios:

  1. Directly using the original container.
  2. Accessing a subset of the original items via a view.
  3. Using a new container with a compacted subset of items, indexing them with the position the have in the new container and not in the original one. This also need the old indices stored in rows/columns to be mapped into the new ones.

Namespaces

namespace  util

Classes

class  FilterIndexRangeView
class  IndexFilterView
class  IndexListView
struct  NoTransform
class  StrongVector
class  TransformView
class  TwoLevelsView
struct  TypeCastTransform
class  ValueFilterView