diff options
author | Anton Samokhvalov <pg83@yandex.ru> | 2022-02-10 16:45:15 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:15 +0300 |
commit | 72cb13b4aff9bc9cf22e49251bc8fd143f82538f (patch) | |
tree | da2c34829458c7d4e74bdfbdf85dff449e9e7fb8 /library/cpp/containers/str_map/str_map.h | |
parent | 778e51ba091dc39e7b7fcab2b9cf4dbedfb6f2b5 (diff) | |
download | ydb-72cb13b4aff9bc9cf22e49251bc8fd143f82538f.tar.gz |
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/containers/str_map/str_map.h')
-rw-r--r-- | library/cpp/containers/str_map/str_map.h | 66 |
1 files changed, 33 insertions, 33 deletions
diff --git a/library/cpp/containers/str_map/str_map.h b/library/cpp/containers/str_map/str_map.h index 31b00d1b99..47a4540787 100644 --- a/library/cpp/containers/str_map/str_map.h +++ b/library/cpp/containers/str_map/str_map.h @@ -1,44 +1,44 @@ #pragma once -#include <util/memory/segmented_string_pool.h> +#include <util/memory/segmented_string_pool.h> #include <util/generic/map.h> #include <util/generic/hash.h> -#include <util/generic/buffer.h> -#include <util/str_stl.h> // less<> and equal_to<> for const char* +#include <util/generic/buffer.h> +#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 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> inline std::pair<typename Map::iterator, bool> -pool_insert(Map* m, const char* key, const typename Map::mapped_type& data, TBuffer& pool) { +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)); - if (ins.second) { // new? - size_t buflen = strlen(key) + 1; // strlen??? - const char* old_pool = pool.Begin(); - pool.Append(key, buflen); - if (pool.Begin() != old_pool) // repoint? + if (ins.second) { // new? + size_t buflen = strlen(key) + 1; // strlen??? + 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) - const_cast<const char*&>((*it).first) += (pool.Begin() - old_pool); - const_cast<const char*&>((*ins.first).first) = pool.End() - buflen; + const_cast<const char*&>((*it).first) += (pool.Begin() - old_pool); + const_cast<const char*&>((*ins.first).first) = pool.End() - buflen; } return ins; } #define HASH_SIZE_DEFAULT 100 -#define AVERAGEWORD_BUF 10 +#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: - TBuffer pool; - + TBuffer pool; + public: using yh = THashMap<const char*, T, HashFcn, EqualTo, Alloc>; using iterator = typename yh::iterator; @@ -46,25 +46,25 @@ public: using mapped_type = typename yh::mapped_type; using size_type = typename yh::size_type; using pool_size_type = typename yh::size_type; - string_hash() { - pool.Reserve(HASH_SIZE_DEFAULT * AVERAGEWORD_BUF); // reserve here + 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 + 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); } - void clear_hash() { + void clear_hash() { yh::clear(); - pool.Clear(); + pool.Clear(); } - pool_size_type pool_size() const { - return pool.Size(); + pool_size_type pool_size() const { + return pool.Size(); } string_hash(const string_hash& sh) @@ -83,7 +83,7 @@ public: (const char*&)(*i).first += delta; } */ - string_hash& operator=(const string_hash& sh) { + string_hash& operator=(const string_hash& sh) { if (&sh != this) { clear_hash(); for (const_iterator i = sh.begin(); i != sh.end(); ++i) @@ -92,7 +92,7 @@ public: return *this; } - mapped_type& operator[](const char* key) { + mapped_type& operator[](const char* key) { iterator I = yh::find(key); if (I == yh::end()) I = insert_copy(key, mapped_type()).first; @@ -104,7 +104,7 @@ template <class C, class T, class HashFcn, class EqualTo> class THashWithSegmentedPoolForKeys: protected THashMap<const C*, T, HashFcn, EqualTo>, TNonCopyable { protected: segmented_pool<C> pool; - + public: using yh = THashMap<const C*, T, HashFcn, EqualTo>; using iterator = typename yh::iterator; @@ -176,7 +176,7 @@ public: }; template <class T, class HashFcn, class EqualTo> -class segmented_string_hash: public THashWithSegmentedPoolForKeys<char, T, HashFcn, EqualTo> { +class segmented_string_hash: public THashWithSegmentedPoolForKeys<char, T, HashFcn, EqualTo> { public: using Base = THashWithSegmentedPoolForKeys<char, T, HashFcn, EqualTo>; using iterator = typename Base::iterator; @@ -185,10 +185,10 @@ public: using size_type = typename Base::size_type; using key_type = typename Base::key_type; using value_type = typename Base::value_type; - + 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) + : Base(hash_size, segsize, afs) { } |