123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
- #pragma warning disable
- using System;
- using System.Collections;
- namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Collections
- {
- public class LinkedDictionary
- : IDictionary
- {
- internal readonly IDictionary hash = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateHashtable();
- internal readonly IList keys = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList();
- public LinkedDictionary()
- {
- }
- public virtual void Add(object k, object v)
- {
- hash.Add(k, v);
- keys.Add(k);
- }
- public virtual void Clear()
- {
- hash.Clear();
- keys.Clear();
- }
- public virtual bool Contains(object k)
- {
- return hash.Contains(k);
- }
- public virtual void CopyTo(Array array, int index)
- {
- foreach (object k in keys)
- {
- array.SetValue(hash[k], index++);
- }
- }
- public virtual int Count
- {
- get { return hash.Count; }
- }
- IEnumerator IEnumerable.GetEnumerator()
- {
- return GetEnumerator();
- }
- public virtual IDictionaryEnumerator GetEnumerator()
- {
- return new LinkedDictionaryEnumerator(this);
- }
- public virtual void Remove(object k)
- {
- hash.Remove(k);
- keys.Remove(k);
- }
- public virtual bool IsFixedSize
- {
- get { return false; }
- }
- public virtual bool IsReadOnly
- {
- get { return false; }
- }
- public virtual bool IsSynchronized
- {
- get { return false; }
- }
- public virtual object SyncRoot
- {
- get { return false; }
- }
- public virtual ICollection Keys
- {
- get { return BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList(keys); }
- }
- public virtual ICollection Values
- {
- // NB: Order has to be the same as for Keys property
- get
- {
- IList values = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList(keys.Count);
- foreach (object k in keys)
- {
- values.Add(hash[k]);
- }
- return values;
- }
- }
- public virtual object this[object k]
- {
- get
- {
- return hash[k];
- }
- set
- {
- if (!hash.Contains(k))
- keys.Add(k);
- hash[k] = value;
- }
- }
- }
- internal class LinkedDictionaryEnumerator : IDictionaryEnumerator
- {
- private readonly LinkedDictionary parent;
- private int pos = -1;
- internal LinkedDictionaryEnumerator(LinkedDictionary parent)
- {
- this.parent = parent;
- }
- public virtual object Current
- {
- get { return Entry; }
- }
- public virtual DictionaryEntry Entry
- {
- get
- {
- object k = CurrentKey;
- return new DictionaryEntry(k, parent.hash[k]);
- }
- }
- public virtual object Key
- {
- get
- {
- return CurrentKey;
- }
- }
- public virtual bool MoveNext()
- {
- if (pos >= parent.keys.Count)
- return false;
- return ++pos < parent.keys.Count;
- }
- public virtual void Reset()
- {
- this.pos = -1;
- }
- public virtual object Value
- {
- get
- {
- return parent.hash[CurrentKey];
- }
- }
- private object CurrentKey
- {
- get
- {
- if (pos < 0 || pos >= parent.keys.Count)
- throw new InvalidOperationException();
- return parent.keys[pos];
- }
- }
- }
- }
- #pragma warning restore
- #endif
|