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

📄 btreecompoundindex.cs

📁 Perst开源实时数据库
💻 CS
📖 第 1 页 / 共 2 页
字号:
                        offs += 4;
                        break;
                   
                    case ClassDescriptor.FieldType.tpUInt:
                        v = (uint)Bytes.unpack4(data, offs);
                        offs += 4;
                        break;
 
                    case ClassDescriptor.FieldType.tpOid:
                    case ClassDescriptor.FieldType.tpObject: 
                    {
                        int oid = Bytes.unpack4(data, offs);
                        v = oid == 0 ? null : ((StorageImpl)Storage).lookupObject(oid, null);
                        offs += 4;
                        break;
                    }
                    case ClassDescriptor.FieldType.tpLong: 
                        v = Bytes.unpack8(data, offs);
                        offs += 8;
                        break;

                    case ClassDescriptor.FieldType.tpDate: 
                    {
                        v = new DateTime(Bytes.unpack8(data, offs));
                        offs += 8;
                        break;
                    }
                    case ClassDescriptor.FieldType.tpULong: 
                        v = (ulong)Bytes.unpack8(data, offs);
                        offs += 8;
                        break;
 				
                    case ClassDescriptor.FieldType.tpFloat: 
                        v = Bytes.unpackF4(data, offs);
                        offs += 4;
                        break;

                    case ClassDescriptor.FieldType.tpDouble: 
                        v = Bytes.unpackF8(data, offs);
                        offs += 8;
                        break;

                    case ClassDescriptor.FieldType.tpDecimal:
                        v = Bytes.unpackDecimal(data, offs);
                        offs += 16;
                        break;

                    case ClassDescriptor.FieldType.tpGuid:
                        v = Bytes.unpackGuid(data, offs);
                        offs += 16;
                        break;

                    case ClassDescriptor.FieldType.tpString:
                    {
                        int len = Bytes.unpack4(data, offs);
                        offs += 4;
                        char[] sval = new char[len];
                        for (int j = 0; j < len; j++)
                        {
                            sval[j] = (char) Bytes.unpack2(pg.data, offs);
                            offs += 2;
                        }
                        v = new String(sval);
                        break;
                    }

                    case ClassDescriptor.FieldType.tpArrayOfByte:
                    {
                        int len = Bytes.unpack4(data, offs);
                        offs += 4;
                        byte[] val = new byte[len];
                        Array.Copy(pg.data, offs, val, 0, len);
                        offs += len;
                        v = val;
                        break;
                    }
                    default: 
                        Debug.Assert(false, "Invalid type");
                        break;
                }
                values[i] = v;
            }
            return values;
        }

        private Key convertKey(Key key) 
        { 
            if (key == null) 
            { 
                return null;
            }
            if (key.type != ClassDescriptor.FieldType.tpArrayOfObject) 
            { 
                throw new StorageError(StorageError.ErrorCode.INCOMPATIBLE_KEY_TYPE);
            }
            Object[] values = (Object[])key.oval;
            ByteBuffer buf = new ByteBuffer(null);
            int dst = 0;
                
            for (int i = 0; i < values.Length; i++) 
            { 
                dst = packKeyPart(buf, dst, types[i], values[i]);
            }
            return new Key(buf.toArray(), key.inclusion != 0);
        }

        private int packKeyPart(ByteBuffer buf, int dst, ClassDescriptor.FieldType type, object val)
        {
            switch (type) 
            {
                case ClassDescriptor.FieldType.tpBoolean:
                    dst = buf.packBool(dst, (bool)val);
                    break;
                case ClassDescriptor.FieldType.tpByte:
                    dst = buf.packI1(dst, (byte)val);
                    break;
                case ClassDescriptor.FieldType.tpSByte:
                    dst = buf.packI1(dst, (sbyte)val);
                    break;
                case ClassDescriptor.FieldType.tpShort:
                    dst = buf.packI2(dst, (short)val);
                    break;
                case ClassDescriptor.FieldType.tpUShort:
                    dst = buf.packI2(dst, (ushort)val);
                    break;
                case ClassDescriptor.FieldType.tpChar:
                    dst = buf.packI2(dst, (char)val);
                    break;
                case ClassDescriptor.FieldType.tpInt:
                case ClassDescriptor.FieldType.tpOid:
                case ClassDescriptor.FieldType.tpEnum:
                    dst = buf.packI4(dst, (int)val);
                    break;            
                case ClassDescriptor.FieldType.tpUInt:
                    dst = buf.packI4(dst, (int)(uint)val);
                    break;            
                case ClassDescriptor.FieldType.tpObject:
                    if (val != null) { 
                        IPersistent obj = (IPersistent)val;
                        if (!obj.IsPersistent())
                        {
                            Storage.MakePersistent(obj);
                        }                        
                        dst =  buf.packI4(dst, obj.Oid);
                    } else { 
                        dst =  buf.packI4(dst, 0);
                    }
                    break;            
                case ClassDescriptor.FieldType.tpLong:
                    dst = buf.packI8(dst, (long)val);
                    break;            
                case ClassDescriptor.FieldType.tpULong:
                    dst = buf.packI8(dst, (long)(ulong)val);
                    break;            
                case ClassDescriptor.FieldType.tpDate:
                    dst = buf.packDate(dst, (DateTime)val);
                    break;            
                case ClassDescriptor.FieldType.tpFloat: 
                    dst = buf.packF4(dst, (float)val);
                    break;            
                case ClassDescriptor.FieldType.tpDouble: 
                    dst = buf.packF8(dst, (double)val);
                    break;            
                case ClassDescriptor.FieldType.tpDecimal: 
                    dst = buf.packDecimal(dst, (decimal)val);
                    break;            
                case ClassDescriptor.FieldType.tpGuid: 
                    dst = buf.packGuid(dst, (Guid)val);
                    break;            
                case ClassDescriptor.FieldType.tpString:
                    dst = buf.packString(dst, (string)val);
                    break;            
                case ClassDescriptor.FieldType.tpArrayOfByte:
                    buf.extend(dst+4);
                    if (val != null) 
                    { 
                        byte[] arr = (byte[])val;
                        int len = arr.Length;
                        Bytes.pack4(buf.arr, dst, len);
                        dst += 4;                          
                        buf.extend(dst + len);
                        Array.Copy(arr, 0, buf.arr, dst, len);
                        dst += len;
                    } 
                    else 
                    { 
                        Bytes.pack4(buf.arr, dst, 0);
                        dst += 4;
                    }
                    break;
                default:
                    Debug.Assert(false, "Invalid type");
                    break;
            }
            return dst;
        }
 
#if USE_GENERICS
        public override V 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, V 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 V[] Get(Key from, Key till)
#endif
        {
            return base.Get(convertKey(from), convertKey(till));
        }

#if USE_GENERICS
        public override V 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, V obj)
#else
        public override bool Put(Key key, IPersistent obj)
#endif
        {
            return base.Put(convertKey(key), obj);
        }

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

 
#if USE_GENERICS
        public override IEnumerable<V> 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 + -