Skip to content

Commit

Permalink
Fix some typos
Browse files Browse the repository at this point in the history
  • Loading branch information
sjanel committed Jan 14, 2024
1 parent 9eb9bbe commit efcb7be
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 41 deletions.
1 change: 1 addition & 0 deletions include/amc/fixedcapacityvector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <stdexcept>
#include <type_traits>

#include "config.hpp"
#include "vectorcommon.hpp"

namespace amc {
Expand Down
4 changes: 2 additions & 2 deletions include/amc/flatset.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

#include <algorithm>
#include <cassert>
#include <cstdint>
#include <functional>
#include <initializer_list>
#include <iterator>
#include <limits>
#include <utility>

#include "allocator.hpp"
Expand Down Expand Up @@ -80,6 +78,8 @@ class FlatSet : private Compare {
node_type &operator=(const node_type &) = delete;
node_type &operator=(node_type &&o) noexcept(std::is_nothrow_move_assignable<value_type>::value) = default;

~node_type() = default;

bool empty() const noexcept { return !_optV.has_value(); }
explicit operator bool() const noexcept { return _optV.has_value(); }
allocator_type get_allocator() const { return static_cast<allocator_type>(*this); }
Expand Down
42 changes: 21 additions & 21 deletions include/amc/smallset.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class SmallSetIteratorCommon {
using pointer = const T *;
using reference = const T &;

// For a set, only equality and unequality operators are defined
// For a set, only equality and un-equality operators are defined
#ifdef AMC_CXX20
bool operator==(const SmallSetIteratorCommon &) const noexcept = default;
#else
Expand Down Expand Up @@ -469,29 +469,29 @@ class SmallSet {
grow();
}
_set.merge(o._set);
} else {
bool small = isSmall();
for (auto oit = o._vec.begin(); oit != o._vec.end();) {
FindFunctor<T> fFunc(key_comp(), *oit);
if (small) {
if (std::none_of(_vec.begin(), _vec.end(), fFunc)) {
if (isSmallContFull()) {
grow();
small = false;
_set.insert(std::move(*oit));
} else {
_vec.push_back(std::move(*oit));
}
oit = o._vec.erase(oit);
return;
}
bool small = isSmall();
for (auto oit = o._vec.begin(); oit != o._vec.end();) {
FindFunctor<T> fFunc(key_comp(), *oit);
if (small) {
if (std::none_of(_vec.begin(), _vec.end(), fFunc)) {
if (isSmallContFull()) {
grow();
small = false;
_set.insert(std::move(*oit));
} else {
++oit;
_vec.push_back(std::move(*oit));
}
oit = o._vec.erase(oit);
} else {
if (_set.insert(std::move(*oit)).second) {
oit = o._vec.erase(oit);
} else {
++oit;
}
++oit;
}
} else {
if (_set.insert(std::move(*oit)).second) {
oit = o._vec.erase(oit);
} else {
++oit;
}
}
}
Expand Down
23 changes: 12 additions & 11 deletions include/amc/vectorcommon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ inline void shift_right(T *first, SizeType n, SizeType count) noexcept {
(void)amc::uninitialized_relocate_n(first, n, first + count);
}

/// Fill 'count' 'v' values at memory starting at 'first', with first 'n' slots on inintialized memory,
/// Fill 'count' 'v' values at memory starting at 'first', with first 'n' slots on initialized memory,
/// and next 'count - n' slots on uninitialized memory if there is overlap
template <class T, class SizeType, typename std::enable_if<!amc::is_trivially_relocatable<T>::value, bool>::type = true>
inline void fill_after_shift(T *first, SizeType n, SizeType count, const T &v) {
Expand Down Expand Up @@ -110,7 +110,7 @@ inline void assign_n(ForwardIt first, SizeType count, T *d_first, SizeType) {
}

/// Copy 'count' elements starting at 'first' to 'pos' location
/// To be used in conjonction with 'shift_right'
/// To be used in conjunction with 'shift_right'
template <class ForwardIt, class SizeType, class T,
typename std::enable_if<!amc::is_trivially_relocatable<T>::value, bool>::type = true>
inline void copy_after_shift(ForwardIt first, SizeType n, SizeType count, T *pos) {
Expand Down Expand Up @@ -184,7 +184,7 @@ inline void erase_at(T *first, SizeType count) {
/// Requirements: n < count
template <class T, class SizeType, typename std::enable_if<!std::is_trivially_copyable<T>::value, bool>::type = true>
inline void fill(T *first, SizeType n, SizeType count, const T &v) {
// uninitialize fill first for slightly better exception safety
// uninitialized fill first for slightly better exception safety
std::uninitialized_fill_n(first + n, count - n, v);
std::fill_n(first, n, v);
}
Expand Down Expand Up @@ -517,7 +517,7 @@ class StdVectorBase : private Alloc {
void move_assign(StdVectorBase &o, SizeType) noexcept {
if (_storage) {
amc::destroy_n(_storage, _size);
freeStorage(); // Compared to swap, we can free memory directly for move assigment
freeStorage(); // Compared to swap, we can free memory directly for move assignment
}
_storage = amc::exchange(o._storage, nullptr);
_capa = amc::exchange(o._capa, 0);
Expand Down Expand Up @@ -566,11 +566,12 @@ class StdVectorBase : private Alloc {
iterator dynStorage() const noexcept { return _storage; }

private:
SizeType _capa = 0, _size = 0;
T *_storage = nullptr;

void shrink();
void freeStorage() noexcept;

SizeType _capa = 0;
SizeType _size = 0;
T *_storage = nullptr;
};

template <class T, class Alloc, class SizeType>
Expand Down Expand Up @@ -619,7 +620,7 @@ class SmallVectorBase : private Alloc {
/// for this special configuration: we will set size to MAX in this case.
/// Maximum size and capacity would make no sense in a SmallVector for a small state, because it could not grow
/// (it could be transformed into a FixedCapacityVector, or, if larger size is needed, SizeType could be upgraded
/// to a larger type). This invalid configuration is catched in a static_assert in SmallVector class.
/// to a larger type). This invalid configuration is caught in a static_assert in SmallVector class.
explicit SmallVectorBase(SizeType inplaceCapa) noexcept : _capa(0), _size(inplaceCapa) {}

SmallVectorBase(SizeType inplaceCapa, const Alloc &alloc) noexcept : Alloc(alloc), _capa(0), _size(inplaceCapa) {}
Expand Down Expand Up @@ -774,9 +775,6 @@ class SmallVectorBase : private Alloc {
iterator dynStorage() const noexcept { return _storage.dyn(); }

private:
SizeType _capa, _size;
ElemWithPtrStorage<T> _storage;

static inline void SwapDynamicBuffer(SmallVectorBase &vDynBuf,
SmallVectorBase &vSmall) noexcept(is_swap_noexcept<T>::value) {
T *oDynStorage = vDynBuf._storage.dyn();
Expand All @@ -787,6 +785,9 @@ class SmallVectorBase : private Alloc {
void shrink();
void resetToSmall(SizeType);
void freeStorage() noexcept;

SizeType _capa, _size;
ElemWithPtrStorage<T> _storage;
};

template <class T, class Alloc, class SizeType>
Expand Down
3 changes: 2 additions & 1 deletion test/sets_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <amc/config.hpp>
#include <amc/fixedcapacityvector.hpp>
#include <amc/flatset.hpp>
#include <initializer_list>
#include <list>
#ifdef AMC_SMALLSET
#include <amc/smallset.hpp>
Expand Down Expand Up @@ -68,8 +67,10 @@ TYPED_TEST(SetListTest, Insert) {
TypeParam s;
s.insert(8);
s.insert(15);
s.insert(8);
EXPECT_EQ(s.size(), 2U);
EXPECT_FALSE(s.empty());
EXPECT_TRUE(s.contains(15));
}

TYPED_TEST(SetListTest, Emplace) {
Expand Down
10 changes: 5 additions & 5 deletions test/testtypes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#include <cstdint>
#include <cstdlib>
#include <cstring>
#include <memory>
#include <stdexcept>
#include <new>
#include <utility>

#ifdef AMC_CXX20
#include <compare>
Expand Down Expand Up @@ -78,7 +78,7 @@ struct NonCopyableType {
bool operator==(const NonCopyableType &o) const { return _i == o._i; }

#ifdef AMC_CXX20
auto operator<=>(const NonCopyableType &o) const { return _i <=> o._i; }
auto operator<=>(const NonCopyableType &o) const = default;
#endif

operator int32_t() const { return _i; }
Expand All @@ -96,7 +96,7 @@ struct SimpleNonTriviallyCopyableType {
operator int32_t() const { return _i; }

#ifdef AMC_CXX20
auto operator<=>(const SimpleNonTriviallyCopyableType &o) const { return _i <=> o._i; }
auto operator<=>(const SimpleNonTriviallyCopyableType &o) const = default;
#endif

int _i;
Expand All @@ -108,7 +108,7 @@ struct NonTrivialType {
operator uint32_t() const { return _i; }

#ifdef AMC_CXX20
auto operator<=>(const NonTrivialType &o) const { return _i <=> o._i; }
auto operator<=>(const NonTrivialType &o) const = default;
#endif

uint32_t _i;
Expand Down
5 changes: 4 additions & 1 deletion test/vectors_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,12 +366,15 @@ TEST(VectorTest, CustomOperations) {
}

TEST(VectorTest, NonCopyableType) {
using NonCopyableTypeVectorType = FixedCapacityVector<NonCopyableType, 10>;
using NonCopyableTypeVectorType = SmallVector<NonCopyableType, 6>;
NonCopyableTypeVectorType v(6);
EXPECT_EQ(v.front(), NonCopyableType());
EXPECT_EQ(v.back(), NonCopyableType());
v.resize(7);
EXPECT_EQ(v[6], NonCopyableType());

v.emplace_back(1);
EXPECT_EQ(v.back(), NonCopyableType(1));
}

#ifdef AMC_NONSTD_FEATURES
Expand Down

0 comments on commit efcb7be

Please sign in to comment.