Skip to content

Commit

Permalink
Merge branch 'release/v0.1.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
gmarcais committed Feb 20, 2023
2 parents 0aab8c4 + 04c7f29 commit 9d5b66a
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 25 deletions.
13 changes: 6 additions & 7 deletions .github/workflows/c-cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ on:
- master
- develop
pull_request:
branches: [ master ]
branches: [ master, develop ]

jobs:
test:
name: Unit tests on ${{ matrix.os }} with ${{ matrix.compiler }} standard ${{ matrix.standard }}
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
Expand All @@ -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]
Expand All @@ -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
2 changes: 1 addition & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
@@ -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 \
Expand Down
30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
![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
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

Expand All @@ -28,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

Expand Down Expand Up @@ -87,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.
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
AC_INIT([compact_vector],[0.1.1],[[email protected]])
AC_INIT([compact_vector],[0.1.2],[[email protected]])
AC_CONFIG_AUX_DIR([build-aux])
AM_SILENT_RULES([yes])
AC_CONFIG_SRCDIR([include/compact_vector.hpp])
Expand Down
6 changes: 5 additions & 1 deletion include/compact_iterator.hpp
Original file line number Diff line number Diff line change
@@ -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 <iterator>
#include <memory>
#include <type_traits>
Expand Down Expand Up @@ -628,7 +632,7 @@ class common {
template<bool TS = false>
void set_bits(W x, unsigned bits) {
Derived& self = *static_cast<Derived*>(this);
gs<W, BITS, W, UB>::set<TS>(x, self.m_ptr, bits, self.m_offset);
gs<W, BITS, W, UB>::template set<TS>(x, self.m_ptr, bits, self.m_offset);
}

// Get, i.e., don't use fetch
Expand Down
4 changes: 4 additions & 0 deletions include/compact_vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Empty file added m4/.gitignore
Empty file.
10 changes: 10 additions & 0 deletions unittests/test_compact_vector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 9d5b66a

Please sign in to comment.