示例#1
0
 private bool Delete(Computed dependent)
 {
     lock (this)
     {
         if (_computedArray != null)
         {
             WeakArray.Remove(ref _computedArray, dependent);
             return(_computedArray == null);
         }
         else if (_computedHash != null)
         {
             _computedHash.Remove(dependent);
             if (_computedHash.Count == 0)
             {
                 _computedHash = null;
                 return(true);
             }
             return(false);
         }
         else
         {
             return(false);
         }
     }
 }
示例#2
0
 private bool Insert(Computed update)
 {
     lock (this)
     {
         if (_computedHash != null)
         {
             _computedHash.Add(update);
             return(false);
         }
         if (WeakArray.Contains(ref _computedArray, update))
         {
             return(false);
         }
         bool first = _computedArray == null;
         if (WeakArray.GetCount(ref _computedArray) >= _maxArraySize)
         {
             _computedHash = new WeakHashSet <Computed>();
             foreach (var item in WeakArray.Enumerate <Computed>(_computedArray))
             {
                 _computedHash.Add(item);
             }
             _computedArray = null;
             _computedHash.Add(update);
             return(false);
         }
         WeakArray.Add(ref _computedArray, update);
         return(first);
     }
 }
示例#3
0
 /// <summary>
 /// Makes all direct and indirect dependents out of date.
 /// </summary>
 internal void MakeDependentsOutOfDate()
 {
     if (_computedArray != null)
     {
         foreach (var computed in WeakArray.Enumerate <Computed>(_computedArray).ToList())
         {
             computed.MakeOutOfDate();
         }
     }
     else if (_computedHash != null)
     {
         foreach (var computed in _computedHash.ToList())
         {
             computed.MakeOutOfDate();
         }
     }
 }
示例#4
0
 private bool Contains(Computed update)
 {
     lock (this)
     {
         if (_computedArray != null)
         {
             return(WeakArray.Contains(ref _computedArray, update));
         }
         else if (_computedHash != null)
         {
             return(_computedHash.Contains(update));
         }
         else
         {
             return(false);
         }
     }
 }