예제 #1
0
        public List <Mask2> Minus(Mask2 Other)
        {
            var builders = new List <StringBuilder>();

            builders.Add(new StringBuilder());

            for (var i = 0; i < MaskString.Length; i++)
            {
                if (MaskString[i] != 'X')
                {
                    if (MaskString[i] != Other.MaskString[i] && Other.MaskString[i] != 'X')
                    {
                        // If there is ever a bit they differ on, then the subtraction removes nothing
                        return(new List <Mask2>()
                        {
                            this
                        });
                    }
                    foreach (var builder in builders)
                    {
                        builder.Append(MaskString[i]);
                    }
                }
                else
                {
                    if (Other.MaskString[i] == 'X')
                    {
                        foreach (var builder in builders)
                        {
                            builder.Append('X');
                        }
                    }
                    else
                    {
                        for (var j = 0; j < builders.Count - 1; j++)
                        {
                            builders[j].Append('X');
                        }
                        builders.Add(new StringBuilder(builders[builders.Count - 1].ToString()));
                        builders[builders.Count - 2].Append(Other.MaskString[i] == '0' ? '1' : '0');
                        builders[builders.Count - 1].Append(Other.MaskString[i]);
                    }
                }
            }

            // Discard the last entry as the other always includes it
            builders.RemoveAt(builders.Count - 1);
            return(builders.Select(builder => new Mask2(builder.ToString())).ToList());
        }