コード例 #1
0
ファイル: Item.cs プロジェクト: jolhe006/managed-lzma
        public bool CheckStructure()
        {
            const int kNumCodersMax = 32; // don't change it
            const int kMaskSize = 32; // it must be >= kNumCodersMax
            const int kNumBindsMax = 32;

            if(Coders.Count > kNumCodersMax || BindPairs.Count > kNumBindsMax)
                return false;

            {
                var v = new BitVector(BindPairs.Count + PackStreams.Count);

                for(int i = 0; i < BindPairs.Count; i++)
                    if(v.GetAndSet(BindPairs[i].InIndex))
                        return false;

                for(int i = 0; i < PackStreams.Count; i++)
                    if(v.GetAndSet(PackStreams[i]))
                        return false;
            }

            {
                var v = new BitVector(UnpackSizes.Count);
                for(int i = 0; i < BindPairs.Count; i++)
                    if(v.GetAndSet(BindPairs[i].OutIndex))
                        return false;
            }

            uint[] mask = new uint[kMaskSize];

            {
                List<int> inStreamToCoder = new List<int>();
                List<int> outStreamToCoder = new List<int>();
                for(int i = 0; i < Coders.Count; i++)
                {
                    CCoderInfo coder = Coders[i];
                    for(int j = 0; j < coder.NumInStreams; j++)
                        inStreamToCoder.Add(i);
                    for(int j = 0; j < coder.NumOutStreams; j++)
                        outStreamToCoder.Add(i);
                }

                for(int i = 0; i < BindPairs.Count; i++)
                {
                    CBindPair bp = BindPairs[i];
                    mask[inStreamToCoder[bp.InIndex]] |= (1u << outStreamToCoder[bp.OutIndex]);
                }
            }

            for(int i = 0; i < kMaskSize; i++)
                for(int j = 0; j < kMaskSize; j++)
                    if(((1u << j) & mask[i]) != 0)
                        mask[i] |= mask[j];

            for(int i = 0; i < kMaskSize; i++)
                if(((1u << i) & mask[i]) != 0)
                    return false;

            return true;
        }
コード例 #2
0
        public bool CheckStructure()
        {
            const int kNumCodersMax = 32; // don't change it
            const int kMaskSize     = 32; // it must be >= kNumCodersMax
            const int kNumBindsMax  = 32;

            if (Coders.Count > kNumCodersMax || BindPairs.Count > kNumBindsMax)
            {
                return(false);
            }

            {
                var v = new BitVector(BindPairs.Count + PackStreams.Count);

                for (int i = 0; i < BindPairs.Count; i++)
                {
                    if (v.GetAndSet(BindPairs[i].InIndex))
                    {
                        return(false);
                    }
                }

                for (int i = 0; i < PackStreams.Count; i++)
                {
                    if (v.GetAndSet(PackStreams[i]))
                    {
                        return(false);
                    }
                }
            }

            {
                var v = new BitVector(UnpackSizes.Count);
                for (int i = 0; i < BindPairs.Count; i++)
                {
                    if (v.GetAndSet(BindPairs[i].OutIndex))
                    {
                        return(false);
                    }
                }
            }

            uint[] mask = new uint[kMaskSize];

            {
                List <int> inStreamToCoder  = new List <int>();
                List <int> outStreamToCoder = new List <int>();
                for (int i = 0; i < Coders.Count; i++)
                {
                    CCoderInfo coder = Coders[i];
                    for (int j = 0; j < coder.NumInStreams; j++)
                    {
                        inStreamToCoder.Add(i);
                    }
                    for (int j = 0; j < coder.NumOutStreams; j++)
                    {
                        outStreamToCoder.Add(i);
                    }
                }

                for (int i = 0; i < BindPairs.Count; i++)
                {
                    CBindPair bp = BindPairs[i];
                    mask[inStreamToCoder[bp.InIndex]] |= (1u << outStreamToCoder[bp.OutIndex]);
                }
            }

            for (int i = 0; i < kMaskSize; i++)
            {
                for (int j = 0; j < kMaskSize; j++)
                {
                    if (((1u << j) & mask[i]) != 0)
                    {
                        mask[i] |= mask[j];
                    }
                }
            }

            for (int i = 0; i < kMaskSize; i++)
            {
                if (((1u << i) & mask[i]) != 0)
                {
                    return(false);
                }
            }

            return(true);
        }