From ede775a89c1f5e8bcd6be7ce776f3bc618289788 Mon Sep 17 00:00:00 2001 From: Guillaume Marcais Date: Sat, 1 Oct 2022 09:09:02 -0400 Subject: [PATCH 1/7] Add zero() method * Zeros out the entire array memory region. Every element is equal to 0 after calling zero(). --- include/compact_iterator.hpp | 2 +- include/compact_vector.hpp | 4 ++++ unittests/test_compact_vector.cc | 10 ++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/include/compact_iterator.hpp b/include/compact_iterator.hpp index 5f1f1a7..48a2125 100644 --- a/include/compact_iterator.hpp +++ b/include/compact_iterator.hpp @@ -628,7 +628,7 @@ class common { template void set_bits(W x, unsigned bits) { Derived& self = *static_cast(this); - gs::set(x, self.m_ptr, bits, self.m_offset); + gs::template set(x, self.m_ptr, bits, self.m_offset); } // Get, i.e., don't use fetch diff --git a/include/compact_vector.hpp b/include/compact_vector.hpp index 3360eac..86fce49 100644 --- a/include/compact_vector.hpp +++ b/include/compact_vector.hpp @@ -241,6 +241,10 @@ class vector { static constexpr unsigned static_bits() { return BITS; } static constexpr unsigned used_bits() { return UB; } static constexpr bool thread_safe() { return TS; } + // Zero out the entire memory array. Every element is 0 after this call. + void zero() { + std::fill_n(get(), elements_to_words(capacity(), bits()), (W)0); + } protected: void enlarge(size_t given = 0) { diff --git a/unittests/test_compact_vector.cc b/unittests/test_compact_vector.cc index 6b32b38..2fe0c8f 100644 --- a/unittests/test_compact_vector.cc +++ b/unittests/test_compact_vector.cc @@ -213,6 +213,16 @@ TEST_F(CompactVectorFixture, Erase) { } } // CompactVectorFixture.Erase +TEST_F(CompactVectorFixture, Zero) { + vector1.zero(); + vector2.zero(); + + for(size_t i = 0; i < vector1.size(); ++i) + EXPECT_EQ((int)0, vector1[i]); + for(size_t i = 0; i < vector2.size(); ++i) + EXPECT_EQ((int)0, vector2[i]); +} // CompactVectorFixture.Zero + // // Testing compact::vector_imp::vector for different vector type, word type, bits and used bits value. From 79b1bf28784911801dece6eb250d91904f5186e7 Mon Sep 17 00:00:00 2001 From: gmarcais Date: Sat, 1 Oct 2022 09:21:12 -0400 Subject: [PATCH 2/7] Show CI status badge --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index dc7239a..4506f75 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +![CI](https://github.com/gmarcais/compact_vector/actions/workflows/c-cpp.yml/badge.svg?event=push) + # Compact vector This library provide a bit-packed vector like data structure for From 000bb052b14ad06e7acf1b9d9bcfa9f9d4915263 Mon Sep 17 00:00:00 2001 From: Bouncner Date: Mon, 20 Feb 2023 20:04:29 +0100 Subject: [PATCH 3/7] Fix GCC 12 issue --- include/compact_iterator.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/compact_iterator.hpp b/include/compact_iterator.hpp index 5f1f1a7..48a2125 100644 --- a/include/compact_iterator.hpp +++ b/include/compact_iterator.hpp @@ -628,7 +628,7 @@ class common { template void set_bits(W x, unsigned bits) { Derived& self = *static_cast(this); - gs::set(x, self.m_ptr, bits, self.m_offset); + gs::template set(x, self.m_ptr, bits, self.m_offset); } // Get, i.e., don't use fetch From 22b6557c3539e640b8f5084a4af0e45361f5805b Mon Sep 17 00:00:00 2001 From: gmarcais Date: Mon, 20 Feb 2023 15:37:53 -0500 Subject: [PATCH 4/7] Update to Ubuntu 22.04 and newer compilers * Use g++ 12 and clang++ 14 * Trigger workflow on PRs on develop --- .github/workflows/c-cpp.yml | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/.github/workflows/c-cpp.yml b/.github/workflows/c-cpp.yml index 6de85ad..65544fc 100644 --- a/.github/workflows/c-cpp.yml +++ b/.github/workflows/c-cpp.yml @@ -6,7 +6,7 @@ on: - master - develop pull_request: - branches: [ master ] + branches: [ master, develop ] jobs: test: @@ -14,9 +14,9 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ubuntu-20.04] + os: [ubuntu-22.04] standard: [c++11, c++14, c++17, c++20] - compiler: [g++-10, clang++-12] + compiler: [g++-12, clang++-14] steps: - uses: actions/checkout@v3 @@ -31,7 +31,7 @@ jobs: test_libcxx: name: Unit tests with clang and libc++ - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 strategy: matrix: standard: [c++11, c++14, c++17, c++20] @@ -41,17 +41,16 @@ jobs: - name: Install gtest run: | set -e - sudo apt install libc++-12-dev libc++1-12 libc++abi1-12 libc++abi-12-dev mkdir gtest build curl -L https://github.com/google/googletest/archive/refs/tags/release-1.11.0.tar.gz | tar zx --strip-components=1 -C gtest cd build - cmake ../gtest -DBUILD_GMOCK=OFF -DCMAKE_CXX_COMPILER=clang++-12 -DCMAKE_CXX_FLAGS="-stdlib=libc++" -DCMAKE_SHARED_LINKER_FLAGS="-stdlib=libc++" + cmake ../gtest -DBUILD_GMOCK=OFF -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_CXX_FLAGS="-stdlib=libc++" -DCMAKE_SHARED_LINKER_FLAGS="-stdlib=libc++" make -j 2 sudo make install sudo ldconfig - name: configure run: | autoreconf -fi - PKG_CONFIG_PATH=/usr/local/lib/pkgconfig ./configure CC=clang-12 CXX=clang++-12 CXXFLAGS="-std=${{ matrix.standard }} -Wall -Werror -stdlib=libc++" LDFLAGS="-stdlib=libc++" || cat config.log + PKG_CONFIG_PATH=/usr/local/lib/pkgconfig ./configure CC=clang CXX=clang++ CXXFLAGS="-std=${{ matrix.standard }} -Wall -Werror -stdlib=libc++" LDFLAGS="-stdlib=libc++" || cat config.log - name: check ${{ matrix.standard }} run: make -j 2 check From d2cb5f3bf3b50eb74aefc7ad441def2ada6acb97 Mon Sep 17 00:00:00 2001 From: Guillaume Marcais Date: Mon, 20 Feb 2023 16:16:01 -0500 Subject: [PATCH 5/7] Typos in README.md --- README.md | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 4506f75..9946561 100644 --- a/README.md +++ b/README.md @@ -2,16 +2,15 @@ # Compact vector -This library provide a bit-packed vector like data structure for -storing integer types. +This library provides a bit-packed vector like data structure for storing +integer types. -* The number of bits used by each entry is specified either at - compile time as a template argument, or at runtime. More - optimizations are performed when the number of bits is known at - compile time. +* The number of bits used by each entry is specified either at compile time as a + template argument, or at runtime as an argument to the constructor. More + optimizations are performed when the number of bits is known at compile time. * The vector supports storing both signed and unsigned integer types. -* The library provides two variant of vectors (`vector` and - `ts_vector`) with different multi-threading guarantees. +* The library provides two variant of vectors (`vector` and `ts_vector`) with + different multi-threading guarantees. # Installation @@ -30,8 +29,8 @@ To install the library globally on a system, use: make install ``` -After installation, use `pkg-config --cflags compact_vector` to use -the library. +After installation, use `pkg-config --cflags compact_vector` get the compiler +flags. ## Testing @@ -89,8 +88,7 @@ from two different threads. ## Thread safe vector class -The class `compact::ts_vector` is thread safe in the sense that if `i -!= j`, then accessing `a[i]` and `a[j]` from two different threads is -safe (just like `std::vector`). There is a performance penalties as -updates to the data structure are now performed with CAS (compare and -swap) atomic operations. +The class `compact::ts_vector` is thread safe in the sense that if `i != j`, +then accessing `a[i]` and `a[j]` from two different threads is safe (just like +`std::vector`). There is a performance penalty as updates to the data structure +are now performed with CAS (compare and swap) atomic operations. From d80d685556cf91f980b3fedac9efba5ec3810a68 Mon Sep 17 00:00:00 2001 From: Guillaume Marcais Date: Mon, 20 Feb 2023 16:19:48 -0500 Subject: [PATCH 6/7] m4 directory --- configure.ac | 2 +- m4/.gitignore | 0 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 m4/.gitignore diff --git a/configure.ac b/configure.ac index b1fffe9..810e851 100644 --- a/configure.ac +++ b/configure.ac @@ -1,4 +1,4 @@ -AC_INIT([compact_vector],[0.1.1],[gmarcais@cs.cmu.edu]) +AC_INIT([compact_vector],[0.1.2],[gmarcais@cs.cmu.edu]) AC_CONFIG_AUX_DIR([build-aux]) AM_SILENT_RULES([yes]) AC_CONFIG_SRCDIR([include/compact_vector.hpp]) diff --git a/m4/.gitignore b/m4/.gitignore new file mode 100644 index 0000000..e69de29 From 04c7f29b30361ba6b58c8afe58199bd8565555f7 Mon Sep 17 00:00:00 2001 From: Guillaume Marcais Date: Mon, 20 Feb 2023 16:48:45 -0500 Subject: [PATCH 7/7] Requires C++11 from header. * Remove -std=c++11 from CXXFLAGS but require c++11 in the compact_iterator.hpp. --- Makefile.am | 2 +- include/compact_iterator.hpp | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Makefile.am b/Makefile.am index 207ec54..ac696a2 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,4 +1,4 @@ -AM_CXXFLAGS = -Wall -Werror -std=c++11 -I$(top_srcdir)/include -I$(top_srcdir)/tests +AM_CXXFLAGS = -Wall -Werror -I$(top_srcdir)/include -I$(top_srcdir)/tests pkginclude_HEADERS = include/compact_iterator.hpp \ include/compact_vector.hpp \ diff --git a/include/compact_iterator.hpp b/include/compact_iterator.hpp index 48a2125..af55aa7 100644 --- a/include/compact_iterator.hpp +++ b/include/compact_iterator.hpp @@ -1,6 +1,10 @@ #ifndef __COMPACT_ITERATOR_H__ #define __COMPACT_ITERATOR_H__ +#if __cplusplus < 201103L +#error C++ versions less than C++11 are not supported. +#endif + #include #include #include