Exemplo n.º 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);
         }
     }
 }
Exemplo n.º 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);
     }
 }