コード例 #1
0
 internal HashtableEntry(KeyType key, ValueType value, uint hashCode, HashtableEntry <KeyType, ValueType> next)
 {
     this.Key      = key;
     this.Value    = value;
     this.hashCode = hashCode;
     this.next     = next;
 }
コード例 #2
0
 public ValueType this[KeyType key]
 {
     get
     {
         var e = this.GetHashtableEntry(key, (uint)key.GetHashCode());
         if (e == null)
         {
             return(default(ValueType));
         }
         return(e.Value);
     }
     set
     {
         uint hashCode = (uint)key.GetHashCode();
         var  e        = this.GetHashtableEntry(key, hashCode);
         if (e != null)
         {
             e.Key   = key;
             e.Value = value;
             return;
         }
         if (++this.Count >= threshold)
         {
             this.Rehash();
         }
         uint index = hashCode % (uint)table.Length;
         table[index] = new HashtableEntry <KeyType, ValueType>(key, value, hashCode, table[index]);
     }
 }
コード例 #3
0
 internal HashtableEntry(HashtableEntry <KeyType, ValueType> template)
 {
     this.Key      = template.Key;
     this.Value    = template.Value;
     this.hashCode = template.hashCode;
     if (template.next != null)
     {
         this.next = new HashtableEntry <KeyType, ValueType>(template.next);
     }
 }
コード例 #4
0
        public bool TryGetValue(KeyType key, out ValueType result)
        {
            HashtableEntry <KeyType, ValueType> e = this.GetHashtableEntry(key, (uint)key.GetHashCode());

            if (e == null)
            {
                result = default(ValueType);
                return(false);
            }
            else
            {
                result = e.Value;
                return(true);
            }
        }
コード例 #5
0
 public bool MoveNext()
 {
     if (this.currentEntry != null)
     {
         this.currentEntry = this.currentEntry.next;
     }
     while (this.currentEntry == null)
     {
         if (this.tableIndex >= this.table.Length)
         {
             return(false);
         }
         this.currentEntry = this.table[this.tableIndex++];
     }
     return(true);
 }
コード例 #6
0
        public SimpleHashtable(SimpleHashtable <KeyType, ValueType> template)
        {
            this.Count = template.Count;
            threshold  = template.threshold;
            int n = template.table.Length;

            table = new HashtableEntry <KeyType, ValueType> [n];
            for (int i = 0; i < n; i++)
            {
                var templateEntry = template.table[i];
                if (templateEntry != null)
                {
                    table[i] = new HashtableEntry <KeyType, ValueType>(templateEntry);
                }
            }
        }
コード例 #7
0
 public bool MoveNext()
 {
     if (currentEntry != null)
     {
         currentEntry = currentEntry.next;
     }
     while (currentEntry == null)
     {
         if (tableIndex >= table.Length)
         {
             return(false);
         }
         currentEntry = table[tableIndex++];
     }
     return(true);
 }
コード例 #8
0
        public void Add(KeyType key, ValueType value)
        {
            uint hashCode = (uint)key.GetHashCode();
            var  e        = this.GetHashtableEntry(key, hashCode);

            if (e != null)
            {
                throw new InvalidOperationException();
            }
            if (++this.Count >= threshold)
            {
                this.Rehash();
            }
            uint index = hashCode % (uint)table.Length;

            table[index] = new HashtableEntry <KeyType, ValueType>(key, value, hashCode, table[index]);
        }
コード例 #9
0
 internal HashtableEntryEnumerator(HashtableEntry <KeyType, ValueType>[] table)
 {
     this.table        = table;
     this.tableIndex   = 0;
     this.currentEntry = null;
 }