Ejemplo n.º 1
0
        /// <summary>
        /// 增加数据
        /// </summary>
        /// <param name="value">新增的数据</param>
        private void onInserted(valueType value)
        {
            int *intCounts = counts.Int;
            int  identity  = GetKey(value);

            if (identity >= size)
            {
                int newLength = int.MaxValue, oldLength = size;
                if ((identity & 0x40000000) == 0 && oldLength != 0x40000000)
                {
                    for (newLength = oldLength << 1; newLength <= identity; newLength <<= 1)
                    {
                        ;
                    }
                }
                values.ToSize(newLength);
                pointer.size newCounts = unmanaged.Get(newLength * sizeof(int), true);
                try
                {
                    unsafer.memory.Copy(intCounts, newCounts.Int, size * sizeof(int));
                    unmanaged.Free(ref counts);
                    counts = newCounts;
                    size   = newLength;
                    newCounts.Null();

                    int index = oldLength, count = (intCounts = counts.Int)[--index];
                    for (int step = 1; (index -= step) != 0; step <<= 1)
                    {
                        count += intCounts[index];
                    }
                    intCounts[oldLength] = count;
                }
                catch (Exception error)
                {
                    log.Error.Add(error, null, true);
                }
                finally
                {
                    unmanaged.Free(ref newCounts);
                }
            }
            valueType newValue = fastCSharp.emit.constructor <valueType> .New();

            fastCSharp.emit.memberCopyer <modelType> .Copy(newValue, value, memberMap);

            setMemberCacheAndValue(newValue);
            values[identity] = newValue;
            for (uint index = (uint)identity, countStep = 1, length = (uint)size; index <= length; countStep <<= 1)
            {
                ++intCounts[index];
                while ((index & countStep) == 0)
                {
                    countStep <<= 1;
                }
                index += countStep;
            }
            ++Count;
            callOnInserted(newValue);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 重新加载数据
        /// </summary>
        protected override void reset()
        {
            valueType[] values      = SqlTool.Where(null, memberMap).getArray();
            int         maxIdentity = values.maxKey(value => GetKey(value), 0);

            if (memberGroup == 0)
            {
                SqlTool.Identity64 = maxIdentity + baseIdentity;
            }
            int length = maxIdentity >= identityArray.ArraySize ? 1 << ((uint)maxIdentity).bits() : identityArray.ArraySize;
            identityArray <valueType> newValues = new identityArray <valueType>(length);

            pointer.size newCounts = unmanaged.Get(length * sizeof(int), true);
            try
            {
                int *intCounts = newCounts.Int;
                foreach (valueType value in values)
                {
                    setMemberCacheAndValue(value);
                    int identity = GetKey(value);
                    newValues[identity] = value;
                    intCounts[identity] = 1;
                }
                for (int step = 2; step != length; step <<= 1)
                {
                    for (int index = step, countStep = step >> 1; index != length; index += step)
                    {
                        intCounts[index] += intCounts[index - countStep];
                    }
                }
                unmanaged.Free(ref counts);
                this.values = newValues;
                counts      = newCounts;
                size        = length;
                Count       = values.Length;
                newCounts.Null();
            }
            catch (Exception error)
            {
                log.Error.Add(error, null, true);
            }
            finally
            {
                unmanaged.Free(ref newCounts);
            }
        }