Skip to content

Commit

Permalink
Use TSL_HT prefix for macros instead of just TSL.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tessil committed Aug 11, 2018
1 parent 00586d6 commit 1c70c32
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 118 deletions.
44 changes: 21 additions & 23 deletions include/tsl/array-hash/array_hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,28 +41,26 @@
#include "array_growth_policy.h"


/*
* __has_include is a bit useless (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79433),
* check also __cplusplus version.
*/
#ifdef __has_include
/*
* __has_include is a bit useless (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79433),
* check also __cplusplus version.
*/
#if __has_include(<string_view>) && __cplusplus >= 201703L
#define TSL_HAS_STRING_VIEW
#endif
# if __has_include(<string_view>) && __cplusplus >= 201703L
# define TSL_AH_HAS_STRING_VIEW
# endif
#endif


#ifdef TSL_HAS_STRING_VIEW
#include <string_view>
#ifdef TSL_AH_HAS_STRING_VIEW
# include <string_view>
#endif


#ifndef tsl_assert
#ifdef TSL_DEBUG
#define tsl_assert(expr) assert(expr)
#else
#define tsl_assert(expr) (static_cast<void>(0))
#endif
#ifdef TSL_DEBUG
# define tsl_ah_assert(expr) assert(expr)
#else
# define tsl_ah_assert(expr) (static_cast<void>(0))
#endif


Expand Down Expand Up @@ -378,7 +376,7 @@ class array_bucket {
const key_size_type key_sz = as_key_size_type(key_size);

if(end_of_bucket == cend()) {
tsl_assert(m_buffer == nullptr);
tsl_ah_assert(m_buffer == nullptr);

const size_type buffer_size = entry_required_bytes(key_sz) + sizeof_in_buff<decltype(END_OF_BUCKET)>();

Expand All @@ -392,7 +390,7 @@ class array_bucket {
return const_iterator(m_buffer);
}
else {
tsl_assert(is_end_of_bucket(end_of_bucket.m_position));
tsl_ah_assert(is_end_of_bucket(end_of_bucket.m_position));

const size_type current_size = ((end_of_bucket.m_position + size_as_char_t<decltype(END_OF_BUCKET)>()) -
m_buffer) * sizeof(CharT);
Expand All @@ -416,7 +414,7 @@ class array_bucket {
}

const_iterator erase(const_iterator position) noexcept {
tsl_assert(position.m_position != nullptr && !is_end_of_bucket(position.m_position));
tsl_ah_assert(position.m_position != nullptr && !is_end_of_bucket(position.m_position));

// get mutable pointers
CharT* start_entry = m_buffer + (position.m_position - m_buffer);
Expand Down Expand Up @@ -715,7 +713,7 @@ class array_hash: private value_container<T>, private Hash, private GrowthPolicy
m_array_bucket_iterator(array_bucket_iterator),
m_array_hash(array_hash_p)
{
tsl_assert(m_array_hash != nullptr);
tsl_ah_assert(m_array_hash != nullptr);
}

public:
Expand All @@ -737,7 +735,7 @@ class array_hash: private value_container<T>, private Hash, private GrowthPolicy
return m_array_bucket_iterator.key_size();
}

#ifdef TSL_HAS_STRING_VIEW
#ifdef TSL_AH_HAS_STRING_VIEW
std::basic_string_view<CharT> key_sv() const {
return std::basic_string_view<CharT>(key(), key_size());
}
Expand All @@ -759,8 +757,8 @@ class array_hash: private value_container<T>, private Hash, private GrowthPolicy
}

array_hash_iterator& operator++() {
tsl_assert(m_buckets_iterator != m_array_hash->m_buckets.end());
tsl_assert(m_array_bucket_iterator != m_buckets_iterator->cend());
tsl_ah_assert(m_buckets_iterator != m_array_hash->m_buckets.end());
tsl_ah_assert(m_array_bucket_iterator != m_buckets_iterator->cend());

++m_array_bucket_iterator;
if(m_array_bucket_iterator == m_buckets_iterator->cend()) {
Expand Down Expand Up @@ -1297,7 +1295,7 @@ class array_hash: private value_container<T>, private Hash, private GrowthPolicy
}

new_values.swap(this->m_values);
tsl_assert(m_nb_elements == this->m_values.size());
tsl_ah_assert(m_nb_elements == this->m_values.size());
}

/**
Expand Down
36 changes: 18 additions & 18 deletions include/tsl/array-hash/array_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class array_map {



#ifdef TSL_HAS_STRING_VIEW
#ifdef TSL_AH_HAS_STRING_VIEW
array_map(std::initializer_list<std::pair<std::basic_string_view<CharT>, T>> init,
size_type bucket_count = ht::DEFAULT_INIT_BUCKET_COUNT,
const Hash& hash = Hash()): array_map(bucket_count, hash)
Expand All @@ -121,7 +121,7 @@ class array_map {



#ifdef TSL_HAS_STRING_VIEW
#ifdef TSL_AH_HAS_STRING_VIEW
array_map& operator=(std::initializer_list<std::pair<std::basic_string_view<CharT>, T>> ilist) {
clear();

Expand Down Expand Up @@ -174,7 +174,7 @@ class array_map {



#ifdef TSL_HAS_STRING_VIEW
#ifdef TSL_AH_HAS_STRING_VIEW
std::pair<iterator, bool> insert(const std::basic_string_view<CharT>& key, const T& value) {
return m_ht.emplace(key.data(), key.size(), value);
}
Expand All @@ -193,7 +193,7 @@ class array_map {



#ifdef TSL_HAS_STRING_VIEW
#ifdef TSL_AH_HAS_STRING_VIEW
std::pair<iterator, bool> insert(const std::basic_string_view<CharT>& key, T&& value) {
return m_ht.emplace(key.data(), key.size(), std::move(value));
}
Expand Down Expand Up @@ -232,7 +232,7 @@ class array_map {



#ifdef TSL_HAS_STRING_VIEW
#ifdef TSL_AH_HAS_STRING_VIEW
void insert(std::initializer_list<std::pair<std::basic_string_view<CharT>, T>> ilist) {
insert(ilist.begin(), ilist.end());
}
Expand All @@ -244,7 +244,7 @@ class array_map {



#ifdef TSL_HAS_STRING_VIEW
#ifdef TSL_AH_HAS_STRING_VIEW
template<class M>
std::pair<iterator, bool> insert_or_assign(const std::basic_string_view<CharT>& key, M&& obj) {
return m_ht.insert_or_assign(key.data(), key.size(), std::forward<M>(obj));
Expand All @@ -267,7 +267,7 @@ class array_map {



#ifdef TSL_HAS_STRING_VIEW
#ifdef TSL_AH_HAS_STRING_VIEW
template<class... Args>
std::pair<iterator, bool> emplace(const std::basic_string_view<CharT>& key, Args&&... args) {
return m_ht.emplace(key.data(), key.size(), std::forward<Args>(args)...);
Expand Down Expand Up @@ -308,7 +308,7 @@ class array_map {



#ifdef TSL_HAS_STRING_VIEW
#ifdef TSL_AH_HAS_STRING_VIEW
/**
* @copydoc erase(const_iterator pos)
*/
Expand Down Expand Up @@ -339,7 +339,7 @@ class array_map {



#ifdef TSL_HAS_STRING_VIEW
#ifdef TSL_AH_HAS_STRING_VIEW
/**
* @copydoc erase_ks(const CharT* key, size_type key_size, std::size_t precalculated_hash)
*/
Expand Down Expand Up @@ -380,7 +380,7 @@ class array_map {
/*
* Lookup
*/
#ifdef TSL_HAS_STRING_VIEW
#ifdef TSL_AH_HAS_STRING_VIEW
T& at(const std::basic_string_view<CharT>& key) {
return m_ht.at(key.data(), key.size());
}
Expand Down Expand Up @@ -415,7 +415,7 @@ class array_map {



#ifdef TSL_HAS_STRING_VIEW
#ifdef TSL_AH_HAS_STRING_VIEW
/**
* @copydoc at_ks(const CharT* key, size_type key_size, std::size_t precalculated_hash)
*/
Expand Down Expand Up @@ -475,7 +475,7 @@ class array_map {



#ifdef TSL_HAS_STRING_VIEW
#ifdef TSL_AH_HAS_STRING_VIEW
T& operator[](const std::basic_string_view<CharT>& key) { return m_ht.access_operator(key.data(), key.size()); }
#else
T& operator[](const CharT* key) { return m_ht.access_operator(key, std::strlen(key)); }
Expand All @@ -484,7 +484,7 @@ class array_map {



#ifdef TSL_HAS_STRING_VIEW
#ifdef TSL_AH_HAS_STRING_VIEW
size_type count(const std::basic_string_view<CharT>& key) const {
return m_ht.count(key.data(), key.size());
}
Expand All @@ -503,7 +503,7 @@ class array_map {



#ifdef TSL_HAS_STRING_VIEW
#ifdef TSL_AH_HAS_STRING_VIEW
/**
* @copydoc count_ks(const CharT* key, size_type key_size, std::size_t precalculated_hash) const
*/
Expand Down Expand Up @@ -535,7 +535,7 @@ class array_map {



#ifdef TSL_HAS_STRING_VIEW
#ifdef TSL_AH_HAS_STRING_VIEW
iterator find(const std::basic_string_view<CharT>& key) {
return m_ht.find(key.data(), key.size());
}
Expand Down Expand Up @@ -570,7 +570,7 @@ class array_map {



#ifdef TSL_HAS_STRING_VIEW
#ifdef TSL_AH_HAS_STRING_VIEW
/**
* @copydoc find_ks(const CharT* key, size_type key_size, std::size_t precalculated_hash)
*/
Expand Down Expand Up @@ -630,7 +630,7 @@ class array_map {



#ifdef TSL_HAS_STRING_VIEW
#ifdef TSL_AH_HAS_STRING_VIEW
std::pair<iterator, iterator> equal_range(const std::basic_string_view<CharT>& key) {
return m_ht.equal_range(key.data(), key.size());
}
Expand Down Expand Up @@ -665,7 +665,7 @@ class array_map {



#ifdef TSL_HAS_STRING_VIEW
#ifdef TSL_AH_HAS_STRING_VIEW
/**
* @copydoc equal_range_ks(const CharT* key, size_type key_size, std::size_t precalculated_hash)
*/
Expand Down
26 changes: 13 additions & 13 deletions include/tsl/array-hash/array_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class array_set {
}


#ifdef TSL_HAS_STRING_VIEW
#ifdef TSL_AH_HAS_STRING_VIEW
array_set(std::initializer_list<std::basic_string_view<CharT>> init,
size_type bucket_count = ht::DEFAULT_INIT_BUCKET_COUNT,
const Hash& hash = Hash()): array_set(bucket_count, hash)
Expand All @@ -114,7 +114,7 @@ class array_set {



#ifdef TSL_HAS_STRING_VIEW
#ifdef TSL_AH_HAS_STRING_VIEW
array_set& operator=(std::initializer_list<std::basic_string_view<CharT>> ilist) {
clear();

Expand Down Expand Up @@ -163,7 +163,7 @@ class array_set {



#ifdef TSL_HAS_STRING_VIEW
#ifdef TSL_AH_HAS_STRING_VIEW
std::pair<iterator, bool> insert(const std::basic_string_view<CharT>& key) {
return m_ht.emplace(key.data(), key.size());
}
Expand Down Expand Up @@ -202,7 +202,7 @@ class array_set {



#ifdef TSL_HAS_STRING_VIEW
#ifdef TSL_AH_HAS_STRING_VIEW
void insert(std::initializer_list<std::basic_string_view<CharT>> ilist) {
insert(ilist.begin(), ilist.end());
}
Expand All @@ -214,7 +214,7 @@ class array_set {



#ifdef TSL_HAS_STRING_VIEW
#ifdef TSL_AH_HAS_STRING_VIEW
/**
* @copydoc emplace_ks(const CharT* key, size_type key_size)
*/
Expand Down Expand Up @@ -248,7 +248,7 @@ class array_set {
iterator erase(const_iterator pos) { return m_ht.erase(pos); }
iterator erase(const_iterator first, const_iterator last) { return m_ht.erase(first, last); }

#ifdef TSL_HAS_STRING_VIEW
#ifdef TSL_AH_HAS_STRING_VIEW
size_type erase(const std::basic_string_view<CharT>& key) {
return m_ht.erase(key.data(), key.size());
}
Expand All @@ -267,7 +267,7 @@ class array_set {



#ifdef TSL_HAS_STRING_VIEW
#ifdef TSL_AH_HAS_STRING_VIEW
/**
* @copydoc erase_ks(const CharT* key, size_type key_size, std::size_t precalculated_hash)
*/
Expand Down Expand Up @@ -306,7 +306,7 @@ class array_set {
/*
* Lookup
*/
#ifdef TSL_HAS_STRING_VIEW
#ifdef TSL_AH_HAS_STRING_VIEW
size_type count(const std::basic_string_view<CharT>& key) const { return m_ht.count(key.data(), key.size()); }
#else
size_type count(const CharT* key) const { return m_ht.count(key, std::strlen(key)); }
Expand All @@ -316,7 +316,7 @@ class array_set {



#ifdef TSL_HAS_STRING_VIEW
#ifdef TSL_AH_HAS_STRING_VIEW
/**
* @copydoc count_ks(const CharT* key, size_type key_size, std::size_t precalculated_hash) const
*/
Expand Down Expand Up @@ -348,7 +348,7 @@ class array_set {



#ifdef TSL_HAS_STRING_VIEW
#ifdef TSL_AH_HAS_STRING_VIEW
iterator find(const std::basic_string_view<CharT>& key) {
return m_ht.find(key.data(), key.size());
}
Expand Down Expand Up @@ -383,7 +383,7 @@ class array_set {



#ifdef TSL_HAS_STRING_VIEW
#ifdef TSL_AH_HAS_STRING_VIEW
/**
* @copydoc find_ks(const CharT* key, size_type key_size, std::size_t precalculated_hash)
*/
Expand Down Expand Up @@ -443,7 +443,7 @@ class array_set {



#ifdef TSL_HAS_STRING_VIEW
#ifdef TSL_AH_HAS_STRING_VIEW
std::pair<iterator, iterator> equal_range(const std::basic_string_view<CharT>& key) {
return m_ht.equal_range(key.data(), key.size());
}
Expand Down Expand Up @@ -478,7 +478,7 @@ class array_set {



#ifdef TSL_HAS_STRING_VIEW
#ifdef TSL_AH_HAS_STRING_VIEW
/**
* @copydoc equal_range_ks(const CharT* key, size_type key_size, std::size_t precalculated_hash)
*/
Expand Down
Loading

0 comments on commit 1c70c32

Please sign in to comment.