19 #ifndef SCID_HFILTER_H 20 #define SCID_HFILTER_H 36 std::unique_ptr<byte[]> data_;
43 : size_(size), nonzero_(size), capacity_(0) {}
47 nonzero_ = size_ =
size;
63 }
else if (size < size_) {
64 nonzero_ = size -
static_cast<gamenumT>(std::count(
65 data_.get(), data_.get() +
size, 0));
66 }
else if (size > size_) {
67 if (size > capacity_) {
70 std::copy_n(tmp.get(), size_, data_.get());
77 std::fill(data_.get() + size_, data_.get() +
size, val);
85 return data_ ? data_[index] : 1;
93 if (data_[index] != 0)
95 }
else if (data_[index] == 0) {
99 }
else if (value != 1) {
101 std::fill(data_.get(), data_.get() + size_, 1);
102 data_[index] = value;
117 std::fill(data_.get(), data_.get() + size_, value);
118 nonzero_ = (value == 0) ? 0 : size_;
123 void allocate(
size_t size) {
124 auto capacity = (size | 63) + 1;
125 data_ = std::make_unique<byte[]>(capacity);
126 capacity_ = capacity;
180 bool inFilter =
true)
181 : gnum_(gnum), end_(end), hfilter_(hfilter), inFilter_(inFilter) {
184 bool included = (hfilter_->
get(gnum_) != 0);
185 if (included != inFilter_)
193 while (++gnum_ != end_) {
194 bool included = (hfilter_->
get(gnum_) != 0);
195 if (included == inFilter_)
202 return gnum_ != b.gnum_ || hfilter_ != b.hfilter_;
205 return !operator!=(b);
233 : main_(
main), mask_(mask) {}
238 return main_->
Set(gnum, ply + 1);
242 return main_->
Count();
244 return mask_->
Count();
246 return static_cast<size_t>(res);
262 if (res != 0 && mask_ != 0)
263 res = mask_->
Get(gnum);
const_iterator beginInverted() const
const HFilter * operator->() const
void Fill(byte value)
Sets all values.
const_iterator end() const
byte * data()
Return a pointer to the allocated data.
void erase(gamenumT gnum)
byte get(gamenumT gnum) const
byte Get(gamenumT index) const
Gets the value at index.
bool operator==(const Filter *b) const
gamenumT Count() const
Return the number of nonzero values in filter.
HFilter(Filter *main=0, const Filter *mask=0)
gamenumT Size() const
Return the number of elements in filter.
HFilter::const_iterator end() const
int main(int argc, char *argv[])
const_iterator endInverted() const
HFilter::const_iterator begin() const
reference operator*() const
void Set(gamenumT index, byte value)
Sets the value at index.
const gamenumT & reference
bool operator!=(const const_iterator &b) const
const_iterator(gamenumT gnum, gamenumT end, const HFilter *hfilter, bool inFilter=true)
bool operator==(const const_iterator &b) const
void Resize(gamenumT size)
Changes the number of elements stored.
std::ptrdiff_t difference_type
const_iterator begin() const
class const_iterator - iterator for HFilter objects
void insert_or_assign(gamenumT gnum, uint8_t ply)
bool operator!=(const Filter *b) const
std::forward_iterator_tag iterator_category
const HFilter & operator*() const
const_iterator & operator++()
HFilterInverted(const HFilter &hfilter)
size_t sizeInverted() const
class HFilterInverted - iterate through games excluded from a filter