
#ifndef PORYGONLANG_BOUNDVARIABLEKEY_HPP
#define PORYGONLANG_BOUNDVARIABLEKEY_HPP

#include <string>
#include "../../Utilities/HashedString.hpp"

namespace Porygon::Binder {
    class BoundVariableKey {
        const Utilities::HashedString _identifier;
        const unsigned int _scopeId;
        const bool _isCreation;
        const uint64_t _hash;

        static uint64_t KnuthsHash(unsigned int i1, unsigned int i2) {
            uint64_t ret = i1;
            ret *= 2654435761U;
            return ret ^ i2;
        }

    public:
        BoundVariableKey(const Utilities::HashedString& id, unsigned int scope, bool creation)
                : _identifier(id),
                  _scopeId(scope),
                  _isCreation(creation),
                  _hash(KnuthsHash(id.GetHash(), scope)) {}


        [[nodiscard]]
        inline const Utilities::HashedString* GetIdentifier() const {
            return &_identifier;
        }

        [[nodiscard]]
        inline unsigned int GetScopeId() const {
            return _scopeId;
        }

        [[nodiscard]]
        inline bool IsCreation() const {
            return _isCreation;
        }

        [[nodiscard]]
        inline uint64_t GetHash() const {
            return _hash;
        }
    };
}

#endif //PORYGONLANG_BOUNDVARIABLEKEY_HPP
