diff options
author | iseg <iseg@yandex-team.ru> | 2022-02-10 16:49:39 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:49:39 +0300 |
commit | 8b71ce88bea710a9663bb143e4916f961c57212e (patch) | |
tree | 5d5cb817648f650d76cf1076100726fd9b8448e8 /library/cpp/containers | |
parent | f828a15ab90e9ca8e848f83caf95c95f06be46e7 (diff) | |
download | ydb-8b71ce88bea710a9663bb143e4916f961c57212e.tar.gz |
Restoring authorship annotation for <iseg@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/containers')
-rw-r--r-- | library/cpp/containers/atomizer/atomizer.h | 52 | ||||
-rw-r--r-- | library/cpp/containers/str_map/str_map.h | 58 |
2 files changed, 55 insertions, 55 deletions
diff --git a/library/cpp/containers/atomizer/atomizer.h b/library/cpp/containers/atomizer/atomizer.h index dd8a3d0a5ba..5e40f47ab93 100644 --- a/library/cpp/containers/atomizer/atomizer.h +++ b/library/cpp/containers/atomizer/atomizer.h @@ -1,5 +1,5 @@ #pragma once - + #include <library/cpp/containers/str_map/str_map.h> #include <util/generic/vector.h> @@ -14,12 +14,12 @@ class atomizer; template <class T, class HashFcn = THash<const char*>, class EqualTo = TEqualTo<const char*>> class super_atomizer; -template <class HashFcn, class EqualTo> +template <class HashFcn, class EqualTo> class atomizer: public string_hash<ui32, HashFcn, EqualTo> { private: TVector<const char*> order; -public: +public: using iterator = typename string_hash<ui32, HashFcn, EqualTo>::iterator; using const_iterator = typename string_hash<ui32, HashFcn, EqualTo>::const_iterator; using value_type = typename string_hash<ui32, HashFcn, EqualTo>::value_type; @@ -34,13 +34,13 @@ public: using string_hash<ui32, HashFcn, EqualTo>::clear_hash; atomizer() { - order.reserve(HASH_SIZE_DEFAULT); - } + order.reserve(HASH_SIZE_DEFAULT); + } atomizer(size_type hash_size, pool_size_type pool_size) : string_hash<ui32, HashFcn, EqualTo>(hash_size, pool_size) - { - order.reserve(hash_size); - } + { + order.reserve(hash_size); + } ~atomizer() = default; ui32 string_to_atom(const char* key) { const char* old_begin = pool.Begin(); @@ -49,36 +49,36 @@ public: if (ins.second) { // new? if (pool.Begin() != old_begin) // repoint? for (TVector<const char*>::iterator ptr = order.begin(); ptr != order.end(); ++ptr) - if (old_begin <= *ptr && *ptr < old_end) // from old pool? + if (old_begin <= *ptr && *ptr < old_end) // from old pool? *ptr += pool.Begin() - old_begin; - order.push_back((*ins.first).first); // copy of 'key' - } + order.push_back((*ins.first).first); // copy of 'key' + } return (ui32)(*ins.first).second; - } - + } + ui32 perm_string_to_atom(const char* key) { value_type val(key, ui32(size() + 1)); std::pair<iterator, bool> ins = this->insert(val); - if (ins.second) - order.push_back((*ins.first).first); // == copy of 'key' + if (ins.second) + order.push_back((*ins.first).first); // == copy of 'key' return (ui32)(*ins.first).second; // == size()+1 - } + } ui32 find_atom(const char* key) const { const_iterator it = find(key); - if (it == end()) - return 0; // INVALID_ATOM - else + if (it == end()) + return 0; // INVALID_ATOM + else return (ui32)(*it).second; - } + } const char* get_atom_name(ui32 atom) const { - if (atom && atom <= size()) + if (atom && atom <= size()) return order[atom - 1]; return nullptr; - } + } void clear_atomizer() { - clear_hash(); - order.clear(); - } + clear_hash(); + order.clear(); + } void SaveC2N(FILE* f) const { // we write sorted file for (ui32 i = 0; i < order.size(); i++) if (order[i]) @@ -197,4 +197,4 @@ public: clear_hash(); order.clear(); } -}; +}; diff --git a/library/cpp/containers/str_map/str_map.h b/library/cpp/containers/str_map/str_map.h index a6d44db7c44..31b00d1b997 100644 --- a/library/cpp/containers/str_map/str_map.h +++ b/library/cpp/containers/str_map/str_map.h @@ -1,5 +1,5 @@ #pragma once - + #include <util/memory/segmented_string_pool.h> #include <util/generic/map.h> #include <util/generic/hash.h> @@ -7,14 +7,14 @@ #include <util/str_stl.h> // less<> and equal_to<> for const char* #include <utility> #include <util/generic/noncopyable.h> - + template <class T, class HashFcn = THash<const char*>, class EqualTo = TEqualTo<const char*>, class Alloc = std::allocator<const char*>> class string_hash; template <class T, class HashFcn = THash<const char*>, class EqualTo = TEqualTo<const char*>> class segmented_string_hash; -template <class Map> +template <class Map> inline std::pair<typename Map::iterator, bool> pool_insert(Map* m, const char* key, const typename Map::mapped_type& data, TBuffer& pool) { std::pair<typename Map::iterator, bool> ins = m->insert(typename Map::value_type(key, data)); @@ -23,23 +23,23 @@ pool_insert(Map* m, const char* key, const typename Map::mapped_type& data, TBuf const char* old_pool = pool.Begin(); pool.Append(key, buflen); if (pool.Begin() != old_pool) // repoint? - for (typename Map::iterator it = m->begin(); it != m->end(); ++it) - if ((*it).first != key) + for (typename Map::iterator it = m->begin(); it != m->end(); ++it) + if ((*it).first != key) const_cast<const char*&>((*it).first) += (pool.Begin() - old_pool); const_cast<const char*&>((*ins.first).first) = pool.End() - buflen; - } - return ins; -} - + } + return ins; +} + #define HASH_SIZE_DEFAULT 100 #define AVERAGEWORD_BUF 10 template <class T, class HashFcn, class EqualTo, class Alloc> class string_hash: public THashMap<const char*, T, HashFcn, EqualTo, Alloc> { -protected: +protected: TBuffer pool; -public: +public: using yh = THashMap<const char*, T, HashFcn, EqualTo, Alloc>; using iterator = typename yh::iterator; using const_iterator = typename yh::const_iterator; @@ -48,24 +48,24 @@ public: using pool_size_type = typename yh::size_type; string_hash() { pool.Reserve(HASH_SIZE_DEFAULT * AVERAGEWORD_BUF); // reserve here - } + } string_hash(size_type hash_size, pool_size_type pool_size) : THashMap<const char*, T, HashFcn, EqualTo, Alloc>(hash_size) - { + { pool.Reserve(pool_size); // reserve here - } - + } + std::pair<iterator, bool> insert_copy(const char* key, const mapped_type& data) { - return ::pool_insert(this, key, data, pool); - } - + return ::pool_insert(this, key, data, pool); + } + void clear_hash() { yh::clear(); pool.Clear(); - } + } pool_size_type pool_size() const { return pool.Size(); - } + } string_hash(const string_hash& sh) : THashMap<const char*, T, HashFcn, EqualTo, Alloc>() @@ -98,8 +98,8 @@ public: I = insert_copy(key, mapped_type()).first; return (*I).second; } -}; - +}; + template <class C, class T, class HashFcn, class EqualTo> class THashWithSegmentedPoolForKeys: protected THashMap<const C*, T, HashFcn, EqualTo>, TNonCopyable { protected: @@ -113,7 +113,7 @@ public: using size_type = typename yh::size_type; using key_type = typename yh::key_type; using value_type = typename yh::value_type; - + THashWithSegmentedPoolForKeys(size_type hash_size = HASH_SIZE_DEFAULT, size_t segsize = HASH_SIZE_DEFAULT * AVERAGEWORD_BUF, bool afs = false) : yh(hash_size) , pool(segsize) @@ -177,7 +177,7 @@ public: template <class T, class HashFcn, class EqualTo> class segmented_string_hash: public THashWithSegmentedPoolForKeys<char, T, HashFcn, EqualTo> { -public: +public: using Base = THashWithSegmentedPoolForKeys<char, T, HashFcn, EqualTo>; using iterator = typename Base::iterator; using const_iterator = typename Base::const_iterator; @@ -189,17 +189,17 @@ public: public: segmented_string_hash(size_type hash_size = HASH_SIZE_DEFAULT, size_t segsize = HASH_SIZE_DEFAULT * AVERAGEWORD_BUF, bool afs = false) : Base(hash_size, segsize, afs) - { - } + { + } std::pair<iterator, bool> insert_copy(const char* key, const mapped_type& data) { return Base::insert_copy(key, strlen(key) + 1, data); - } + } mapped_type& operator[](const char* key) { iterator I = Base::find(key); if (I == Base::end()) I = insert_copy(key, mapped_type()).first; return (*I).second; - } -}; + } +}; |