2929
3030#include " small_string_map.hh"
3131
32+ #include " lnav_log.hh"
33+
3234namespace lnav {
3335
3436std::optional<uint32_t >
@@ -47,6 +49,7 @@ small_string_map::lookup(const string_fragment& in)
4749 || this ->ssm_keys [index * MAX_KEY_SIZE + in.length ()] == ' \0 ' ))
4850 {
4951 this ->ssm_start_index = index;
52+ this ->ssm_age [index] = true ;
5053 return this ->ssm_values [index];
5154 }
5255 index = (index + 1 ) % MAP_SIZE ;
@@ -57,18 +60,27 @@ small_string_map::lookup(const string_fragment& in)
5760void
5861small_string_map::insert (const string_fragment& key, uint32_t value)
5962{
60- if (key.length () >= MAX_KEY_SIZE ) {
63+ if (key.empty () || key. length () > MAX_KEY_SIZE ) {
6164 return ;
6265 }
6366
64- auto key_index = this ->ssm_used_keys < MAP_SIZE ? this ->ssm_used_keys ++
65- : key.hash () % MAP_SIZE ;
67+ auto key_index = (this ->ssm_start_index + 1 ) % MAP_SIZE ;
68+ for (auto lpc = 0 ; lpc < MAP_SIZE ; lpc++) {
69+ if (!this ->ssm_age [lpc]) {
70+ key_index = lpc;
71+ } else {
72+ this ->ssm_age [lpc] = false ;
73+ }
74+ }
75+ this ->ssm_age [this ->ssm_start_index ] = true ;
76+ this ->ssm_age [key_index] = true ;
6677
6778 memset (&this ->ssm_keys [key_index * MAX_KEY_SIZE ],
6879 0 ,
6980 MAX_KEY_SIZE * sizeof (char ));
7081 memcpy (&this ->ssm_keys [key_index * MAX_KEY_SIZE ], key.data (), key.length ());
7182 this ->ssm_values [key_index] = value;
83+ this ->ssm_start_index = key_index;
7284}
7385
7486} // namespace lnav
0 commit comments