Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Faster hashmap #212

Open
Gullesnuffs opened this issue Aug 14, 2022 · 0 comments
Open

Faster hashmap #212

Gullesnuffs opened this issue Aug 14, 2022 · 0 comments

Comments

@Gullesnuffs
Copy link
Contributor

The following was >2x faster than std::unordered_map for https://codeforces.com/gym/103861/problem/B and the pbds hash map was also terrible (slow construction time? too much memory use?):

typedef uint64_t ull;                                                                                                                   
template<class T>
struct HashMap {
    int b;
    vector<pair<ull, T>> v;
    HashMap(int b) : b(b), v(1 << b) {}
    T& operator[](ull x) {
        ull y = x >> (64 - b), m = (1 << b) - 1;
        while (v[y].first && v[y].first != x) ++y &= m;
        v[y].first = x;
        return v[y].second;
    }   
};

Maybe worth adding to KACTL instead of the pbds one?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant