예제 #1
0
        public static List <BinNode> GraphBuildingOptimization(List <BinNode> input)
        {
            var output = new List <BinNode>();
            var mask   = new BinCode();
            int count  = Int32.MaxValue;

            while (input.Count > 0 && input.Count < count)
            {
                var level  = new List <BinNode>();
                var input2 = new List <BinNode>();
                var mask2  = new BinCode();
                count = input.Count;

                foreach (var elem in input)
                {
                    var parents2 = elem.parents - mask;
                    if (parents2.IsEmpty())
                    {
                        level.Add(elem);
                        mask2 += elem.val;
                    }
                    else
                    {
                        elem.parents = parents2;
                        input2.Add(elem);
                    }
                }

                output.AddRange(level);
                input = input2;
                mask  = mask2;
            }

            return(output);
        }
예제 #2
0
        private BinCode Subtract(BinCode hc2)
        {
            // x  y   x&!y
            // 0  0    0
            // 0  1    0
            // 1  0    1
            // 1  1    0

            var hc = new BinCode(this);

            if (hc2 != null && hc2.field != null)
            {
                foreach (var kv in hc2.field.Where(e => e.Value != 0))
                {
                    if (hc.field.ContainsKey(kv.Key))
                    {
                        hc.field[kv.Key] &= ~(kv.Value);

                        if (hc.field[kv.Key] == 0)
                        {
                            hc.field.Remove(kv.Key);
                        }
                    }
                }
            }
            return(hc);
        }
예제 #3
0
        public static BinCode operator !(BinCode hc2)
        {
            var hc   = new BinCode();
            int mask = 0xFF;

            if (hc2 != null && hc2.field != null)
            {
                hc.field = hc2.field.Where(e => (int)(e.Value ^ mask) != 0).ToDictionary(kv => kv.Key, kv => kv.Value ^ mask);
            }

            return(hc);
        }
예제 #4
0
        private BinCode Union(BinCode hc2)
        {
            BinCode hc = new BinCode(this);

            if (hc2 != null && hc2.field != null)
            {
                foreach (var kv in hc2.field.Where(e => e.Value != 0))
                {
                    if (!hc.field.ContainsKey(kv.Key))
                    {
                        hc.field.Add(kv.Key, kv.Value);
                    }
                    else
                    {
                        hc.field[kv.Key] |= kv.Value;
                    }
                }
            }
            return(hc);
        }
예제 #5
0
        public int CompareTo(object obj)
        {
            if (null == obj || obj.GetType() != typeof(BinCode))
            {
                return(1);
            }

            BinCode hc = (BinCode)obj;

            if (this.field == null && hc.field == null)
            {
                return(0);
            }
            else if (this.field == null || hc.field == null)
            {
                return(1);
            }
            else
            {
                foreach (var kv in this.field.Where(e => e.Value != 0))
                {
                    if (!hc.field.ContainsKey(kv.Key) || (int)(kv.Value ^ hc.field[kv.Key]) > 0)
                    {
                        return(1);
                    }
                }

                foreach (var kv in hc.field.Where(e => e.Value != 0))
                {
                    if (!this.field.ContainsKey(kv.Key) || (int)(kv.Value ^ this.field[kv.Key]) > 0)
                    {
                        return(1);
                    }
                }
            }

            return(0);
        }
예제 #6
0
 public BinNode(int index)
 {
     idx     = index;
     val     = new BinCode(idx);
     parents = new BinCode();
 }
예제 #7
0
 public BinCode(BinCode hc)
 {
     this.field = (hc != null && hc.field != null) ? hc.field.Where(e => e.Value != 0).ToDictionary(kv => kv.Key, kv => kv.Value) : new Dictionary <int, int>();
 }