24#ifndef FORTRAN_COMMON_FAST_INT_SET_H_
25#define FORTRAN_COMMON_FAST_INT_SET_H_
34 static constexpr int maxValue{N - 1};
36 int size()
const {
return size_; }
37 const int *value()
const {
return &value_[0]; }
39 bool IsValidValue(
int n)
const {
return n >= 0 && n <= maxValue; }
41 void Clear() { size_ = 0; }
43 bool IsEmpty()
const {
return size_ == 0; }
45 void InitializeState() {
46 if (!isFullyInitialized_) {
47 for (
int j{size_}; j < N; ++j) {
48 value_[j] = index_[j] = 0;
50 isFullyInitialized_ =
true;
54 bool Contains(
int n)
const {
55 if (IsValidValue(n)) {
57 return j >= 0 && j < size_ && value_[j] == n;
64 if (IsValidValue(n)) {
65 if (!UncheckedContains(n)) {
66 value_[index_[n] = size_++] = n;
75 if (IsValidValue(n)) {
76 if (UncheckedContains(n)) {
77 int last{value_[--size_]};
78 value_[index_[last] = index_[n]] = last;
86 std::optional<int> PopValue() {
90 return value_[--size_];
95 bool UncheckedContains(
int n)
const {
97 return j >= 0 && j < size_ && value_[j] == n;
103 bool isFullyInitialized_{
false};
Definition: fast-int-set.h:31
Definition: bit-population-count.h:20