⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 persistentmapimpl.cs

📁 Perst开源实时数据库
💻 CS
📖 第 1 页 / 共 2 页
字号:
        {
            return GetDictionaryEnumerator();
        }
#else
        public override IEnumerator GetEnumerator()
        {
            return GetDictionaryEnumerator();
        }

        IDictionaryEnumerator IDictionary.GetEnumerator() 
        {
            return GetDictionaryEnumerator();
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return GetDictionaryEnumerator();
        }
#endif

        public IDictionaryEnumerator GetDictionaryEnumerator()
        {
            if (index != null) 
            { 
                return index.GetDictionaryEnumerator();
            } 
            else 
            {
                return new SmallMapDictionaryEnumerator(this);
            }
        }

#if USE_GENERICS
        public ICollection<K> Keys 
#else
        public ICollection Keys 
#endif
        {
            get 
            {
                if (keySet == null) 
                {
                    keySet = new KeySet(this);
                }
                return keySet;
            }
        }

#if USE_GENERICS
        public ICollection<V> Values 
#else
        public ICollection Values 
#endif
        {
            get 
            {
                if (valueSet == null) 
                {
                    valueSet = new ValueSet(this);
                }
                return valueSet;
            }
        }

        class SmallMapDictionaryEnumerator:IDictionaryEnumerator 
        {
#if USE_GENERICS
            PersistentMapImpl<K,V> map;
#else
            PersistentMapImpl map;
#endif
            int               i;

#if USE_GENERICS
            public SmallMapDictionaryEnumerator(PersistentMapImpl<K,V> map) 
#else
            public SmallMapDictionaryEnumerator(PersistentMapImpl map) 
#endif
            {
                this.map  = map;
                Reset();
            }

            public void Reset() 
            {
                i = -1;
            }

            public bool MoveNext()
            {
                if (i+1 < map.values.Count) 
                {
                    i += 1;
                    return true;
                }
                return false;
            }

            public object Current 
            {
                get 
                {
                    return Entry;
                }
            }
            
            public DictionaryEntry Entry 
            {
                get 
                {
                    return new DictionaryEntry(Key, Value);
                }
            }

            public object Key 
            {
                get 
                {
                    if (i < 0) 
                    {
                        throw new InvalidOperationException();
                    }               
                    return ((object[])map.keys)[i];
                }
            }

            public object Value 
            {
                get 
                {
                    if (i < 0) 
                    {
                        throw new InvalidOperationException();
                    }               
                    return map.values[i];
                }
            }
        }


#if USE_GENERICS

        class ValueEnumerator:IEnumerator<V>,IEnumerator
        {
            IDictionaryEnumerator e;
            
            public ValueEnumerator(IDictionaryEnumerator e)
            {
                this.e = e;
            }
        
            public void Reset() 
            {
                e.Reset();
            }

            public bool MoveNext() 
            {
                return e.MoveNext();
            }

            public void Dispose() {}
            
            object IEnumerator.Current
            {
                get 
                {
                    return e.Value;
                }
            }

            public V Current 
            {
                get 
                {
                    return (V)e.Value;
                }
            }
        }

        class KeyEnumerator:IEnumerator<K>,IEnumerator
        {
            IDictionaryEnumerator e;
            
            public KeyEnumerator(IDictionaryEnumerator e)
            {
                this.e = e;
            }
        
            public void Reset() 
            {
                e.Reset();
            }

            public bool MoveNext() 
            {
                return e.MoveNext();
            }

            public void Dispose() {}

            public K Current 
            {
                get 
                {
                    return (K)e.Key;
                }
            }

            object IEnumerator.Current
            {
                get 
                {
                    return e.Key;
                }
            }
        }

        abstract class ReadOnlyCollection<T>:ICollection<T>
        {
            protected PersistentMapImpl<K,V> map;
            
            protected ReadOnlyCollection(PersistentMapImpl<K,V> map)
            {
                this.map = map;
            }

            public int Count 
            {
                get 
                {
                    return map.Count;
                }
            }

            public bool IsSynchronized 
            {
                get 
                {
                    return false;
                }
            }

            public bool IsReadOnly 
            {
                get 
                {
                    return true;
                }
            }

            public object SyncRoot 
            {
                get 
                {
                    return null;
                }
            }

            public void CopyTo(T[] dst, int i) 
            {
                foreach (T obj in this)
                {
                    dst[i++] = obj;
                }
            }
            public void Add(T obj)
            {
                throw new InvalidOperationException("Collection is readonly");
            }

            public void Clear()
            {
                throw new InvalidOperationException("Collection is readonly");
            }

            public virtual bool Contains(T obj) 
            {
                if (obj == null)
                {
                    foreach (T o in this)
                    { 
                        if (o == null) 
                        {
                            return true;
                        }
                    }
                } 
                else 
                {  
                    foreach (T o in this)
                    {  
                        if (obj.Equals(o)) 
                        {
                            return true;
                        }
                    }
                }
                return false;
            }

            public virtual bool Remove(T obj) 
            {        
                throw new InvalidOperationException("Collection is readonly");
            }

            public abstract IEnumerator<T> GetEnumerator();

            IEnumerator IEnumerable.GetEnumerator()
            {
                return (IEnumerator)this.GetEnumerator();
            }
        }

        class ValueSet:ReadOnlyCollection<V>
        {
            public ValueSet(PersistentMapImpl<K,V> map) : base(map) {}
  
            public override IEnumerator<V> GetEnumerator() 
            {
                return new ValueEnumerator(map.GetDictionaryEnumerator());
            }
        }

                     

        class KeySet:ReadOnlyCollection<K>
        {
            public KeySet(PersistentMapImpl<K,V> map) : base(map) {}
 
            public override IEnumerator<K> GetEnumerator() 
            {
                return new KeyEnumerator(map.GetDictionaryEnumerator());
            }
        }

#else

        class ValueEnumerator:IEnumerator
        {
            IDictionaryEnumerator e;
            
            public ValueEnumerator(IDictionaryEnumerator e)
            {
                this.e = e;
            }
        
            public void Reset() 
            {
                e.Reset();
            }

            public bool MoveNext() 
            {
                return e.MoveNext();
            }

            public object Current 
            {
                get 
                {
                    return e.Value;
                }
            }
        }

        class KeyEnumerator:IEnumerator
        {
            IDictionaryEnumerator e;
            
            public KeyEnumerator(IDictionaryEnumerator e)
            {
                this.e = e;
            }
        
            public void Reset() 
            {
                e.Reset();
            }

            public bool MoveNext() 
            {
                return e.MoveNext();
            }

            public object Current 
            {
                get 
                {
                    return e.Key;
                }
            }
        }

        abstract class ReadOnlyCollection:ICollection
        {
            protected PersistentMapImpl map;
            
            protected ReadOnlyCollection(PersistentMapImpl map)
            {
                this.map = map;
            }

            public int Count 
            {
                get 
                {
                    return map.Count;
                }
            }

            public bool IsSynchronized 
            {
                get 
                {
                    return false;
                }
            }

            public object SyncRoot 
            {
                get 
                {
                    return null;
                }
            }

            public abstract IEnumerator GetEnumerator();

            public void CopyTo(Array dst, int i) 
            {
                foreach (object o in this) 
                { 
                    dst.SetValue(o, i++);
                }
            }
        }

        class ValueSet:ReadOnlyCollection 
        {
            public ValueSet(PersistentMapImpl map) : base(map) {}
  
            public override IEnumerator GetEnumerator() 
            {
                return new ValueEnumerator(map.GetDictionaryEnumerator());
            }
        }

                     

        class KeySet:ReadOnlyCollection 
        {
            public KeySet(PersistentMapImpl map) : base(map) {}
 
            public override IEnumerator GetEnumerator() 
            {
                return new KeyEnumerator(map.GetDictionaryEnumerator());
            }
        }
#endif
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -