greg7mdp / parallel-hashmap

A family of header-only, very fast and memory-friendly hashmap and btree containers.
https://greg7mdp.github.io/parallel-hashmap/
Apache License 2.0
2.53k stars 239 forks source link

LLDB pretty-printer is buggy #204

Open HolyBlackCat opened 1 year ago

HolyBlackCat commented 1 year ago

The LLDB pretty-printer sometimes prints junk values. Consider following example:

#include <iostream>
#include <parallel_hashmap/phmap.h>

struct ivec2
{
    int x = 0, y = 0;

    friend bool operator==(ivec2 a, ivec2 b)
    {
        return a.x == b.x && a.y == b.y;
    }
};

template <>
struct std::hash<ivec2>
{
    std::size_t operator()(ivec2 v) const
    {
        std::size_t ret = std::hash<int>{}(v.x);
        ret ^= std::hash<int>{}(v.y) + std::size_t(0x9E3779B97F4A7C16) + (ret << 6) + (ret >> 2);
        return ret;
    }
};

int main()
{
    phmap::flat_hash_map<ivec2, int> m{{{20,10},1},{{18,8},0}};
    std::cout << m.at({18,20}) << '\n';
}

I did:

clang++-16 1.cpp -g -Iparallel-hashmap
lldb-16 a.out

Then typed:

command script import parallel-hashmap/phmap_lldb.py
b 28
run
p m

This gave me following output:

(phmap::flat_hash_map<ivec2, int, phmap::Hash<ivec2>, phmap::EqualTo<ivec2>, std::allocator<std::pair<const ivec2, int> > >) $0 = size = 2 (capacity = 3) {
  [0] = {{...}, {...}} {
    value = {
      first = (x = 18, y = 8)
      second = 0
    }
    mutable_value = {
      first = (x = 18, y = 8)
      second = 0
    }
    key = (x = 18, y = 8)
  }
  [1] = {{...}, {...}} {
    value = {
      first = (x = 0, y = 0)
      second = 0
    }
    mutable_value = {
      first = (x = 0, y = 0)
      second = 0
    }
    key = (x = 0, y = 0)
  }
}

Notice key = (x = 0, y = 0) for the second element, while it should be key = (x = 18, y = 8).

Also, I don't know if it's easy to configure, but it's probably a good idea to remove repetition in the output too (key is printed 3 times, and the value is printed 2 times).

greg7mdp commented 1 year ago

Thanks for letting me know, @HolyBlackCat . It was a contribution and I don't use it myself, but I'll have a look when I have some time. It probably isn't too hard to fix.

greg7mdp commented 1 year ago

@HolyBlackCat I fixed the issues you mentioned. I believe it is working fine for the flat versions. The node versions still need some work.