[bit-set] Implement standard-5 methods plus swap

This commit is contained in:
Behdad Esfahbod 2021-11-01 21:14:12 -06:00
parent 11eadb5d28
commit 1e3f57c079
1 changed files with 16 additions and 8 deletions

View File

@ -35,13 +35,21 @@
struct hb_bit_set_t
{
hb_bit_set_t () { init (); }
~hb_bit_set_t () { fini (); }
hb_bit_set_t () = default;
~hb_bit_set_t () = default;
hb_bit_set_t (const hb_bit_set_t& other) : hb_bit_set_t () { set (other); }
void operator= (const hb_bit_set_t& other) { set (other); }
// TODO Add move construtor/assign
// TODO Add constructor for Iterator; with specialization for (sorted) vector / array?
hb_bit_set_t ( hb_bit_set_t&& other) : hb_bit_set_t () { hb_swap (*this, other); }
hb_bit_set_t& operator= (const hb_bit_set_t& other) { set (other); return *this; }
hb_bit_set_t& operator= (hb_bit_set_t&& other) { hb_swap (*this, other); return *this; }
friend void swap (hb_bit_set_t &a, hb_bit_set_t &b)
{
hb_swap (a.successful, b.successful);
hb_swap (a.population, b.population);
hb_swap (a.last_page_lookup, b.last_page_lookup);
hb_swap (a.page_map, b.page_map);
hb_swap (a.pages, b.pages);
}
void init ()
{
@ -67,9 +75,9 @@ struct hb_bit_set_t
uint32_t index;
};
bool successful; /* Allocations successful */
mutable unsigned int population;
mutable unsigned int last_page_lookup;
bool successful = true; /* Allocations successful */
mutable unsigned int population = 0;
mutable unsigned int last_page_lookup = 0;
hb_sorted_vector_t<page_map_t> page_map;
hb_vector_t<page_t> pages;