コード例 #1
0
ファイル: StorageList.cs プロジェクト: kr1992/PhantasmaChain
        public static void RemoveAt <T>(this StorageList list, BigInteger index)
        {
            var size = list.Count();

            if (index < 0 || index >= size)
            {
                throw new StorageException("outside of range");
            }

            var indexKey = ElementKey(list.BaseKey, index);

            size = size - 1;

            if (size > index)
            {
                // TODO <T> would not really be necessary here, this swap could be improved by using byte[]
                var last = list.Get <T>(size);
                list.Replace(index, last);
            }

            var key = ElementKey(list.BaseKey, size);

            list.Context.Delete(key);

            list.Context.Put(CountKey(list.BaseKey), size);
        }
コード例 #2
0
ファイル: StorageList.cs プロジェクト: kr1992/PhantasmaChain
        public static T[] All <T>(this StorageList list)
        {
            var size  = list.Count();
            var items = new T[(int)size];

            for (int i = 0; i < size; i++)
            {
                items[i] = list.Get <T>(i);
            }
            return(items);
        }
コード例 #3
0
ファイル: StorageList.cs プロジェクト: kr1992/PhantasmaChain
        public static BigInteger IndexOf <T>(this StorageList list, T obj)
        {
            BigInteger index = 0;
            var        size  = list.Count();

            while (index < size)
            {
                var val = list.Get <T>(index);
                if (val.Equals(obj))
                {
                    return(index);
                }
                index++;
            }

            return(-1);
        }
コード例 #4
0
ファイル: StorageList.cs プロジェクト: kr1992/PhantasmaChain
        public static T[] Range <T>(this StorageList list, BigInteger minIndex, BigInteger maxIndex)
        {
            if (minIndex > maxIndex)
            {
                throw new StorageException("outside of range");
            }

            int total = 1 + (int)(maxIndex - minIndex);

            var result = new T[total];

            int        offset = 0;
            BigInteger index  = minIndex;

            while (offset < total)
            {
                result[offset] = list.Get <T>(index);
                offset         = offset + 1;
                index++;
            }

            return(result);
        }