public XHashtable <TValue> .XHashtableState Resize()
            {
                if (this.numEntries < this.buckets.Length)
                {
                    return((XHashtable <TValue> .XHashtableState) this);
                }
                int capacity = 0;

                for (int i = 0; i < this.buckets.Length; i++)
                {
                    int index = this.buckets[i];
                    if (index == 0)
                    {
                        index = Interlocked.CompareExchange(ref this.buckets[i], -1, 0);
                    }
                    while (index > 0)
                    {
                        if (this.extractKey(this.entries[index].Value) != null)
                        {
                            capacity++;
                        }
                        if (this.entries[index].Next == 0)
                        {
                            index = Interlocked.CompareExchange(ref this.entries[index].Next, -1, 0);
                        }
                        else
                        {
                            index = this.entries[index].Next;
                        }
                    }
                }
                if (capacity < (this.buckets.Length / 2))
                {
                    capacity = this.buckets.Length;
                }
                else
                {
                    capacity = this.buckets.Length * 2;
                    if (capacity < 0)
                    {
                        throw new OverflowException();
                    }
                }
                XHashtable <TValue> .XHashtableState state = new XHashtable <TValue> .XHashtableState(this.extractKey, capacity);

                for (int j = 0; j < this.buckets.Length; j++)
                {
                    for (int k = this.buckets[j]; k > 0; k = this.entries[k].Next)
                    {
                        TValue local;
                        state.TryAdd(this.entries[k].Value, out local);
                    }
                }
                return(state);
            }
Example #2
0
        private const int NamespacesCapacity = 32;     // Starting capacity of XNamespace table, which must be power of 2

        /// <summary>
        /// Constructor, internal so that external users must go through the Get() method to create an XNamespace.
        /// </summary>
        internal XNamespace(string namespaceName)
        {
            _namespaceName = namespaceName;
            _hashCode      = namespaceName.GetHashCode();
            _names         = new XHashtable <XName>(ExtractLocalName, NamesCapacity);
        }
 public XHashtableState(XHashtable <TValue> .ExtractKeyDelegate extractKey, int capacity)
 {
     this.buckets    = new int[capacity];
     this.entries    = new Entry <TValue> [capacity];
     this.extractKey = extractKey;
 }
Example #4
0
 internal XNamespace(string namespaceName)
 {
     this.namespaceName = namespaceName;
     this.hashCode      = namespaceName.GetHashCode();
     this.names         = new XHashtable <XName>(new XHashtable <XName> .ExtractKeyDelegate(XNamespace.ExtractLocalName), 8);
 }