1using System;
2
3namespace Google.Protobuf
4{
5    /// <summary>
6    /// Struct used to hold the keys for the fieldByNumber table in DescriptorPool and the keys for the
7    /// extensionByNumber table in ExtensionRegistry.
8    /// </summary>
9    internal struct ObjectIntPair<T> : IEquatable<ObjectIntPair<T>> where T : class
10    {
11        private readonly int number;
12        private readonly T obj;
13
14        internal ObjectIntPair(T obj, int number)
15        {
16            this.number = number;
17            this.obj = obj;
18        }
19
20        public bool Equals(ObjectIntPair<T> other)
21        {
22            return obj == other.obj
23                   && number == other.number;
24        }
25
26        public override bool Equals(object obj)
27        {
28            if (obj is ObjectIntPair<T>)
29            {
30                return Equals((ObjectIntPair<T>)obj);
31            }
32            return false;
33        }
34
35        public override int GetHashCode()
36        {
37            return obj.GetHashCode() * ((1 << 16) - 1) + number;
38        }
39    }
40}
41