bool Bitmask::exists (const size_t id ) const { size_t element = static_cast<size_t> (div_floor (id, sizeof(size_t))); if (element >= mask.size()) return false; size_t check_mask = 1 << (id - (element * sizeof(size_t))); return (mask[element] & check_mask) != 0; }
void Bitmask::add (const size_t id) { size_t element = static_cast<size_t> (div_floor (id, sizeof(size_t))); while (element >= mask.size()) mask.push_back(0); if (exists(id)) return; size_t add_mask = 1 << (id - (element * sizeof(size_t))); mask[element] |= add_mask; if (id < _max_nonrepair) --holes; }
void div_floor_int(int x, int y, int& w, int& z) { std::tie(w, z) = div_floor(x, y); // const auto r = div_floor(x, y); // w = r.quot; // z = r.rem; }
/* Compute day number of the first day of a given year. */ static int day_from_year(int year) { /* Note: in integer arithmetic, (x / 4) is same as floor(x / 4) for non-negative * values, but is incorrect for negative ones. */ return 365 * (year - 1970) + div_floor(year - 1969, 4) - div_floor(year - 1901, 100) + div_floor(year - 1601, 400); }