@Override public NodeAndSlotCounts getNodeAndSlotCountIfSlotsWereTaken(int slotsNeeded) { int slotsFound = 0; int nodesFound = 0; Iterator<Node> it = _nodes.iterator(); while (it.hasNext() && slotsNeeded > 0) { Node n = it.next(); nodesFound++; int totalSlots = n.totalSlots(); slotsFound += totalSlots; slotsNeeded -= totalSlots; } return new NodeAndSlotCounts(nodesFound, slotsFound); }
@Override public NodeAndSlotCounts getNodeAndSlotCountIfSlotsWereTaken(int slotsNeeded) { int nodesFound = 0; int slotsFound = 0; for (Entry<String, Set<Node>> entry : _topologyIdToNodes.entrySet()) { if (!_isolated.contains(entry.getKey())) { for (Node n : entry.getValue()) { if (n.isAlive()) { nodesFound++; int totalSlotsFree = n.totalSlots(); slotsFound += totalSlotsFree; slotsNeeded -= totalSlotsFree; if (slotsNeeded <= 0) { return new NodeAndSlotCounts(nodesFound, slotsFound); } } } } } return new NodeAndSlotCounts(nodesFound, slotsFound); }
@Override public NodeAndSlotCounts getNodeAndSlotCountIfSlotsWereTaken(int slotsNeeded) { int nodesFound = 0; int slotsFound = 0; LinkedList<Node> sortedNodes = new LinkedList<>(_nodes); Collections.sort(sortedNodes, Node.FREE_NODE_COMPARATOR_DEC); for (Node n : sortedNodes) { if (slotsNeeded <= 0) { break; } if (n.isAlive()) { nodesFound++; int totalSlotsFree = n.totalSlots(); slotsFound += totalSlotsFree; slotsNeeded -= totalSlotsFree; } } return new NodeAndSlotCounts(nodesFound, slotsFound); }
@Override public NodeAndSlotCounts getNodeAndSlotCountIfSlotsWereTaken(int slotsNeeded) { int nodesFound = 0; int slotsFound = 0; for (Entry<String, Set<Node>> entry: _topologyIdToNodes.entrySet()) { if (!_isolated.contains(entry.getKey())) { for (Node n : entry.getValue()) { if (n.isAlive()) { nodesFound++; int totalSlotsFree = n.totalSlots(); slotsFound += totalSlotsFree; slotsNeeded -= totalSlotsFree; if (slotsNeeded <= 0) { return new NodeAndSlotCounts(nodesFound, slotsFound); } } } } } return new NodeAndSlotCounts(nodesFound, slotsFound); }
@Override public NodeAndSlotCounts getNodeAndSlotCountIfSlotsWereTaken(int slotsNeeded) { int nodesFound = 0; int slotsFound = 0; LinkedList<Node> sortedNodes = new LinkedList<>(_nodes); Collections.sort(sortedNodes, Node.FREE_NODE_COMPARATOR_DEC); for (Node n: sortedNodes) { if (slotsNeeded <= 0) { break; } if (n.isAlive()) { nodesFound++; int totalSlotsFree = n.totalSlots(); slotsFound += totalSlotsFree; slotsNeeded -= totalSlotsFree; } } return new NodeAndSlotCounts(nodesFound, slotsFound); }
@Override public NodeAndSlotCounts getNodeAndSlotCountIfSlotsWereTaken(int slotsNeeded) { int slotsFound = 0; int nodesFound = 0; Iterator<Node> it = _nodes.iterator(); while (it.hasNext() && slotsNeeded > 0) { Node n = it.next(); nodesFound++; int totalSlots = n.totalSlots(); slotsFound += totalSlots; slotsNeeded -= totalSlots; } return new NodeAndSlotCounts(nodesFound, slotsFound); }