Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const long long P = 41;
- const int hashes_count = 2;
- const long long mods[hashes_count] = {1000000087, 1000000093};
- class Hashes {
- long long hashes[hashes_count];
- inline static long long mod(long long x, long long m) {
- long long res = x % m;
- return res < 0 ? res + m : res;
- }
- public:
- Hashes() {
- for (int i = 0; i < hashes_count; i++)
- hashes[i] = 0;
- }
- Hashes operator =(const Hashes &other) {
- for (int i = 0; i < hashes_count; i++)
- hashes[i] = other.hashes[i];
- return *this;
- }
- Hashes(const Hashes &other) {
- for (int i = 0; i < hashes_count; i++)
- hashes[i] = other.hashes[i];
- }
- Hashes operator +=(int value) {
- for (int i = 0; i < hashes_count; i++)
- hashes[i] = mod(hashes[i] + value, mods[i]);
- return *this;
- }
- Hashes operator +=(const Hashes &other) {
- for (int i = 0; i < hashes_count; i++)
- hashes[i] = mod(hashes[i] + other.hashes[i], mods[i]);
- return *this;
- }
- Hashes operator *=(int value) {
- for (int i = 0; i < hashes_count; i++)
- hashes[i] = mod(hashes[i] * value, mods[i]);
- return *this;
- }
- friend bool operator <(const Hashes &a, const Hashes &b);
- friend bool operator ==(const Hashes &a, const Hashes &b);
- };
- bool operator <(const Hashes &a, const Hashes &b) {
- for (int i = 0; i < hashes_count; i++)
- if (a.hashes[i] != b.hashes[i])
- return a.hashes[i] < b.hashes[i];
- return false;
- }
- bool operator ==(const Hashes &a, const Hashes &b) {
- for (int i = 0; i < hashes_count; i++)
- if (a.hashes[i] != b.hashes[i])
- return false;
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement