Esempio n. 1
0
        public void RemoveDependency(BitArray from, BitArray to)
        {
            if (from.Count != Keys.Count)
            {
                return;
            }
            if (to.Count != Keys.Count)
            {
                return;
            }
            to.And(Utils.Not(from));
            var index =
                DependencyList.FindIndex(tuple => tuple.Item1.EqualsTo(from));

            if (index == -1)
            {
                throw new ArgumentOutOfRangeException();
            }
            if (to.EqualsTo(DependencyList[index].Item2))
            {
                DependencyList.RemoveAt(index);
            }
            else
            {
                DependencyList[index].Item2.And(Utils.Not(to));
            }
            _prepared = false;
        }
Esempio n. 2
0
 private void Minimalize()
 {
     if (_prepared)
     {
         return;
     }
     while (true)
     {
         var change = false;
         for (var i = 0; i < DependencyList.Count; i++)
         {
             for (var j = 0; j < DependencyList.Count; j++)
             {
                 if (i == j)
                 {
                     continue;
                 }
                 if (!DependencyList[i].Item1.IsSuperSet(DependencyList[j].Item1))
                 {
                     continue;
                 }
                 foreach (var key in Keys.Where(key => DependencyList[j].Item2[key]))
                 {
                     change |= DependencyList[i].Item2[key] || DependencyList[i].Item1[key];
                     DependencyList[i].Item1.Set(key, false);
                     DependencyList[i].Item2.Set(key, false);
                 }
             }
         }
         if (!change)
         {
             break;
         }
         DependencyList.RemoveAll(dependency => !dependency.Item2.ToBitString().Contains('1'));
         for (var i = 0; i < DependencyList.Count; i++)
         {
             for (var j = i + 1; j < DependencyList.Count; j++)
             {
                 if (!DependencyList[i].Item1.EqualsTo(DependencyList[j].Item1))
                 {
                     continue;
                 }
                 DependencyList[i].Item2.Or(DependencyList[j].Item2);
                 DependencyList.RemoveAt(j);
                 j--;
             }
         }
     }
 }
Esempio n. 3
0
 public void RemoveKey(int index)
 {
     if (Keys.Count <= index)
     {
         return;
     }
     _prepared = false;
     Keys      = Enumerable.Range(0, Keys.Count - 1).ToList();
     foreach (var key in Keys.Where(key => CurrentPrimaryKey[key + (key >= index ? 1 : 0)]))
     {
         CurrentPrimaryKey[key] = true;
     }
     CurrentPrimaryKey.Length = Keys.Count;
     for (var i = 0; i < DependencyList.Count; i++)
     {
         if (DependencyList[i].Item1[index])
         {
             DependencyList.RemoveAt(i);
             i--;
             continue;
         }
         var newDependent   = new BitArray(Keys.Count);
         var newIndependent = new BitArray(Keys.Count);
         var foundDependent = false;
         foreach (var key in Keys)
         {
             if (DependencyList[i].Item1[key + (key >= index ? 1 : 0)])
             {
                 newIndependent[key] = true;
             }
             if (DependencyList[i].Item2[key + (key >= index ? 1 : 0)])
             {
                 newDependent[key] = foundDependent = true;
             }
         }
         if (!foundDependent)
         {
             DependencyList.RemoveAt(i);
             i--;
             continue;
         }
         DependencyList[i] = new Tuple <BitArray, BitArray>(newIndependent, newDependent);
     }
 }