Get an array of nodes that can serve the streaming request
The best one is the first in the array which has maximum
local copies of all blocks
349779
public DatanodeInfo[] bestNode(LocatedBlocks blks) throws IOException {
    // insert all known replica locations into a tree map where the
    // key is the DatanodeInfo
    TreeMap<DatanodeInfo, NodeRecord> map = 
      new TreeMap<DatanodeInfo, NodeRecord>();
    for (int i = 0; i < blks.getLocatedBlocks().size(); i++) {
      DatanodeInfo [] nodes = blks.get(i).getLocations();
      for (int j = 0; j < nodes.length; j++) {
        NodeRecord obj = map.get(nodes[j]);
        if (obj != null) {
          obj.frequency++;
        } else {
          map.put(nodes[j], new NodeRecord(nodes[j], 1));
        }
      }
    }
    // sort all locations by their frequency of occurance
    Collection<NodeRecord> values = map.values();
    NodeRecord[] nodes = (NodeRecord[]) 
                         values.toArray(new NodeRecord[values.size()]);
    Arrays.sort(nodes, new NodeRecordComparator());
    try {
      List<NodeRecord> candidates = bestNode(nodes, false);
      return candidates.toArray(new DatanodeInfo[candidates.size()]);
    } catch (IOException e) {
      return new DatanodeInfo[] {randomNode()};
    }
  }
229061
def list_nodes_full(call=None, for_output=True):
    '''
    
    '''
    if call == 'action':
        raise SaltCloudSystemExit(
            'The list_nodes_full function must be called with -f or --function.'
        )
    creds = get_creds()
    clc.v1.SetCredentials(creds["token"], creds["token_pass"])
    servers_raw = clc.v1.Server.GetServers(location=None)
    servers_raw = salt.utils.json.dumps(servers_raw)
    servers = salt.utils.json.loads(servers_raw)
    return servers
874593
function nodeCopy(a)
{
	var newA = {
		ctor: '_Array',
		height: a.height,
		table: a.table.slice()
	};
	if (a.height > 0)
	{
		newA.lengths = a.lengths.slice();
	}
	return newA;
}
1125628
def fetch_block(block_size=nil)
      block_size ||= @block_size ||= @options.fetch(:block_size) { 1000 }
      @result = @connection.execute("fetch #{block_size} from cursor_#{@cursor}")

      if @iterate == :each_array
        @block = @result.each_row.collect {|row| row }
      else
        @block = @result.collect {|row| row }
      end
    end
614959
def nodes_az(c_obj):
    """"""
    az_nodes = []
    try:
        az_nodes = c_obj.list_nodes()
    except BaseHTTPError as e:
        abort_err("\r HTTP Error with Azure: {}".format(e))
    az_nodes = adj_nodes_az(az_nodes)
    return az_nodes
744712
function getBlockNodes(nodes) {
  // TODO(perf): just check if all items in `nodes` are siblings and if they are return the original
  //             collection, otherwise update the original collection.
  var node = nodes[0];
  var endNode = nodes[nodes.length - 1];
  var blockNodes = [node];

  do {
    node = node.nextSibling;
    if (!node) break;
    blockNodes.push(node);
  } while (node !== endNode);

  return jqLite(blockNodes);
}
73223
private Block[] allocateParityBlocks(int numParityBlocks) throws IOException {
    Block[] blocks = new Block[numParityBlocks];
    for (int i = 0; i < numParityBlocks; i++) {
      Block b = new Block(generateBlockId(), 0, 0);
      while (isValidBlock(b)) {
        b.setBlockId(generateBlockId());
      }
      b.setGenerationStamp(getGenerationStamp());
      blocks[i] = b;
    }
    return blocks;
  }
1341748
@Override
	public Endpoint next(Endpoint[] array) {

		// Minimum values
		long minCPU = Long.MAX_VALUE;
		Endpoint minEndpoint = null;

		// Processing variables
		Endpoint endpoint;
		int cpu;

		// Find the lower CPU usage in sample
		for (int i = 0; i < maxTries; i++) {

			// Get random endpoint
			endpoint = super.next(array);

			// Check CPU usage
			cpu = transporter.getCpuUsage(endpoint.getNodeID());
			if (cpu <= lowCpuUsage) {
				return endpoint;
			}
			if (minEndpoint == null || cpu < minCPU) {
				minCPU = cpu;
				minEndpoint = endpoint;
			}
		}
		return minEndpoint;
	}
1171464
function(array, nodesToMove,
                                                   insertDepth) {
    var firstNode = array.length - 2;
    var nextNode = array.length - 1;
    var currentDepth = (insertDepth == 1) ? 2 : 1;
    var nodesLeftToMove = (insertDepth == 1) ? nodesToMove - 2 : nodesToMove;
    var availableNodes, lastNode, offset, i;

    for (availableNodes = currentDepth << 1;
         availableNodes > 0;
         currentDepth++) {
      lastNode = firstNode;
      firstNode = (firstNode <= nodesToMove) ? firstNode : first (array, lastNode - 1, nodesToMove);

      offset = 0;
      if (currentDepth >= insertDepth) {
        offset = Math.min (nodesLeftToMove, 1 << (currentDepth - insertDepth));
      } else if (currentDepth == (insertDepth - 1)) {
        offset = 1;
        if ((array[firstNode]) == lastNode) {
          firstNode++;
        }
      }

      for (i = availableNodes - (lastNode - firstNode + offset); i > 0; i--) {
        array[nextNode--] = currentDepth;
      }

      nodesLeftToMove -= offset;
      availableNodes = (lastNode - firstNode + offset) << 1;
    }
  }
100791
function ChunkedStreamManager_requestRange(
                      begin, end, callback) {

      end = Math.min(end, this.length);

      var beginChunk = this.getBeginChunk(begin);
      var endChunk = this.getEndChunk(end);

      var chunks = [];
      for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
        chunks.push(chunk);
      }

      this.requestChunks(chunks, callback);
    }
940793
function() {
    var withBlock = this.accept('+');
    if ('url' == this.peek().val.name) return this.url();
    var name = this.expect('function').val.name;
    this.state.push('function arguments');
    this.parens++;
    var args = this.args();
    this.expect(')');
    this.parens--;
    this.state.pop();
    var call = new nodes.Call(name, args);
    if (withBlock) {
      this.state.push('function');
      call.block = this.block(call);
      this.state.pop();
    }
    return call;
  }
1227321
private boolean getGoodNode(
      HashMap<String, HashSet<Node>> candidateNodesByRacks,
      boolean considerLoad,
      long blockSize,
      List<DatanodeDescriptor> results) {
    List<Map.Entry<String, HashSet<Node>>> sorted =
      new ArrayList<Map.Entry<String, HashSet<Node>>>();
    for (Map.Entry<String, HashSet<Node>> entry :
           candidateNodesByRacks.entrySet()) {
      sorted.add(entry);
    }
    Collections.sort(sorted, new RackComparator(blockSize));
    int count = sorted.size() / 4;
    Collections.shuffle(sorted.subList(0, count));
    for (Map.Entry<String, HashSet<Node>> e : sorted) {
      if (getGoodNode(e.getValue(), considerLoad, blockSize, results)) {
        return true;
      }
    }
    return false;
  }
572974
function nodesToArray(nodes) {
    if (!nodes || nodes.length === 0) {
        return false;
    } else {
        return nodes.length ? [].slice.call(nodes) : [nodes];
    }
}
106625
def get_stream(path, response_block, params = nil, headers = {}, auth = true)
      request(path: path, query: params, headers: headers, response_block: response_block, auth: auth, gzip: false)
    end
757048
function collectUniqNodes(list, func) {
    var result = [];
    var nodeIds = {};
    var currentNodeId;

    flexiEach(list, function(value) {
      flexiEach(func(value), function(node) {
        if (!nodeIds[currentNodeId = getNodeId(node)]) {
          result.push(node);
          nodeIds[currentNodeId] = true;
        }
      });
    });
    return result;
  }
253640
public static <E> Stream<E> stream(JsArrayLike<E> nodes) {
        if (nodes == null) {
            return Stream.empty();
        } else {
            return StreamSupport.stream(spliteratorUnknownSize(iterator(nodes), 0), false);
        }
    }
417000
def top(self):
        
        nodes = []
        for node in self.nodes():
            nodes.append(self.http_client.get(API_TOP % node['name']))
        return nodes