示例#1
0
        /**
         * decompress the data with stack-ZDPD algorithm
         *
         * @param layers compressed mzArray
         * @return decompressed mzArray
         */
        public static List <int[]> stackDecode(Layers layers)
        {
            int[]  stackArr   = CompressUtil.fastPforDecoder(CompressUtil.byteToInt(CompressUtil.zlibDecoder(layers.mzArray)));
            int[]  stackIndex = new int[stackArr.Length];
            byte[] tagShift   = CompressUtil.zlibDecoder(layers.tagArray);
            int    digit      = layers.digit;

            //拆分byte为8个bit,并分别存储
            byte[] value = new byte[8 * tagShift.Length];
            for (int i = 0; i < tagShift.Length; i++)
            {
                for (int j = 0; j < 8; j++)
                {
                    value[8 * i + j] = (byte)(((tagShift[i] & 0xff) >> j) & 1);
                }
            }
            //还原为int类型的index
            for (int i = 0; i < stackIndex.Length; i++)
            {
                for (int j = 0; j < digit; j++)
                {
                    stackIndex[i] += value[digit * i + j] << j;
                }
            }

            //统计index数组中各个元素出现的次数
            Hashtable table = new Hashtable();

            foreach (int index in stackIndex)
            {
                if (table.ContainsKey(index))
                {
                    table[index] = (int)table[index] + 1;
                }
                else
                {
                    table[index] = 1;
                }
            }

            //根据index拆分stackArr,还原数组
            List <int[]> arrGroup = new List <int[]>();
            int          arrNum   = table.Keys.Count;

            for (int i = 0; i < arrNum; i++)
            {
                arrGroup.Add(new int[(int)table[i]]);
            }
            int[] p = new int[arrNum];
            for (int i = 0; i < stackIndex.Length; i++)
            {
                arrGroup[stackIndex[i]][p[stackIndex[i]]++] = stackArr[i];
            }
            return(arrGroup);
        }
示例#2
0
        /**
         * compress the data with stack-ZDPD algorithm
         *
         * @param arrGroup mzArray to be compressed
         * @param pair sorting method of mzArray
         * @return compressed mzArray
         */
        public static Layers stackEncode(List <int[]> arrGroup, Boolean pair)
        {
            int stackLen = 0;  //记录堆叠数总长度

            foreach (int[] arr in arrGroup)
            {
                stackLen += arr.Length;
            }

            //合并排序数组 pair:默认采取pair成对排序,True也采取pair排序;false时采用QueueSort
            int[,] stackSort;
            stackSort = getPairSortArray(arrGroup);
            //if (pair)
            //{
            //    stackSort = getPairSortArray(arrGroup);
            //}
            //else
            //{
            //    stackSort = getQueueSortArray(arrGroup);
            //}
            //取出stack数组和index数组
            int[] stackArr   = new int[stackLen];
            int[] stackIndex = new int[stackLen];
            for (int i = 0; i < stackLen; i++)
            {
                stackArr[i]   = stackSort[i, 0];
                stackIndex[i] = stackSort[i, 1];
            }
            //index移位存储
            int digit    = (int)Math.Ceiling(Math.Log(arrGroup.Count) / Math.Log(2));
            int indexLen = (stackLen * digit - 1) / 8 + 1;

            byte[] value = new byte[8 * indexLen];
            for (int i = 0; i < stackLen; i++)
            {
                int fromIndex = digit * i;
                for (int j = 0; j < digit; j++)
                {
                    value[fromIndex + j] = (byte)((stackIndex[i] >> j) & 1);
                }
            }
            //把8个byte并为1个byte,用byte数组存是因为zlib压缩的是byte
            byte[] indexShift = new byte[indexLen];
            for (int i = 0; i < indexLen; i++)
            {
                int temp = 0;
                for (int j = 0; j < 8; j++)
                {
                    temp         += value[8 * i + j] << j;
                    indexShift[i] = (byte)temp;
                }
            }
            //数组用fastPFor压缩,index用zlib压缩,并记录层数
            Layers layers = new Layers();

            layers.mzArray  = CompressUtil.zlibEncoder(CompressUtil.intToByte(CompressUtil.fastPforEncoder(stackArr)));
            layers.tagArray = CompressUtil.zlibEncoder(indexShift);
            layers.digit    = digit;

            return(layers);
        }