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

📄 altbtreecompoundindex.cs

📁 Perst开源实时数据库
💻 CS
字号:
namespace Perst.Impl
{
    using System;
#if USE_GENERICS
    using System.Collections.Generic;
#endif
    using System.Collections;
    using System.Diagnostics;
    using Perst;
    
#if USE_GENERICS
    class AltBtreeCompoundIndex<T>:AltBtree<object[],T>, CompoundIndex<T> where T:class,IPersistent
#else
    class AltBtreeCompoundIndex:AltBtree, CompoundIndex
#endif
    {
        ClassDescriptor.FieldType[]    types;

        internal AltBtreeCompoundIndex() 
        {
        }
    
        internal AltBtreeCompoundIndex(Type[] keyTypes, bool unique) 
        {
            this.unique = unique;
            type = ClassDescriptor.FieldType.tpArrayOfByte;        
            types = new ClassDescriptor.FieldType[keyTypes.Length];
            for (int i = 0; i < keyTypes.Length; i++) 
            {
                types[i] = checkType(keyTypes[i]);
            }
        }

        public Type[] KeyTypes
        {
            get
            { 
                Type[] keyTypes = new Type[types.Length];
                for (int i = 0; i < keyTypes.Length; i++) 
                { 
                     keyTypes[i] = mapKeyType(types[i]);
                }
                return keyTypes;
            }
        }

        [Serializable]
        internal class CompoundKey : IComparable
        {
            internal object[] keys;
            
            public int CompareTo(object o)
            {
                CompoundKey c = (CompoundKey) o;
                int n = keys.Length < c.keys.Length?keys.Length:c.keys.Length;
                for (int i = 0; i < n; i++)
                {
                    int diff = ((IComparable) keys[i]).CompareTo(c.keys[i]);
                    if (diff != 0)
                    {
                        return diff;
                    }
                }
                return  0; // allow to compare part of the compound key
            }
            
            internal CompoundKey(object[] keys)
            {
                this.keys = keys;
            }
        }
        
        private Key convertKey(Key key)
        {
            if (key == null)
            {
                return null;
            }
            if (key.type != ClassDescriptor.FieldType.tpArrayOfObject)
            {
                throw new StorageError(StorageError.ErrorCode.INCOMPATIBLE_KEY_TYPE);
            }
            return new Key(new CompoundKey((System.Object[]) key.oval), key.inclusion != 0);
        }
        
#if USE_GENERICS
        public override T Remove(Key key) 
#else
        public override IPersistent Remove(Key key) 
#endif
        {
            return base.Remove(convertKey(key));
        }       

#if USE_GENERICS
        public override void Remove(Key key, T obj)
#else
        public override void Remove(Key key, IPersistent obj)
#endif
        {

            base.Remove(convertKey(key), obj);
        }       

#if !USE_GENERICS
        public override IPersistent[] Get(Key from, Key till)
#else 
        public override T[] Get(Key from, Key till)
#endif
        {
            return base.Get(convertKey(from), convertKey(till));
        }

#if USE_GENERICS
        public override T Get(Key key) 
#else
        public override IPersistent Get(Key key) 
#endif
        {
            return base.Get(convertKey(key));
        }

#if USE_GENERICS
        public override bool Put(Key key, T obj)
#else
        public override bool Put(Key key, IPersistent obj)
#endif
        {
            return base.Put(convertKey(key), obj);
        }

#if USE_GENERICS
        public override T Set(Key key, T obj)
#else
        public override IPersistent Set(Key key, IPersistent obj)
#endif
        {
            return base.Set(convertKey(key), obj);
        }

#if USE_GENERICS
        public override IEnumerable<T> Range(Key from, Key till, IterationOrder order) 
#else
        public override IEnumerable Range(Key from, Key till, IterationOrder order) 
#endif
        { 
            return base.Range(convertKey(from), convertKey(till), order);
        }


        public override IDictionaryEnumerator GetDictionaryEnumerator(Key from, Key till, IterationOrder order) 
        {
            return base.GetDictionaryEnumerator(convertKey(from), convertKey(till), order);
        }
    }
}

⌨️ 快捷键说明

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