diff options
| author | eeight <[email protected]> | 2022-02-10 16:46:18 +0300 | 
|---|---|---|
| committer | Daniil Cherednik <[email protected]> | 2022-02-10 16:46:18 +0300 | 
| commit | 475c0a46f28166e83fd263badc7546377cddcabe (patch) | |
| tree | 39c5a49b8aaad78fe390b6f1f2886bdbda40f3e7 /library/cpp/containers | |
| parent | a6e0145a095c7bb3770d6e07aee301de5c73f96e (diff) | |
Restoring authorship annotation for <[email protected]>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/containers')
| -rw-r--r-- | library/cpp/containers/bitseq/bititerator.h | 2 | ||||
| -rw-r--r-- | library/cpp/containers/bitseq/bitvector.h | 2 | ||||
| -rw-r--r-- | library/cpp/containers/bitseq/readonly_bitvector.h | 12 | ||||
| -rw-r--r-- | library/cpp/containers/bitseq/ya.make | 2 | ||||
| -rw-r--r-- | library/cpp/containers/comptrie/chunked_helpers_trie.h | 20 | ||||
| -rw-r--r-- | library/cpp/containers/comptrie/comptrie_ut.cpp | 2 | ||||
| -rw-r--r-- | library/cpp/containers/sorted_vector/sorted_vector.h | 34 | ||||
| -rw-r--r-- | library/cpp/containers/stack_vector/stack_vec.h | 116 | ||||
| -rw-r--r-- | library/cpp/containers/stack_vector/stack_vec_ut.cpp | 74 | 
9 files changed, 132 insertions, 132 deletions
diff --git a/library/cpp/containers/bitseq/bititerator.h b/library/cpp/containers/bitseq/bititerator.h index 52dadd37982..2977abdd54d 100644 --- a/library/cpp/containers/bitseq/bititerator.h +++ b/library/cpp/containers/bitseq/bititerator.h @@ -2,7 +2,7 @@  #include "traits.h" -#include <library/cpp/pop_count/popcount.h> +#include <library/cpp/pop_count/popcount.h>   template <typename T>  class TBitIterator { diff --git a/library/cpp/containers/bitseq/bitvector.h b/library/cpp/containers/bitseq/bitvector.h index 3f8fd81ee57..a620f83cb2d 100644 --- a/library/cpp/containers/bitseq/bitvector.h +++ b/library/cpp/containers/bitseq/bitvector.h @@ -2,7 +2,7 @@  #include "traits.h" -#include <library/cpp/pop_count/popcount.h> +#include <library/cpp/pop_count/popcount.h>   #include <util/generic/vector.h>  #include <util/ysaveload.h> diff --git a/library/cpp/containers/bitseq/readonly_bitvector.h b/library/cpp/containers/bitseq/readonly_bitvector.h index 8612739c3f7..02f04f94394 100644 --- a/library/cpp/containers/bitseq/readonly_bitvector.h +++ b/library/cpp/containers/bitseq/readonly_bitvector.h @@ -19,12 +19,12 @@ public:      {      } -    explicit TReadonlyBitVector(const TBitVector<T>& vector) -        : Size_(vector.Size_) -        , Data_(vector.Data_.data()) -    { -    } - +    explicit TReadonlyBitVector(const TBitVector<T>& vector)  +        : Size_(vector.Size_)  +        , Data_(vector.Data_.data())  +    {  +    }  +       bool Test(ui64 pos) const {          return TTraits::Test(Data_, pos, Size_);      } diff --git a/library/cpp/containers/bitseq/ya.make b/library/cpp/containers/bitseq/ya.make index 7090956c557..ec000d827ed 100644 --- a/library/cpp/containers/bitseq/ya.make +++ b/library/cpp/containers/bitseq/ya.make @@ -4,7 +4,7 @@ OWNER(g:util)  PEERDIR(      util/draft -    library/cpp/pop_count +    library/cpp/pop_count   )  SRCS( diff --git a/library/cpp/containers/comptrie/chunked_helpers_trie.h b/library/cpp/containers/comptrie/chunked_helpers_trie.h index cfa35f5ba2a..02e998607ca 100644 --- a/library/cpp/containers/comptrie/chunked_helpers_trie.h +++ b/library/cpp/containers/comptrie/chunked_helpers_trie.h @@ -85,7 +85,7 @@ public:      bool Get(const char* key, T* value) const {          ui64 trieValue;          if (Trie.Find(key, strlen(key), &trieValue)) { -            *value = ReadUnaligned<T>(&trieValue); +            *value = ReadUnaligned<T>(&trieValue);               return true;          } else {              return false; @@ -95,7 +95,7 @@ public:      T Get(const char* key, T def = T()) const {          ui64 trieValue;          if (Trie.Find(key, strlen(key), &trieValue)) { -            return ReadUnaligned<T>(&trieValue); +            return ReadUnaligned<T>(&trieValue);           } else {              return def;          } @@ -126,9 +126,9 @@ public:      }      void Add(const char* key, const T& value) { -        ui64 intValue = 0; -        memcpy(&intValue, &value, sizeof(T)); -        Builder.Add(key, strlen(key), intValue); +        ui64 intValue = 0;  +        memcpy(&intValue, &value, sizeof(T));  +        Builder.Add(key, strlen(key), intValue);   #ifndef NDEBUG          /*          if (!IsSorted) { @@ -140,15 +140,15 @@ public:      }      void Add(const TString& s, const T& value) { -        ui64 intValue = 0; -        memcpy(&intValue, &value, sizeof(T)); -        Builder.Add(s.data(), s.size(), intValue); +        ui64 intValue = 0;  +        memcpy(&intValue, &value, sizeof(T));  +        Builder.Add(s.data(), s.size(), intValue);       }      bool Get(const char* key, T* value) const {          ui64 trieValue;          if (Builder.Find(key, strlen(key), &trieValue)) { -            *value = ReadUnaligned<T>(&trieValue); +            *value = ReadUnaligned<T>(&trieValue);               return true;          } else {              return false; @@ -158,7 +158,7 @@ public:      T Get(const char* key, T def = (T)0) const {          ui64 trieValue;          if (Builder.Find(key, strlen(key), &trieValue)) { -            return ReadUnaligned<T>(&trieValue); +            return ReadUnaligned<T>(&trieValue);           } else {              return def;          } diff --git a/library/cpp/containers/comptrie/comptrie_ut.cpp b/library/cpp/containers/comptrie/comptrie_ut.cpp index 74bee09b5d6..278e36ed0c8 100644 --- a/library/cpp/containers/comptrie/comptrie_ut.cpp +++ b/library/cpp/containers/comptrie/comptrie_ut.cpp @@ -18,7 +18,7 @@  #include <util/random/fast.h>  #include <util/string/hex.h> -#include <util/string/cast.h> +#include <util/string/cast.h>   #include "comptrie.h"  #include "set.h" diff --git a/library/cpp/containers/sorted_vector/sorted_vector.h b/library/cpp/containers/sorted_vector/sorted_vector.h index 123539af9e2..93c4bdfb44a 100644 --- a/library/cpp/containers/sorted_vector/sorted_vector.h +++ b/library/cpp/containers/sorted_vector/sorted_vector.h @@ -4,7 +4,7 @@  #include <util/generic/hash.h>  #include <util/generic/vector.h>  #include <util/generic/algorithm.h> -#include <util/generic/mapfindptr.h> +#include <util/generic/mapfindptr.h>   #include <util/ysaveload.h>  #include <utility> @@ -328,10 +328,10 @@ namespace NSorted {      // and then inserts a new one, the existing reference can be broken (due to reallocation).      // Please keep this in mind when using this structure.      template <typename TKeyType, typename TValueType, class TPredicate = TLess<TKeyType>, class A = std::allocator<TValueType>> -    class TSimpleMap: -        public TSortedVector<std::pair<TKeyType, TValueType>, TKeyType, TSelect1st, TPredicate, A>, -        public TMapOps<TSimpleMap<TKeyType, TValueType, TPredicate, A>> -    { +    class TSimpleMap:  +        public TSortedVector<std::pair<TKeyType, TValueType>, TKeyType, TSelect1st, TPredicate, A>,  +        public TMapOps<TSimpleMap<TKeyType, TValueType, TPredicate, A>>  +    {       private:          typedef TSortedVector<std::pair<TKeyType, TValueType>, TKeyType, TSelect1st, TPredicate, A> TBase; @@ -379,22 +379,22 @@ namespace NSorted {          Y_FORCE_INLINE TValueType& operator[](const K& key) {              return Get(key);          } - +           template<class K>          const TValueType& at(const K& key) const { -            const auto i = TBase::Find(key); -            if (i == TBase::end()) { -                throw std::out_of_range("NSorted::TSimpleMap: missing key"); -            } - -            return i->second; -        } - +            const auto i = TBase::Find(key);  +            if (i == TBase::end()) {  +                throw std::out_of_range("NSorted::TSimpleMap: missing key");  +            }  +  +            return i->second;  +        }  +           template<class K>          TValueType& at(const K& key) { -            return const_cast<TValueType&>( -                    const_cast<const TSimpleMap<TKeyType, TValueType, TPredicate, A>*>(this)->at(key)); -        } +            return const_cast<TValueType&>(  +                    const_cast<const TSimpleMap<TKeyType, TValueType, TPredicate, A>*>(this)->at(key));  +        }       };      // The simplified set (a.k.a TFlatSet, flat_set), which is implemented by the sorted-vector. diff --git a/library/cpp/containers/stack_vector/stack_vec.h b/library/cpp/containers/stack_vector/stack_vec.h index fcc5d9a2a50..4fc3f26d89f 100644 --- a/library/cpp/containers/stack_vector/stack_vec.h +++ b/library/cpp/containers/stack_vector/stack_vec.h @@ -3,23 +3,23 @@  #include <util/generic/vector.h>  #include <util/ysaveload.h> -#include <type_traits> - +#include <type_traits>  +   // A vector preallocated on the stack.  // After exceeding the preconfigured stack space falls back to the heap.  // Publicly inherits TVector, but disallows swap (and hence shrink_to_fit, also operator= is reimplemented via copying).  //  // Inspired by: http://qt-project.org/doc/qt-4.8/qvarlengtharray.html#details -template <typename T, size_t CountOnStack = 256, bool UseFallbackAlloc = true, class Alloc = std::allocator<T>> +template <typename T, size_t CountOnStack = 256, bool UseFallbackAlloc = true, class Alloc = std::allocator<T>>   class TStackVec;  template <typename T, class Alloc = std::allocator<T>> -using TSmallVec = TStackVec<T, 16, true, Alloc>; - -template <typename T, size_t CountOnStack = 256> -using TStackOnlyVec = TStackVec<T, CountOnStack, false>; +using TSmallVec = TStackVec<T, 16, true, Alloc>;  +template <typename T, size_t CountOnStack = 256>  +using TStackOnlyVec = TStackVec<T, CountOnStack, false>;  +   namespace NPrivate {      template <class Alloc, class StackAlloc, typename T, typename U>      struct TRebind { @@ -31,10 +31,10 @@ namespace NPrivate {          typedef StackAlloc other;      }; -    template <typename T, size_t CountOnStack, bool UseFallbackAlloc, class Alloc = std::allocator<T>> +    template <typename T, size_t CountOnStack, bool UseFallbackAlloc, class Alloc = std::allocator<T>>       class TStackBasedAllocator: public Alloc {      public: -        typedef TStackBasedAllocator<T, CountOnStack, UseFallbackAlloc, Alloc> TSelf; +        typedef TStackBasedAllocator<T, CountOnStack, UseFallbackAlloc, Alloc> TSelf;           using typename Alloc::difference_type;          using typename Alloc::size_type; @@ -58,14 +58,14 @@ namespace NPrivate {          {}          T* allocate(size_type n) { -            if (!IsStorageUsed && CountOnStack >= n) { -                IsStorageUsed = true; +            if (!IsStorageUsed && CountOnStack >= n) {  +                IsStorageUsed = true;                   return reinterpret_cast<T*>(&StackBasedStorage[0]);              } else { -                if constexpr (!UseFallbackAlloc) { -                    Y_FAIL( -                            "Stack storage overflow. Capacity: %d, requested: %d", (int)CountOnStack, int(n)); -                } +                if constexpr (!UseFallbackAlloc) {  +                    Y_FAIL(  +                            "Stack storage overflow. Capacity: %d, requested: %d", (int)CountOnStack, int(n));  +                }                   return FallbackAllocator().allocate(n);              }          } @@ -73,15 +73,15 @@ namespace NPrivate {          void deallocate(T* p, size_type n) {              if (p >= reinterpret_cast<T*>(&StackBasedStorage[0]) &&                      p < reinterpret_cast<T*>(&StackBasedStorage[CountOnStack])) { -                Y_VERIFY(IsStorageUsed); -                IsStorageUsed = false; +                Y_VERIFY(IsStorageUsed);  +                IsStorageUsed = false;               } else {                  FallbackAllocator().deallocate(p, n);              }          }      private: -        std::aligned_storage_t<sizeof(T), alignof(T)> StackBasedStorage[CountOnStack]; +        std::aligned_storage_t<sizeof(T), alignof(T)> StackBasedStorage[CountOnStack];           bool IsStorageUsed = false;      private: @@ -91,8 +91,8 @@ namespace NPrivate {      };  } -template <typename T, size_t CountOnStack, bool UseFallbackAlloc, class Alloc> -class TStackVec: public TVector<T, ::NPrivate::TStackBasedAllocator<T, CountOnStack, UseFallbackAlloc, TReboundAllocator<Alloc, T>>> { +template <typename T, size_t CountOnStack, bool UseFallbackAlloc, class Alloc>  +class TStackVec: public TVector<T, ::NPrivate::TStackBasedAllocator<T, CountOnStack, UseFallbackAlloc, TReboundAllocator<Alloc, T>>> {   private:      using TBase = TVector<T, ::NPrivate::TStackBasedAllocator<T, CountOnStack, UseFallbackAlloc, TReboundAllocator<Alloc, T>>>;      using TAllocator = typename TBase::allocator_type; @@ -131,13 +131,13 @@ public:      }      TStackVec(const TStackVec& src) -        : TStackVec(src.begin(), src.end()) +        : TStackVec(src.begin(), src.end())       {      }      template <class A> -    TStackVec(const TVector<T, A>& src) -        : TStackVec(src.begin(), src.end()) +    TStackVec(const TVector<T, A>& src)  +        : TStackVec(src.begin(), src.end())       {      } @@ -150,20 +150,20 @@ public:      TStackVec(TIter first, TIter last, const TAllocator& alloc = TAllocator())          : TBase(alloc)      { -        // NB(eeight) Since we want to call 'reserve' here, we cannot just delegate to TVector ctor. -        // The best way to insert values afterwards is to call TVector::insert. However there is a caveat. -        // In order to call this ctor of TVector, T needs to be just move-constructible. Insert however -        // requires T to be move-assignable. -        TBase::reserve(CountOnStack); -        if constexpr (std::is_move_assignable_v<T>) { -            // Fast path -            TBase::insert(TBase::end(), first, last); -        } else { -            // Slow path. -            for (; first != last; ++first) { -                TBase::push_back(*first); -            } -        } +        // NB(eeight) Since we want to call 'reserve' here, we cannot just delegate to TVector ctor.  +        // The best way to insert values afterwards is to call TVector::insert. However there is a caveat.  +        // In order to call this ctor of TVector, T needs to be just move-constructible. Insert however  +        // requires T to be move-assignable.  +        TBase::reserve(CountOnStack);  +        if constexpr (std::is_move_assignable_v<T>) {  +            // Fast path  +            TBase::insert(TBase::end(), first, last);  +        } else {  +            // Slow path.  +            for (; first != last; ++first) {  +                TBase::push_back(*first);  +            }  +        }       }  public: @@ -188,25 +188,25 @@ public:  };  template <typename T, size_t CountOnStack, class Alloc> -class TSerializer<TStackVec<T, CountOnStack, true, Alloc>>: public TVectorSerializer<TStackVec<T, CountOnStack, true, Alloc>> { -}; - -template <typename T, size_t CountOnStack, class Alloc> -class TSerializer<TStackVec<T, CountOnStack, false, Alloc>> { -public: -    static void Save(IOutputStream* rh, const TStackVec<T, CountOnStack, false, Alloc>& v) { -        if constexpr (CountOnStack < 256) { -            ::Save(rh, (ui8)v.size()); -        } else { -            ::Save(rh, v.size()); -        } -        ::SaveArray(rh, v.data(), v.size()); -    } - -    static void Load(IInputStream* rh, TStackVec<T, CountOnStack, false, Alloc>& v) { -        std::conditional_t<CountOnStack < 256, ui8, size_t> size; -        ::Load(rh, size); -        v.resize(size); -        ::LoadPodArray(rh, v.data(), v.size()); -    } +class TSerializer<TStackVec<T, CountOnStack, true, Alloc>>: public TVectorSerializer<TStackVec<T, CountOnStack, true, Alloc>> {   }; +  +template <typename T, size_t CountOnStack, class Alloc>  +class TSerializer<TStackVec<T, CountOnStack, false, Alloc>> {  +public:  +    static void Save(IOutputStream* rh, const TStackVec<T, CountOnStack, false, Alloc>& v) {  +        if constexpr (CountOnStack < 256) {  +            ::Save(rh, (ui8)v.size());  +        } else {  +            ::Save(rh, v.size());  +        }  +        ::SaveArray(rh, v.data(), v.size());  +    }  +  +    static void Load(IInputStream* rh, TStackVec<T, CountOnStack, false, Alloc>& v) {  +        std::conditional_t<CountOnStack < 256, ui8, size_t> size;  +        ::Load(rh, size);  +        v.resize(size);  +        ::LoadPodArray(rh, v.data(), v.size());  +    }  +};  diff --git a/library/cpp/containers/stack_vector/stack_vec_ut.cpp b/library/cpp/containers/stack_vector/stack_vec_ut.cpp index 19f9677781c..89821dd4a8f 100644 --- a/library/cpp/containers/stack_vector/stack_vec_ut.cpp +++ b/library/cpp/containers/stack_vector/stack_vec_ut.cpp @@ -2,13 +2,13 @@  #include <library/cpp/testing/unittest/registar.h> -namespace { -    struct TNotCopyAssignable { -        const int Value; -    }; - -    static_assert(std::is_copy_constructible_v<TNotCopyAssignable>); -    static_assert(!std::is_copy_assignable_v<TNotCopyAssignable>); +namespace {  +    struct TNotCopyAssignable {  +        const int Value;  +    };  +  +    static_assert(std::is_copy_constructible_v<TNotCopyAssignable>);  +    static_assert(!std::is_copy_assignable_v<TNotCopyAssignable>);       template <class T, size_t JunkPayloadSize>      struct TThickAlloc: public std::allocator<T> { @@ -41,8 +41,8 @@ namespace {              return TBase::allocate(n);          }      }; -} - +}  +   Y_UNIT_TEST_SUITE(TStackBasedVectorTest) {      Y_UNIT_TEST(TestCreateEmpty) {          TStackVec<int> ints; @@ -98,34 +98,34 @@ Y_UNIT_TEST_SUITE(TStackBasedVectorTest) {              UNIT_ASSERT_EQUAL(ints3[i], (int)i);          }      } - -    Y_UNIT_TEST(TestCappedSize) { -        TStackVec<int, 8, false> ints; -        ints.push_back(1); -        ints.push_back(2); - -        auto intsCopy = ints; -        UNIT_ASSERT_VALUES_EQUAL(intsCopy.capacity(), 8); - -        for (int i = 2; i != 8; ++i) { -            intsCopy.push_back(i); -        } -        // Just verify that the program did not crash. -    } - -    Y_UNIT_TEST(TestCappedSizeWithNotCopyAssignable) { -        TStackVec<TNotCopyAssignable, 8, false> values; -        values.push_back({1}); -        values.push_back({2}); - -        auto valuesCopy = values; -        UNIT_ASSERT_VALUES_EQUAL(valuesCopy.capacity(), 8); - -        for (int i = 2; i != 8; ++i) { -            valuesCopy.push_back({i}); -        } -        // Just verify that the program did not crash. -    } +  +    Y_UNIT_TEST(TestCappedSize) {  +        TStackVec<int, 8, false> ints;  +        ints.push_back(1);  +        ints.push_back(2);  +  +        auto intsCopy = ints;  +        UNIT_ASSERT_VALUES_EQUAL(intsCopy.capacity(), 8);  +  +        for (int i = 2; i != 8; ++i) {  +            intsCopy.push_back(i);  +        }  +        // Just verify that the program did not crash.  +    }  +  +    Y_UNIT_TEST(TestCappedSizeWithNotCopyAssignable) {  +        TStackVec<TNotCopyAssignable, 8, false> values;  +        values.push_back({1});  +        values.push_back({2});  +  +        auto valuesCopy = values;  +        UNIT_ASSERT_VALUES_EQUAL(valuesCopy.capacity(), 8);  +  +        for (int i = 2; i != 8; ++i) {  +            valuesCopy.push_back({i});  +        }  +        // Just verify that the program did not crash.  +    }       Y_UNIT_TEST(TestCustomAllocSize) {          constexpr size_t n = 16384;  | 
