25#include "absl/container/flat_hash_set.h"
26#include "absl/status/status.h"
27#include "absl/strings/str_cat.h"
28#include "absl/strings/string_view.h"
29#include "absl/types/span.h"
38 for (
int i = 0; i < ids.size(); previous = ids[i], ++i) {
39 if (ids[i] < 0 || ids[i] == std::numeric_limits<int64_t>::max()) {
41 <<
"Expected ids to be nonnegative and not max(int64_t) but at "
43 << i <<
" found id: " << ids[i];
45 if (ids[i] <= previous) {
47 <<
"Expected ids to be strictly increasing, but at index " << i
48 <<
" found id: " << ids[i] <<
" and at index " << i - 1
49 <<
" found id: " << ids[i - 1];
52 return absl::OkStatus();
58 for (
const int64_t
id : ids) {
62 <<
" should be less than upper bound: " << *
upper_bound;
64 if (!universe.
HasId(
id)) {
68 return absl::OkStatus();
73 absl::string_view ids_description,
74 absl::string_view universe_description) {
75 for (
int i = 0; i < ids.size(); ++i) {
76 const int64_t
id = ids[i];
77 if (!universe.
HasId(
id)) {
79 <<
"Id: " <<
id <<
" (at index: " << i <<
") in "
80 << ids_description <<
" is missing from " << universe_description;
83 return absl::OkStatus();
88 absl::string_view first_description,
89 absl::string_view second_description) {
90 if (first_ids.size() != second_ids.
Size()) {
92 << first_description <<
" has size " << first_ids.size() <<
", but "
93 << second_description <<
" has size " << second_ids.
Size();
97 return absl::OkStatus();
#define RETURN_IF_ERROR(expr)
bool HasId(int64_t id) const
An object oriented wrapper for quadratic constraints in ModelStorage.
absl::Status CheckIdsSubset(absl::Span< const int64_t > ids, const IdNameBiMap &universe, std::optional< int64_t > upper_bound)
absl::Status CheckIdsIdentical(absl::Span< const int64_t > first_ids, const IdNameBiMap &second_ids, absl::string_view first_description, absl::string_view second_description)
first_ids and second_ids must include distinct ids.
absl::Status CheckIdsRangeAndStrictlyIncreasing(absl::Span< const int64_t > ids)
StatusBuilder InvalidArgumentErrorBuilder()