@@ -21,6 +21,33 @@ namespace {
21
21
22
22
typedef std::pair<TStringBuf, TStringBuf> TDescriptor;
23
23
24
+ [[noreturn]]
25
+ void ReportRedefinitionError (const TStringBuf key, const TStringBuf data, const ui64 kk, const TDescriptor& prev) noexcept {
26
+ const auto & [prevKey, value] = prev;
27
+ Y_ABORT_UNLESS (key == prevKey, " Internal hash collision:"
28
+ " old key: %s,"
29
+ " new key: %s,"
30
+ " hash: %" PRIx64 " ." ,
31
+ TString{prevKey}.Quote ().c_str (),
32
+ TString{key}.Quote ().c_str (),
33
+ kk);
34
+ size_t vsize = GetCodec ()->DecompressedLength (value);
35
+ size_t dsize = GetCodec ()->DecompressedLength (data);
36
+ if (vsize + dsize < 1000 ) {
37
+ Y_ABORT_UNLESS (false , " Redefinition of key %s:\n "
38
+ " old value: %s,\n "
39
+ " new value: %s." ,
40
+ TString{key}.Quote ().c_str (),
41
+ Decompress (value).Quote ().c_str (),
42
+ Decompress (data).Quote ().c_str ());
43
+ } else {
44
+ Y_ABORT_UNLESS (false , " Redefinition of key %s,"
45
+ " old size: %zu,"
46
+ " new size: %zu." ,
47
+ TString{key}.Quote ().c_str (), vsize, dsize);
48
+ }
49
+ }
50
+
24
51
struct TStore final : public IStore, public absl::flat_hash_map<ui64, TDescriptor*> {
25
52
static inline ui64 ToK (TStringBuf k) {
26
53
return NHashPrivate::ComputeStringHash (k.data (), k.size ());
@@ -29,28 +56,16 @@ namespace {
29
56
void Store (const TStringBuf key, const TStringBuf data) override {
30
57
auto kk = ToK (key);
31
58
32
- if (contains (kk)) {
33
- const TStringBuf value = (*this )[kk]->second ;
59
+ const auto [it, unique] = try_emplace (kk, nullptr );
60
+ if (!unique) {
61
+ const auto & [_, value] = *it->second ;
34
62
if (value != data) {
35
- size_t vsize = GetCodec ()->DecompressedLength (value);
36
- size_t dsize = GetCodec ()->DecompressedLength (data);
37
- if (vsize + dsize < 1000 ) {
38
- Y_ABORT_UNLESS (false , " Redefinition of key %s:\n "
39
- " old value: %s,\n "
40
- " new value: %s." ,
41
- TString{key}.Quote ().c_str (),
42
- Decompress (value).Quote ().c_str (),
43
- Decompress (data).Quote ().c_str ());
44
- } else {
45
- Y_ABORT_UNLESS (false , " Redefinition of key %s,"
46
- " old size: %zu,"
47
- " new size: %zu." ,
48
- TString{key}.Quote ().c_str (), vsize, dsize);
49
- }
63
+ ReportRedefinitionError (key, data, kk, *it->second );
64
+ Y_UNREACHABLE ();
50
65
}
51
66
} else {
52
67
D_.push_back (TDescriptor (key, data));
53
- (* this )[kk] = &D_.back ();
68
+ it-> second = &D_.back ();
54
69
}
55
70
56
71
Y_ABORT_UNLESS (size () == Count (), " size mismatch" );
0 commit comments