Google OR-Tools v9.14
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
operations_research::math_opt::ElementStorage Class Reference

#include <element_storage.h>

Public Member Functions

 ElementStorage ()
int64_t Add (const absl::string_view name)
 Creates a new element and returns its id.
bool Erase (const int64_t id)
bool Exists (const int64_t id) const
 Returns true an element with this id was created and not yet erased.
absl::StatusOr< absl::string_view > GetName (const int64_t id) const
int64_t next_id () const
std::vector< int64_t > AllIds () const
int64_t size () const
 Returns the number of elements added and not erased.
void EnsureNextIdAtLeast (const int64_t id)

Detailed Description

Definition at line 107 of file element_storage.h.

Constructor & Destructor Documentation

◆ ElementStorage()

operations_research::math_opt::ElementStorage::ElementStorage ( )
inline

We start with a dense storage, which is more efficient, and switch to a sparse storage when an element is erased.

Definition at line 128 of file element_storage.h.

Member Function Documentation

◆ Add()

int64_t operations_research::math_opt::ElementStorage::Add ( const absl::string_view name)
inline

Creates a new element and returns its id.

Definition at line 131 of file element_storage.h.

◆ AllIds()

std::vector< int64_t > operations_research::math_opt::ElementStorage::AllIds ( ) const

Returns all ids of all elements in the model in an unsorted, non-deterministic order.

Definition at line 52 of file element_storage.cc.

◆ EnsureNextIdAtLeast()

void operations_research::math_opt::ElementStorage::EnsureNextIdAtLeast ( const int64_t id)
inline

Increases next_id() to id if it is currently less than id.

Useful for reading a model back from proto, most users should not need to call this directly.

Definition at line 171 of file element_storage.h.

◆ Erase()

bool operations_research::math_opt::ElementStorage::Erase ( const int64_t id)
inline

Deletes an element by id, returning true on success and false if no element was deleted (it was already deleted or the id was not from any existing element).

Definition at line 138 of file element_storage.h.

◆ Exists()

bool operations_research::math_opt::ElementStorage::Exists ( const int64_t id) const
inline

Returns true an element with this id was created and not yet erased.

Definition at line 141 of file element_storage.h.

◆ GetName()

absl::StatusOr< absl::string_view > operations_research::math_opt::ElementStorage::GetName ( const int64_t id) const
inline

Returns the name of this element, or CHECK fails if no element with this id exists.

Definition at line 147 of file element_storage.h.

◆ next_id()

int64_t operations_research::math_opt::ElementStorage::next_id ( ) const
inline

Returns the id that will be used for the next element added.

Note
when no elements have been erased, this equals size().

Definition at line 154 of file element_storage.h.

◆ size()

int64_t operations_research::math_opt::ElementStorage::size ( ) const
inline

Returns the number of elements added and not erased.

Definition at line 163 of file element_storage.h.


The documentation for this class was generated from the following files: