From 8caf441629712823d8d97dd13e8cc307d33be693 Mon Sep 17 00:00:00 2001 From: Masataro Asai Date: Sun, 12 Jan 2025 13:09:52 -0500 Subject: [PATCH 01/17] ArrayView::copy_from with memcpy --- src/search/per_state_array.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/search/per_state_array.h b/src/search/per_state_array.h index 1fad15ddc9..a90e86572d 100644 --- a/src/search/per_state_array.h +++ b/src/search/per_state_array.h @@ -5,7 +5,7 @@ #include #include - +#include template class ConstArrayView { @@ -54,6 +54,12 @@ class ArrayView { int size() const { return size_; } + void copy_from(const ArrayView &other) { + assert(size_ == other.size_); + if (p != other.p){ + std::memcpy(p, other.p, sizeof(T) * size_); + } + } }; /* From dfc64fc756068f19fc7df552c0ec88bea5a1ef66 Mon Sep 17 00:00:00 2001 From: Masataro Asai Date: Fri, 5 Jul 2024 19:19:59 -0400 Subject: [PATCH 02/17] DynamicBitset: copy constructor, copy assignment op, resize --- src/search/algorithms/dynamic_bitset.h | 29 +++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/search/algorithms/dynamic_bitset.h b/src/search/algorithms/dynamic_bitset.h index 68fffab158..1f1cc8640a 100644 --- a/src/search/algorithms/dynamic_bitset.h +++ b/src/search/algorithms/dynamic_bitset.h @@ -17,7 +17,7 @@ class DynamicBitset { "Block type must be unsigned"); std::vector blocks; - const std::size_t num_bits; + std::size_t num_bits; static const Block zeros; static const Block ones; @@ -55,15 +55,42 @@ class DynamicBitset { } public: + explicit DynamicBitset() + : blocks(0, zeros), + num_bits(0) { + } explicit DynamicBitset(std::size_t num_bits) : blocks(compute_num_blocks(num_bits), zeros), num_bits(num_bits) { } + // copy constructor + DynamicBitset(const DynamicBitset &other) + : blocks(other.blocks), + num_bits(other.num_bits) { + } + // copy assignment operator + DynamicBitset& operator=(const DynamicBitset& other) { + if (this == &other) { + return *this; + } + blocks = other.blocks; + num_bits = other.num_bits; + return *this; + } + std::size_t size() const { return num_bits; } + void resize(std::size_t _num_bits){ + if (num_bits != _num_bits){ + num_bits = _num_bits; + std::size_t num_blocks = compute_num_blocks(num_bits); + blocks.resize(num_blocks, zeros); + } + } + /* Count the number of set bits. From c0bf36b9fb4a4953c64c007824b86fb273c102ba Mon Sep 17 00:00:00 2001 From: Masataro Asai Date: Sat, 6 Jul 2024 16:44:40 -0400 Subject: [PATCH 03/17] DynamicBitset: count uses popcount --- src/search/algorithms/dynamic_bitset.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/search/algorithms/dynamic_bitset.h b/src/search/algorithms/dynamic_bitset.h index 1f1cc8640a..d296217f7a 100644 --- a/src/search/algorithms/dynamic_bitset.h +++ b/src/search/algorithms/dynamic_bitset.h @@ -4,6 +4,7 @@ #include #include #include +#include /* Poor man's version of boost::dynamic_bitset, mostly copied from there. @@ -99,9 +100,12 @@ class DynamicBitset { */ int count() const { int result = 0; - for (std::size_t pos = 0; pos < num_bits; ++pos) { - result += static_cast(test(pos)); - } + // for (std::size_t pos = 0; pos < num_bits; ++pos) { + // result += static_cast(test(pos)); + // } + for (Block blk : blocks){ + result += std::popcount(blk); + } return result; } From 4b266b103012651943c6e6edb6f989ddc48dddc2 Mon Sep 17 00:00:00 2001 From: Masataro Asai Date: Fri, 12 Jul 2024 15:43:15 -0400 Subject: [PATCH 04/17] DynamicBitset: update_and/ior/nand/nor/xor --- src/search/algorithms/dynamic_bitset.h | 32 ++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/search/algorithms/dynamic_bitset.h b/src/search/algorithms/dynamic_bitset.h index d296217f7a..703c4f9376 100644 --- a/src/search/algorithms/dynamic_bitset.h +++ b/src/search/algorithms/dynamic_bitset.h @@ -154,6 +154,38 @@ class DynamicBitset { } return true; } + + void update_and(const DynamicBitset &other) { + assert(size() == other.size()); + for (std::size_t i = 0; i < blocks.size(); ++i) { + blocks[i] &= other.blocks[i]; + } + } + void update_or(const DynamicBitset &other) { + assert(size() == other.size()); + for (std::size_t i = 0; i < blocks.size(); ++i) { + blocks[i] |= other.blocks[i]; + } + } + void update_andc(const DynamicBitset &other) { // and complement + assert(size() == other.size()); + for (std::size_t i = 0; i < blocks.size(); ++i) { + blocks[i] &= ~(other.blocks[i]); + } + } + void update_orc(const DynamicBitset &other) { // or complement + assert(size() == other.size()); + for (std::size_t i = 0; i < blocks.size(); ++i) { + blocks[i] |= ~(other.blocks[i]); + } + } + void update_xor(const DynamicBitset &other) { + assert(size() == other.size()); + for (std::size_t i = 0; i < blocks.size(); ++i) { + blocks[i] ^= other.blocks[i]; + } + } + }; template From 013b0c7b1b232bb19901c2c831856d6740635e1b Mon Sep 17 00:00:00 2001 From: Masataro Asai Date: Tue, 16 Jul 2024 16:18:09 -0400 Subject: [PATCH 05/17] DynamicBitset: update_not --- src/search/algorithms/dynamic_bitset.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/search/algorithms/dynamic_bitset.h b/src/search/algorithms/dynamic_bitset.h index 703c4f9376..249418e542 100644 --- a/src/search/algorithms/dynamic_bitset.h +++ b/src/search/algorithms/dynamic_bitset.h @@ -155,6 +155,11 @@ class DynamicBitset { return true; } + void update_not() { + for (std::size_t i = 0; i < blocks.size(); ++i) { + blocks[i] = ~blocks[i]; + } + } void update_and(const DynamicBitset &other) { assert(size() == other.size()); for (std::size_t i = 0; i < blocks.size(); ++i) { From 7274b2ab0f7deccbd517dc0a31e156beaeb71b3c Mon Sep 17 00:00:00 2001 From: Masataro Asai Date: Tue, 16 Jul 2024 16:19:14 -0400 Subject: [PATCH 06/17] DynamicBitset: overloading &= |= ^= --- src/search/algorithms/dynamic_bitset.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/search/algorithms/dynamic_bitset.h b/src/search/algorithms/dynamic_bitset.h index 249418e542..6a4864c0a5 100644 --- a/src/search/algorithms/dynamic_bitset.h +++ b/src/search/algorithms/dynamic_bitset.h @@ -190,7 +190,18 @@ class DynamicBitset { blocks[i] ^= other.blocks[i]; } } - + DynamicBitset& operator&=(const DynamicBitset &other){ + update_and(other); + return *this; + } + DynamicBitset& operator|=(const DynamicBitset &other){ + update_or(other); + return *this; + } + DynamicBitset& operator^=(const DynamicBitset &other){ + update_xor(other); + return *this; + } }; template From b45d5959391ec3ec7318d914b29217b6c171c2b9 Mon Sep 17 00:00:00 2001 From: Masataro Asai Date: Tue, 16 Jul 2024 16:29:37 -0400 Subject: [PATCH 07/17] DynamicBitset: overloading ~ && || ^ --- src/search/algorithms/dynamic_bitset.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/search/algorithms/dynamic_bitset.h b/src/search/algorithms/dynamic_bitset.h index 6a4864c0a5..31876c697b 100644 --- a/src/search/algorithms/dynamic_bitset.h +++ b/src/search/algorithms/dynamic_bitset.h @@ -204,6 +204,28 @@ class DynamicBitset { } }; +template +DynamicBitset operator~(DynamicBitset copy){ + copy.update_not(); + return copy; +} +template +DynamicBitset operator&&(DynamicBitset copy, const DynamicBitset &other){ + copy &= other; + return copy; +} +template +DynamicBitset operator||(DynamicBitset copy, const DynamicBitset &other){ + copy |= other; + return copy; +} +template +DynamicBitset operator^(DynamicBitset copy, const DynamicBitset &other){ + copy ^= other; + return copy; +} + + template const Block DynamicBitset::zeros = Block(0); From aca06a9c69af967c2a27c0e87723497cf6bb6af2 Mon Sep 17 00:00:00 2001 From: Masataro Asai Date: Sun, 12 Jan 2025 13:12:49 -0500 Subject: [PATCH 08/17] DynamicBitset: any --- src/search/algorithms/dynamic_bitset.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/search/algorithms/dynamic_bitset.h b/src/search/algorithms/dynamic_bitset.h index 31876c697b..3a17de6889 100644 --- a/src/search/algorithms/dynamic_bitset.h +++ b/src/search/algorithms/dynamic_bitset.h @@ -108,6 +108,14 @@ class DynamicBitset { } return result; } + bool any() const{ + for (Block blk : blocks){ + if (blk != 0){ + return true; + } + } + return false; + } void set() { std::fill(blocks.begin(), blocks.end(), ones); From 9df5125b45d35901a3f9297403d8c59e5c51a45b Mon Sep 17 00:00:00 2001 From: Masataro Asai Date: Fri, 12 Jul 2024 12:15:08 -0400 Subject: [PATCH 09/17] BitsetView::count with popcount --- src/search/per_state_bitset.cc | 7 +++++++ src/search/per_state_bitset.h | 1 + 2 files changed, 8 insertions(+) diff --git a/src/search/per_state_bitset.cc b/src/search/per_state_bitset.cc index 374b5213fb..b24bc757f3 100644 --- a/src/search/per_state_bitset.cc +++ b/src/search/per_state_bitset.cc @@ -55,6 +55,13 @@ int BitsetView::size() const { return num_bits; } +int BitsetView::count() const { + int result = 0; + for (int i = 0; i < data.size(); i++){ + result += std::popcount(data[i]); + } + return result; +} static vector pack_bit_vector(const vector &bits) { int num_bits = bits.size(); diff --git a/src/search/per_state_bitset.h b/src/search/per_state_bitset.h index 21c12d8eb4..c99b9ac67e 100644 --- a/src/search/per_state_bitset.h +++ b/src/search/per_state_bitset.h @@ -62,6 +62,7 @@ class BitsetView { bool test(int index) const; void intersect(const BitsetView &other); int size() const; + int count() const; }; From d4d1d1095e5b82e8edceff2c7c0828e177f6daff Mon Sep 17 00:00:00 2001 From: Masataro Asai Date: Fri, 12 Jul 2024 12:52:58 -0400 Subject: [PATCH 10/17] BitsetView::copy_from with memcpy --- src/search/per_state_bitset.cc | 8 ++++++++ src/search/per_state_bitset.h | 1 + 2 files changed, 9 insertions(+) diff --git a/src/search/per_state_bitset.cc b/src/search/per_state_bitset.cc index b24bc757f3..0f2f359e1b 100644 --- a/src/search/per_state_bitset.cc +++ b/src/search/per_state_bitset.cc @@ -63,6 +63,14 @@ int BitsetView::count() const { return result; } +void BitsetView::copy_from(const BitsetView& other) { + assert(num_bits == other.num_bits); + // for (int i = 0; i < data.size(); i++){ + // data[i] = other.data[i]; + // } + data.copy_from(other.data); +} + static vector pack_bit_vector(const vector &bits) { int num_bits = bits.size(); int num_blocks = BitsetMath::compute_num_blocks(num_bits); diff --git a/src/search/per_state_bitset.h b/src/search/per_state_bitset.h index c99b9ac67e..da7373d6d1 100644 --- a/src/search/per_state_bitset.h +++ b/src/search/per_state_bitset.h @@ -63,6 +63,7 @@ class BitsetView { void intersect(const BitsetView &other); int size() const; int count() const; + void copy_from(const BitsetView& other); }; From e067c98ce11a24bad9c92d74a0476ecfc8bc3108 Mon Sep 17 00:00:00 2001 From: Masataro Asai Date: Fri, 12 Jul 2024 17:37:02 -0400 Subject: [PATCH 11/17] BitsetView::update_and/or/andc/orc/xor --- src/search/per_state_bitset.cc | 32 ++++++++++++++++++++++++++++++++ src/search/per_state_bitset.h | 5 +++++ 2 files changed, 37 insertions(+) diff --git a/src/search/per_state_bitset.cc b/src/search/per_state_bitset.cc index 0f2f359e1b..ecc9f8447d 100644 --- a/src/search/per_state_bitset.cc +++ b/src/search/per_state_bitset.cc @@ -71,6 +71,38 @@ void BitsetView::copy_from(const BitsetView& other) { data.copy_from(other.data); } + +void BitsetView::update_and(const BitsetView &other) { + assert(size() == other.size()); + for (int i = 0; i < data.size(); ++i) { + data[i] &= other.data[i]; + } +} +void BitsetView::update_or(const BitsetView &other) { + assert(size() == other.size()); + for (int i = 0; i < data.size(); ++i) { + data[i] |= other.data[i]; + } +} +void BitsetView::update_andc(const BitsetView &other) { // and complement + assert(size() == other.size()); + for (int i = 0; i < data.size(); ++i) { + data[i] &= ~(other.data[i]); + } +} +void BitsetView::update_orc(const BitsetView &other) { // or complement + assert(size() == other.size()); + for (int i = 0; i < data.size(); ++i) { + data[i] |= ~(other.data[i]); + } +} +void BitsetView::update_xor(const BitsetView &other) { + assert(size() == other.size()); + for (int i = 0; i < data.size(); ++i) { + data[i] ^= other.data[i]; + } +} + static vector pack_bit_vector(const vector &bits) { int num_bits = bits.size(); int num_blocks = BitsetMath::compute_num_blocks(num_bits); diff --git a/src/search/per_state_bitset.h b/src/search/per_state_bitset.h index da7373d6d1..fa1e90fdb0 100644 --- a/src/search/per_state_bitset.h +++ b/src/search/per_state_bitset.h @@ -64,6 +64,11 @@ class BitsetView { int size() const; int count() const; void copy_from(const BitsetView& other); + void update_and(const BitsetView &other); + void update_or(const BitsetView &other); + void update_andc(const BitsetView &other); + void update_orc(const BitsetView &other); + void update_xor(const BitsetView &other); }; From c110adf9c4ac5082e64134d12f094f9075b00639 Mon Sep 17 00:00:00 2001 From: Masataro Asai Date: Tue, 16 Jul 2024 16:36:16 -0400 Subject: [PATCH 12/17] BitsetView: update_not --- src/search/per_state_bitset.cc | 5 +++++ src/search/per_state_bitset.h | 1 + 2 files changed, 6 insertions(+) diff --git a/src/search/per_state_bitset.cc b/src/search/per_state_bitset.cc index ecc9f8447d..501fa54d1c 100644 --- a/src/search/per_state_bitset.cc +++ b/src/search/per_state_bitset.cc @@ -72,6 +72,11 @@ void BitsetView::copy_from(const BitsetView& other) { } +void BitsetView::update_not() { + for (int i = 0; i < data.size(); ++i) { + data[i] = ~data[i]; + } +} void BitsetView::update_and(const BitsetView &other) { assert(size() == other.size()); for (int i = 0; i < data.size(); ++i) { diff --git a/src/search/per_state_bitset.h b/src/search/per_state_bitset.h index fa1e90fdb0..06c6980d31 100644 --- a/src/search/per_state_bitset.h +++ b/src/search/per_state_bitset.h @@ -64,6 +64,7 @@ class BitsetView { int size() const; int count() const; void copy_from(const BitsetView& other); + void update_not(); void update_and(const BitsetView &other); void update_or(const BitsetView &other); void update_andc(const BitsetView &other); From 121f6a46e9c9a9738d9fadfe707508a6a61cae74 Mon Sep 17 00:00:00 2001 From: Masataro Asai Date: Tue, 16 Jul 2024 16:42:07 -0400 Subject: [PATCH 13/17] BitsetView: overloading &= |= ^= --- src/search/per_state_bitset.cc | 13 +++++++++++++ src/search/per_state_bitset.h | 3 +++ 2 files changed, 16 insertions(+) diff --git a/src/search/per_state_bitset.cc b/src/search/per_state_bitset.cc index 501fa54d1c..cdcf70808e 100644 --- a/src/search/per_state_bitset.cc +++ b/src/search/per_state_bitset.cc @@ -108,6 +108,19 @@ void BitsetView::update_xor(const BitsetView &other) { } } +BitsetView& BitsetView::operator&=(const BitsetView &other){ + update_and(other); + return *this; +} +BitsetView& BitsetView::operator|=(const BitsetView &other){ + update_or(other); + return *this; +} +BitsetView& BitsetView::operator^=(const BitsetView &other){ + update_xor(other); + return *this; +} + static vector pack_bit_vector(const vector &bits) { int num_bits = bits.size(); int num_blocks = BitsetMath::compute_num_blocks(num_bits); diff --git a/src/search/per_state_bitset.h b/src/search/per_state_bitset.h index 06c6980d31..9a081071aa 100644 --- a/src/search/per_state_bitset.h +++ b/src/search/per_state_bitset.h @@ -70,6 +70,9 @@ class BitsetView { void update_andc(const BitsetView &other); void update_orc(const BitsetView &other); void update_xor(const BitsetView &other); + BitsetView& operator&=(const BitsetView &other); + BitsetView& operator|=(const BitsetView &other); + BitsetView& operator^=(const BitsetView &other); }; From 00d469e5c05da1dcc02fc67643e20d9c08cfadfb Mon Sep 17 00:00:00 2001 From: Masataro Asai Date: Tue, 16 Jul 2024 16:45:27 -0400 Subject: [PATCH 14/17] BitsetView: overloading ~ && || ^ --- src/search/per_state_bitset.cc | 17 +++++++++++++++++ src/search/per_state_bitset.h | 5 +++++ 2 files changed, 22 insertions(+) diff --git a/src/search/per_state_bitset.cc b/src/search/per_state_bitset.cc index cdcf70808e..bebb9c634f 100644 --- a/src/search/per_state_bitset.cc +++ b/src/search/per_state_bitset.cc @@ -121,6 +121,23 @@ BitsetView& BitsetView::operator^=(const BitsetView &other){ return *this; } +BitsetView operator~(BitsetView copy){ + copy.update_not(); + return copy; +} +BitsetView operator&&(BitsetView copy, const BitsetView &other){ + copy &= other; + return copy; +} +BitsetView operator||(BitsetView copy, const BitsetView &other){ + copy |= other; + return copy; +} +BitsetView operator^(BitsetView copy, const BitsetView &other){ + copy ^= other; + return copy; +} + static vector pack_bit_vector(const vector &bits) { int num_bits = bits.size(); int num_blocks = BitsetMath::compute_num_blocks(num_bits); diff --git a/src/search/per_state_bitset.h b/src/search/per_state_bitset.h index 9a081071aa..47ec700d81 100644 --- a/src/search/per_state_bitset.h +++ b/src/search/per_state_bitset.h @@ -75,6 +75,11 @@ class BitsetView { BitsetView& operator^=(const BitsetView &other); }; +BitsetView operator~(BitsetView copy); +BitsetView operator&&(BitsetView copy, const BitsetView &other); +BitsetView operator||(BitsetView copy, const BitsetView &other); +BitsetView operator^(BitsetView copy, const BitsetView &other); + class PerStateBitset { int num_bits_per_entry; From 40a291ae85f8360b2f760f8cb77582814ea265a3 Mon Sep 17 00:00:00 2001 From: Masataro Asai Date: Tue, 16 Jul 2024 17:00:21 -0400 Subject: [PATCH 15/17] BitsetView: any --- src/search/per_state_bitset.cc | 9 +++++++++ src/search/per_state_bitset.h | 1 + 2 files changed, 10 insertions(+) diff --git a/src/search/per_state_bitset.cc b/src/search/per_state_bitset.cc index bebb9c634f..3e176c0f47 100644 --- a/src/search/per_state_bitset.cc +++ b/src/search/per_state_bitset.cc @@ -63,6 +63,15 @@ int BitsetView::count() const { return result; } +bool BitsetView::any() const { + for (int i = 0; i < data.size(); i++){ + if (data[i] != 0){ + return true; + } + } + return false; +} + void BitsetView::copy_from(const BitsetView& other) { assert(num_bits == other.num_bits); // for (int i = 0; i < data.size(); i++){ diff --git a/src/search/per_state_bitset.h b/src/search/per_state_bitset.h index 47ec700d81..acd0639cd5 100644 --- a/src/search/per_state_bitset.h +++ b/src/search/per_state_bitset.h @@ -63,6 +63,7 @@ class BitsetView { void intersect(const BitsetView &other); int size() const; int count() const; + bool any() const; void copy_from(const BitsetView& other); void update_not(); void update_and(const BitsetView &other); From e9df443c2d4f2a39092293ac1431c46ff6e345c2 Mon Sep 17 00:00:00 2001 From: Masataro Asai Date: Fri, 12 Jul 2024 17:47:06 -0400 Subject: [PATCH 16/17] make dynamic bitset and bitsetview interoperable --- src/search/algorithms/dynamic_bitset.h | 4 ++ src/search/per_state_bitset.cc | 55 +++++++++++++++++++++++--- src/search/per_state_bitset.h | 28 ++++++++++--- 3 files changed, 75 insertions(+), 12 deletions(-) diff --git a/src/search/algorithms/dynamic_bitset.h b/src/search/algorithms/dynamic_bitset.h index 3a17de6889..f2e891b6ba 100644 --- a/src/search/algorithms/dynamic_bitset.h +++ b/src/search/algorithms/dynamic_bitset.h @@ -10,6 +10,8 @@ Poor man's version of boost::dynamic_bitset, mostly copied from there. */ +class BitsetView; + namespace dynamic_bitset { template class DynamicBitset { @@ -17,6 +19,8 @@ class DynamicBitset { !std::numeric_limits::is_signed, "Block type must be unsigned"); + friend class ::BitsetView; // in ../per_state_bitset.h , global namespace + std::vector blocks; std::size_t num_bits; diff --git a/src/search/per_state_bitset.cc b/src/search/per_state_bitset.cc index 3e176c0f47..92c1eddc26 100644 --- a/src/search/per_state_bitset.cc +++ b/src/search/per_state_bitset.cc @@ -117,15 +117,55 @@ void BitsetView::update_xor(const BitsetView &other) { } } -BitsetView& BitsetView::operator&=(const BitsetView &other){ +void BitsetView::copy_from(const dynamic_bitset::DynamicBitset& other) { + assert(num_bits == other.num_bits); + for (int i = 0; i < data.size(); i++){ + data[i] = other.blocks[i]; + } +} +void BitsetView::update_and(const dynamic_bitset::DynamicBitset &other) { + assert(size() == other.size()); + for (int i = 0; i < data.size(); ++i) { + data[i] &= other.blocks[i]; + } +} +void BitsetView::update_or(const dynamic_bitset::DynamicBitset &other) { + assert(size() == other.size()); + for (int i = 0; i < data.size(); ++i) { + data[i] |= other.blocks[i]; + } +} +void BitsetView::update_andc(const dynamic_bitset::DynamicBitset &other) { // and complement + assert(size() == other.size()); + for (int i = 0; i < data.size(); ++i) { + data[i] &= ~(other.blocks[i]); + } +} +void BitsetView::update_orc(const dynamic_bitset::DynamicBitset &other) { // or complement + assert(size() == other.size()); + for (int i = 0; i < data.size(); ++i) { + data[i] |= ~(other.blocks[i]); + } +} +void BitsetView::update_xor(const dynamic_bitset::DynamicBitset &other) { + assert(size() == other.size()); + for (int i = 0; i < data.size(); ++i) { + data[i] ^= other.blocks[i]; + } +} + +template +BitsetView& BitsetView::operator&=(const T &other){ update_and(other); return *this; } -BitsetView& BitsetView::operator|=(const BitsetView &other){ +template +BitsetView& BitsetView::operator|=(const T &other){ update_or(other); return *this; } -BitsetView& BitsetView::operator^=(const BitsetView &other){ +template +BitsetView& BitsetView::operator^=(const T &other){ update_xor(other); return *this; } @@ -134,15 +174,18 @@ BitsetView operator~(BitsetView copy){ copy.update_not(); return copy; } -BitsetView operator&&(BitsetView copy, const BitsetView &other){ +template +BitsetView operator&&(BitsetView copy, const T &other){ copy &= other; return copy; } -BitsetView operator||(BitsetView copy, const BitsetView &other){ +template +BitsetView operator||(BitsetView copy, const T &other){ copy |= other; return copy; } -BitsetView operator^(BitsetView copy, const BitsetView &other){ +template +BitsetView operator^(BitsetView copy, const T &other){ copy ^= other; return copy; } diff --git a/src/search/per_state_bitset.h b/src/search/per_state_bitset.h index acd0639cd5..6f27aa2f97 100644 --- a/src/search/per_state_bitset.h +++ b/src/search/per_state_bitset.h @@ -2,6 +2,7 @@ #define PER_STATE_BITSET_H #include "per_state_array.h" +#include "algorithms/dynamic_bitset.h" #include @@ -42,6 +43,9 @@ class ConstBitsetView { class BitsetView { + + friend class dynamic_bitset::DynamicBitset; + ArrayView data; int num_bits; public: @@ -71,15 +75,27 @@ class BitsetView { void update_andc(const BitsetView &other); void update_orc(const BitsetView &other); void update_xor(const BitsetView &other); - BitsetView& operator&=(const BitsetView &other); - BitsetView& operator|=(const BitsetView &other); - BitsetView& operator^=(const BitsetView &other); + void copy_from(const dynamic_bitset::DynamicBitset& other); + void update_and(const dynamic_bitset::DynamicBitset &other); + void update_or(const dynamic_bitset::DynamicBitset &other); + void update_andc(const dynamic_bitset::DynamicBitset &other); + void update_orc(const dynamic_bitset::DynamicBitset &other); + void update_xor(const dynamic_bitset::DynamicBitset &other); + template + BitsetView& operator&=(const T &other); + template + BitsetView& operator|=(const T &other); + template + BitsetView& operator^=(const T &other); }; BitsetView operator~(BitsetView copy); -BitsetView operator&&(BitsetView copy, const BitsetView &other); -BitsetView operator||(BitsetView copy, const BitsetView &other); -BitsetView operator^(BitsetView copy, const BitsetView &other); +template +BitsetView operator&&(BitsetView copy, const T &other); +template +BitsetView operator||(BitsetView copy, const T &other); +template +BitsetView operator^(BitsetView copy, const T &other); class PerStateBitset { From ed2bdb00e2f1a72f042af6477a42ce0f1c16e5b3 Mon Sep 17 00:00:00 2001 From: Masataro Asai Date: Sun, 12 Jan 2025 13:46:15 -0500 Subject: [PATCH 17/17] BitsetView: use long int to make popcount faster (callgrind ir/call 2227 -> 1135) --- src/search/per_state_bitset.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/search/per_state_bitset.h b/src/search/per_state_bitset.h index 6f27aa2f97..a283673b5a 100644 --- a/src/search/per_state_bitset.h +++ b/src/search/per_state_bitset.h @@ -9,7 +9,7 @@ class BitsetMath { public: - using Block = unsigned int; + using Block = unsigned long int; static_assert( !std::numeric_limits::is_signed, "Block type must be unsigned");