/// <summary>Removes a resource for the specified interval</summary>
 /// <param name="reservationInterval">
 /// the interval for which the resource is to be
 /// removed
 /// </param>
 /// <param name="capacity">the resource to be removed</param>
 /// <returns>true if removal is successful, false otherwise</returns>
 public virtual bool RemoveInterval(ReservationInterval reservationInterval, ReservationRequest
                                    capacity)
 {
     Org.Apache.Hadoop.Yarn.Api.Records.Resource totCap = Resources.Multiply(capacity.
                                                                             GetCapability(), (float)capacity.GetNumContainers());
     if (totCap.Equals(ZeroResource))
     {
         return(true);
     }
     writeLock.Lock();
     try
     {
         long startKey = reservationInterval.GetStartTime();
         long endKey   = reservationInterval.GetEndTime();
         // update the start key
         NavigableMap <long, Org.Apache.Hadoop.Yarn.Api.Records.Resource> ticks = cumulativeCapacity
                                                                                  .HeadMap(endKey, false);
         // Decrease all the capacities of overlapping intervals
         SortedDictionary <long, Org.Apache.Hadoop.Yarn.Api.Records.Resource> overlapSet =
             ticks.TailMap(startKey);
         if (overlapSet != null && !overlapSet.IsEmpty())
         {
             Org.Apache.Hadoop.Yarn.Api.Records.Resource updatedCapacity = Org.Apache.Hadoop.Yarn.Api.Records.Resource
                                                                           .NewInstance(0, 0);
             long currentKey = -1;
             for (IEnumerator <KeyValuePair <long, Org.Apache.Hadoop.Yarn.Api.Records.Resource> >
                  overlapEntries = overlapSet.GetEnumerator(); overlapEntries.HasNext();)
             {
                 KeyValuePair <long, Org.Apache.Hadoop.Yarn.Api.Records.Resource> entry = overlapEntries
                                                                                          .Next();
                 currentKey      = entry.Key;
                 updatedCapacity = Resources.Subtract(entry.Value, totCap);
                 // update each entry between start and end key
                 cumulativeCapacity[currentKey] = updatedCapacity;
             }
             // Remove the first overlap entry if it is same as previous after
             // updation
             long firstKey = overlapSet.FirstKey();
             if (IsSameAsPrevious(firstKey, overlapSet[firstKey]))
             {
                 Sharpen.Collections.Remove(cumulativeCapacity, firstKey);
             }
             // Remove the next entry if it is same as end entry after updation
             if ((currentKey != -1) && (IsSameAsNext(currentKey, updatedCapacity)))
             {
                 Sharpen.Collections.Remove(cumulativeCapacity, cumulativeCapacity.HigherKey(currentKey
                                                                                             ));
             }
         }
         return(true);
     }
     finally
     {
         writeLock.Unlock();
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Construct an
 /// <see cref="System.Collections.IEnumerable{T}"/>
 /// object,
 /// so that an
 /// <see cref="System.Collections.IEnumerator{E}"/>
 /// can be created
 /// for iterating the given
 /// <see cref="Sharpen.NavigableMap{K, V}"/>
 /// .
 /// The iteration begins from the starting key exclusively.
 /// </summary>
 public CyclicIteration(NavigableMap <K, V> navigablemap, K startingkey)
 {
     if (navigablemap == null || navigablemap.IsEmpty())
     {
         this.navigablemap = null;
         this.tailmap      = null;
     }
     else
     {
         this.navigablemap = navigablemap;
         this.tailmap      = navigablemap.TailMap(startingkey, false);
     }
 }
Ejemplo n.º 3
0
    public override void _Ready()
    {
        levelMap = this.FindParentOfType <NavigableMap>(true);
        if (levelMap != null)
        {
            Rect2   rect     = levelMap.GetUsedRect();
            Vector2 position = rect.Position * levelMap.CellSize;
            Vector2 end      = rect.End * levelMap.CellSize;
            GD.Print($"Positon: {position}, End: {end}");

            LimitLeft   = (int)position.x;
            LimitTop    = (int)position.y;
            LimitRight  = (int)end.x;
            LimitBottom = (int)end.y;

            GD.Print($"Left: {LimitLeft}, Right: {LimitRight}, Top: {LimitTop}, Bottom: {LimitBottom}");
        }
    }
Ejemplo n.º 4
0
 private void readObject(java.io.ObjectInputStream stream)
 {//throws IOException,ClassNotFoundException
     {
         stream.defaultReadObject();
         TreeMap <E, Object> map = new TreeMap <E, Object>(
             (Comparator <E>)stream.readObject());
         int size = stream.readInt();
         if (size > 0)
         {
             TreeMap <E, Object> .Node <E, Object> lastNode = null;
             for (int i = 0; i < size; i++)
             {
                 E elem = (E)stream.readObject();
                 lastNode = map.addToLast(lastNode, elem, java.lang.Boolean.TRUE);
             }
         }
         backingMap = map;
     }
 }
Ejemplo n.º 5
0
        /// <summary>Cursor-based listing of encryption zones.</summary>
        /// <remarks>
        /// Cursor-based listing of encryption zones.
        /// <p/>
        /// Called while holding the FSDirectory lock.
        /// </remarks>
        /// <exception cref="System.IO.IOException"/>
        internal virtual BatchedRemoteIterator.BatchedListEntries <EncryptionZone> ListEncryptionZones
            (long prevId)
        {
            System.Diagnostics.Debug.Assert(dir.HasReadLock());
            NavigableMap <long, EncryptionZoneManager.EncryptionZoneInt> tailMap = encryptionZones
                                                                                   .TailMap(prevId, false);
            int numResponses             = Math.Min(maxListEncryptionZonesResponses, tailMap.Count);
            IList <EncryptionZone> zones = Lists.NewArrayListWithExpectedSize(numResponses);
            int count = 0;

            foreach (EncryptionZoneManager.EncryptionZoneInt ezi in tailMap.Values)
            {
                /*
                 * Skip EZs that are only present in snapshots. Re-resolve the path to
                 * see if the path's current inode ID matches EZ map's INode ID.
                 *
                 * INode#getFullPathName simply calls getParent recursively, so will return
                 * the INode's parents at the time it was snapshotted. It will not
                 * contain a reference INode.
                 */
                string       pathName  = GetFullPathName(ezi);
                INodesInPath iip       = dir.GetINodesInPath(pathName, false);
                INode        lastINode = iip.GetLastINode();
                if (lastINode == null || lastINode.GetId() != ezi.GetINodeId())
                {
                    continue;
                }
                // Add the EZ to the result list
                zones.AddItem(new EncryptionZone(ezi.GetINodeId(), pathName, ezi.GetSuite(), ezi.
                                                 GetVersion(), ezi.GetKeyName()));
                count++;
                if (count >= numResponses)
                {
                    break;
                }
            }
            bool hasMore = (numResponses < tailMap.Count);

            return(new BatchedRemoteIterator.BatchedListEntries <EncryptionZone>(zones, hasMore
                                                                                 ));
        }
Ejemplo n.º 6
0
 /*
  * Constructs a new empty instance of {@code TreeSet} which uses the
  * specified comparator.
  *
  * @param comparator
  *            the comparator to use.
  */
 public TreeSet(Comparator <E> comparator)
 {
     backingMap = new TreeMap <E, Object>(comparator);
 }
Ejemplo n.º 7
0
 /*
  * Constructs a new empty instance of {@code TreeSet} which uses natural
  * ordering.
  */
 public TreeSet()
 {
     backingMap = new TreeMap <E, Object>();
 }
Ejemplo n.º 8
0
 TreeSet(NavigableMap <E, Object> map)
 {
     backingMap = map;
 }
 /// <summary>Add a resource for the specified interval</summary>
 /// <param name="reservationInterval">
 /// the interval for which the resource is to be
 /// added
 /// </param>
 /// <param name="capacity">the resource to be added</param>
 /// <returns>true if addition is successful, false otherwise</returns>
 public virtual bool AddInterval(ReservationInterval reservationInterval, ReservationRequest
                                 capacity)
 {
     Org.Apache.Hadoop.Yarn.Api.Records.Resource totCap = Resources.Multiply(capacity.
                                                                             GetCapability(), (float)capacity.GetNumContainers());
     if (totCap.Equals(ZeroResource))
     {
         return(true);
     }
     writeLock.Lock();
     try
     {
         long startKey = reservationInterval.GetStartTime();
         long endKey   = reservationInterval.GetEndTime();
         NavigableMap <long, Org.Apache.Hadoop.Yarn.Api.Records.Resource> ticks = cumulativeCapacity
                                                                                  .HeadMap(endKey, false);
         if (ticks != null && !ticks.IsEmpty())
         {
             Org.Apache.Hadoop.Yarn.Api.Records.Resource updatedCapacity = Org.Apache.Hadoop.Yarn.Api.Records.Resource
                                                                           .NewInstance(0, 0);
             KeyValuePair <long, Org.Apache.Hadoop.Yarn.Api.Records.Resource> lowEntry = ticks.
                                                                                         FloorEntry(startKey);
             if (lowEntry == null)
             {
                 // This is the earliest starting interval
                 cumulativeCapacity[startKey] = totCap;
             }
             else
             {
                 updatedCapacity = Resources.Add(lowEntry.Value, totCap);
                 // Add a new tick only if the updated value is different
                 // from the previous tick
                 if ((startKey == lowEntry.Key) && (IsSameAsPrevious(lowEntry.Key, updatedCapacity
                                                                     )))
                 {
                     Sharpen.Collections.Remove(cumulativeCapacity, lowEntry.Key);
                 }
                 else
                 {
                     cumulativeCapacity[startKey] = updatedCapacity;
                 }
             }
             // Increase all the capacities of overlapping intervals
             ICollection <KeyValuePair <long, Org.Apache.Hadoop.Yarn.Api.Records.Resource> > overlapSet
                 = ticks.TailMap(startKey, false);
             foreach (KeyValuePair <long, Org.Apache.Hadoop.Yarn.Api.Records.Resource> entry in
                      overlapSet)
             {
                 updatedCapacity = Resources.Add(entry.Value, totCap);
                 entry.SetValue(updatedCapacity);
             }
         }
         else
         {
             // This is the first interval to be added
             cumulativeCapacity[startKey] = totCap;
         }
         Org.Apache.Hadoop.Yarn.Api.Records.Resource nextTick = cumulativeCapacity[endKey];
         if (nextTick != null)
         {
             // If there is overlap, remove the duplicate entry
             if (IsSameAsPrevious(endKey, nextTick))
             {
                 Sharpen.Collections.Remove(cumulativeCapacity, endKey);
             }
         }
         else
         {
             // Decrease capacity as this is end of the interval
             cumulativeCapacity[endKey] = Resources.Subtract(cumulativeCapacity.FloorEntry(endKey
                                                                                           ).Value, totCap);
         }
         return(true);
     }
     finally
     {
         writeLock.Unlock();
     }
 }
Ejemplo n.º 10
0
    public override void _Ready()
    {
        currentMap = this.FindChildrenOfType <NavigableMap>().FirstOrDefault();

        Ready?.Invoke();
    }
Ejemplo n.º 11
0
 /// <summary>
 /// Constructs a set backed by the specified navigable map.
 /// </summary>
 internal TreeSet(NavigableMap <E, Object> m)
 {
     this.m = m;
 }