Example #1
0
            /// <summary>
            /// Initializes a new instance of the <see cref="ImmutableHashMap&lt;TKey, TValue&gt;.HashBucket"/> class.
            /// </summary>
            /// <param name="suggestedHashRoll">The suggested hash roll.</param>
            /// <param name="bucket1">The bucket1.</param>
            /// <param name="bucket2">The bucket2.</param>
            internal HashBucket(int suggestedHashRoll, ValueOrListBucket bucket1, ValueOrListBucket bucket2)
            {
                RoslynDebug.AssertNotNull(bucket1);
                RoslynDebug.AssertNotNull(bucket2);
                Debug.Assert(bucket1.Hash != bucket2.Hash);

                // find next hashRoll that causes these two to be slotted in different buckets
                var h1 = bucket1.Hash;
                var h2 = bucket2.Hash;
                int s1;
                int s2;

                for (var i = 0; i < 32; i++)
                {
                    _hashRoll = (suggestedHashRoll + i) & 31;
                    s1        = this.ComputeLogicalSlot(h1);
                    s2        = this.ComputeLogicalSlot(h2);
                    if (s1 != s2)
                    {
                        _count   = 2;
                        _used    = (1u << s1) | (1u << s2);
                        _buckets = new Bucket[2];
                        _buckets[this.ComputePhysicalSlot(s1)] = bucket1;
                        _buckets[this.ComputePhysicalSlot(s2)] = bucket2;
                        return;
                    }
                }

                throw new InvalidOperationException();
            }
Example #2
0
            /// <summary>
            /// Initializes a new instance of the <see cref="ImmutableHashMap&lt;TKey, TValue&gt;.HashBucket"/> class.
            /// </summary>
            /// <param name="suggestedHashRoll">The suggested hash roll.</param>
            /// <param name="bucket1">The bucket1.</param>
            /// <param name="bucket2">The bucket2.</param>
            internal HashBucket(int suggestedHashRoll, ValueOrListBucket bucket1, ValueOrListBucket bucket2)
            {
                Contract.Requires(bucket1 != null);
                Contract.Requires(bucket2 != null);
                Contract.Requires(bucket1.Hash != bucket2.Hash);

                // find next hashRoll that causes these two to be slotted in different buckets
                var h1 = bucket1.Hash;
                var h2 = bucket2.Hash;
                int s1;
                int s2;

                for (int i = 0; i < 32; i++)
                {
                    this.hashRoll = (suggestedHashRoll + i) & 31;
                    s1            = this.ComputeLogicalSlot(h1);
                    s2            = this.ComputeLogicalSlot(h2);
                    if (s1 != s2)
                    {
                        this.count   = 2;
                        this.used    = (1u << s1) | (1u << s2);
                        this.buckets = new Bucket[2];
                        this.buckets[this.ComputePhysicalSlot(s1)] = bucket1;
                        this.buckets[this.ComputePhysicalSlot(s2)] = bucket2;
                        return;
                    }
                }

                throw new InvalidOperationException();
            }
            internal HashBucket(int suggestedHashRoll, ValueOrListBucket bucket1, ValueOrListBucket bucket2)
            {
                Debug.Assert(bucket1 != null);
                Debug.Assert(bucket2 != null);
                Debug.Assert(bucket1.Hash != bucket2.Hash);

                int h1 = bucket1.Hash;
                int h2 = bucket2.Hash;

                for (int i = 0; i < 32; i++)
                {
                    _hashRoll = (suggestedHashRoll + i) & 31;
                    int s1 = this.ComputeLogicalSlot(h1);
                    int s2 = this.ComputeLogicalSlot(h2);

                    if (s1 != s2)
                    {
                        _count   = 2;
                        _used    = (1u << s1) | (1u << s2);
                        _buckets = new Bucket[2];
                        _buckets[this.ComputePhysicalSlot(s1)] = bucket1;
                        _buckets[this.ComputePhysicalSlot(s2)] = bucket2;
                        return;
                    }
                }

                throw new InvalidOperationException();
            }