/*
Helper function that creates a map that contains the order of nodes in a
particular layer.
192952
function dig_dot_layout_orderMap(g, layer) {
  var order = {};
  for (var i = 0; i < layer.length; ++i) {
    order[layer[i]] = i;
  }
  return order;
}
1075141
private static TreeMap<Double ,Set<String>> sortScoreMap(TreeMap<String, Double> scoreMap)
    {
        TreeMap<Double, Set<String>> result = new TreeMap<Double, Set<String>>(Collections.reverseOrder());
        for (Map.Entry<String, Double> entry : scoreMap.entrySet())
        {
            Set<String> sentenceSet = result.get(entry.getValue());
            if (sentenceSet == null)
            {
                sentenceSet = new HashSet<String>();
                result.put(entry.getValue(), sentenceSet);
            }
            sentenceSet.add(entry.getKey());
        }

        return result;
    }
430436
public static <K, V> Map<K, V> sortNumberMapByValueDescending(Map<K, V> map) {
        ArrayList<Map.Entry<K, V>> entries = new ArrayList<>(map.entrySet());
        Collections.sort(entries, (Map.Entry<K, V> a, Map.Entry<K, V> b) -> {
            Double va = TypeInference.toDouble(a.getValue());
            Double vb = TypeInference.toDouble(b.getValue());
            return -va.compareTo(vb);
        });
        
        Map<K, V> sortedMap = new LinkedHashMap<>();
        for (Map.Entry<K, V> entry : entries) {
          sortedMap.put(entry.getKey(), entry.getValue());
        }
        
        return sortedMap;
    }
360441
public Map<String, String> getSortedMap()
    {
        ImmutableSortedMap.Builder<String, String> builder = ImmutableSortedMap.naturalOrder();
        for ( FieldValue fv : fieldValues )
        {
            builder.put(fv.getField(), fv.getValue());
        }

        return builder.build();
    }
785941
private static <K, V> ImmutableMap<K, V> filterMapToKeysPreservingOrder(
      final ImmutableMap<? extends K, ? extends V> map, Iterable<? extends K> keys) {
    final ImmutableMap.Builder<K, V> ret = ImmutableMap.builder();
    for (final K key : keys) {
      final V value = map.get(key);
      checkArgument(value != null, "Key " + key + " not in map");
      ret.put(key, value);
    }
    return ret.build();
  }
713907
function ( srcs ) {
		return [
			/*
			 * Distribute foldernames and filenames in hashmaps.
			 */
			function step1 ( srcs ) {
				var map = Object.create ( null );
				function next ( source, parts, map ) {
					var part = parts.shift ();
					if ( !parts.length ) {
						map [ part ] = source;
					} else {
						map [ part ] = map [ part ] || Object.create ( null );
						next ( source, parts, map [ part ]);
					}
				}
				srcs.forEach ( function ( source ) {
					next ( source, source.split ( "/" ), map );
				});
				return map;
			},
			/*
			 * Transforming hashmaps into objects and arrays.
			 */
			function step2 ( map ) {
				var root = { name : "/", nodes : []};
				return ( function next ( map, parent, level ) {
					gui.Object.each ( map, function ( key, val ) {
						var node = { name : key };
						if ( typeof ( val ) === "object" ) {
							node.nodes = [];
							node.open = level < 1;
							next ( val, node, level + 1 );
						} else {
							node.src = val;
						}
						parent.nodes.push ( node );
					});
					return parent;
				}) ( map, root, 0 );
			},
			/*
			 * Split files from folders and sort them alphabetically.
			 */
			function step3 ( folder ) {
				var is, nodes = folder.nodes, alpha = function ( n1, n2 ) {
					return n1.name < n2.name ? -1 : n1.name > n2.name ? 1 : 0;
				};
				folder.nodes = nodes.filter ( function ( node ) {
					return (( is = node.nodes )) ? step3 ( node ) : false;
				}).sort ( alpha ).concat ( nodes.filter ( function ( node ) {
					return !node.nodes;
				}).sort ( alpha ));
				return folder;
			},
			/**
			 * Reduce to minimum viable root folder.
			 */
			function step4 ( folder ) {
				while ( folder.nodes.length === 1 && folder.nodes [ 0 ].nodes ) {
					//folder.hidden = true;
					folder = folder.nodes [ 0 ];
				}
				return folder;
			},
			/**
			 * Preoptimize search by stamping descendant filenames onto folders.
			 */
			function step5 ( folder ) {
				folder.filenames = folder.filenames || folder.nodes.map ( function ( node ) {
					return node.nodes ? step5 ( node ).filenames : node.name.toLowerCase ();
				}).join ( " " );
				return folder;
			}
		].reduce ( function ( input, nextstep ) { 
			return nextstep ( input ); 
		}, srcs );
	}
156363
private LinkedHashMap<HypergraphNode<Variable>, Integer> createInitialOrdering(final Formula formula, final Map<Variable, HypergraphNode<Variable>> nodes) {
    final LinkedHashMap<HypergraphNode<Variable>, Integer> initialOrdering = new LinkedHashMap<>();
    final List<Variable> dfsOrder = this.dfsOrdering.getOrder(formula);
    for (int i = 0; i < dfsOrder.size(); i++)
      initialOrdering.put(nodes.get(dfsOrder.get(i)), i);
    return initialOrdering;
  }
147888
function() {
        var layer;
        // walk through all map layers, because we want to keep the order
        for(var i=0; i<this.map.layers.length; ++i) {
            layer = this.map.layers[i];
            if(OpenLayers.Util.indexOf(this.layers, layer) != -1) {
                layer.renderer.moveRoot(this.renderer);
            }
        }
    }
907185
function(map) {

  var Fuzzymap = {};
  var Map = map;
  var PureMap = map;
  var LastValue = null;

  if(!_.isArray(map))
    Map = [Map]

  Fuzzymap.Map = function() { return PureMap; };
  Fuzzymap.last = function() { return LastValue; };
  Fuzzymap.keys = function() {
    return _.chain(Map)
      .compact()
      .map(function(mapDefinition) {
        return _.keys(mapDefinition);
      })
      .flatten()
      .uniq()
      .value();
  }

  Fuzzymap.map = function(item) {
    LastValue = item;
    
    if(_.isObject(item))
      testObject(item);
    else
      testItem(item);

    return Fuzzymap.last();
  };

  Fuzzymap.extract = function(item) {
    LastValue = item;

    if(!_.isObject)
      return item;

    return extractObject(item);
  };

  var extractObject = function(param) {
    var result = {};
    var defaults = {};
    _.each(Map, function(MapGroup) {
      _.each(_.keys(MapGroup), function(key) {
        if(!defaults.hasOwnProperty(key))
          defaults[key] = null;
      });
    });

    _.each(_.keys(param), function(key) {
      var mappedKey = testItem(key);
      if(defaults.hasOwnProperty(mappedKey))
        defaults[mappedKey] = param[key];
    });

    return defaults;
  };

  var testObject = function(param) {
    var result = {};
    _.each(_.keys(param), function(key) {
      var mappedKey = testItem(key);
      result[mappedKey] = param[key];
    });
    LastValue = result;
    
    return result;
  };

  var testItem = function(item) {
    LastValue = item;
    _.find(Map, function(MapGroup) {
      return testGroup(item, MapGroup) !== false;
    });

    return Fuzzymap.last();
  };
    
  var testGroup = function(item, MapGroup) {
    if(nil(MapGroup))
      MapGroup = {};

    var mapped = _.find(_.keys(MapGroup), function(mapString) {
      var regexes = MapGroup[mapString];

      if(!_.isArray(regexes))
        regexes = [regexes];

      var regex = _.find(regexes, function(regex) {
        return nil(item.match(regex)) === false;
      });
      
      return nil(regex) === false;
    });

    if(!nil(mapped))
      LastValue = mapped;
    
    return nil(mapped) === false;

  };

  return Fuzzymap;
}
972203
function sequence ( map, components, results, missing, recursive, nest ) {
  components.forEach( component => {
    if ( results.indexOf( component ) !== -1 ) {
      return; // de-dup results
    }

    const deps = map.get( component );

    if ( ! deps ) {
      missing.push( component );
    } else if ( nest.indexOf( component ) > -1 ) {
      nest.push( component );
      recursive.push( nest.slice(0) );
      nest.pop( component );
    } else if ( deps.length ) {
      nest.push( component );
      sequence( map, deps, results, missing, recursive, nest ); // recurse
      nest.pop( component );
    }
    results.push( component );
  });
}
369327
private void addElementsToSortOrderMap(final Element element, int baseSortOrder) {
        elementSortOrderMap.addElement(element, baseSortOrder);
        final List<Element> castToChildElementList = castToChildElementList(element);
        // Increments the sort order index for each element
        int sortOrder = baseSortOrder;
        for (Element child : castToChildElementList) {
            sortOrder += SORT_ORDER_INCREMENT;
            addElementsToSortOrderMap(child, sortOrder);
        }
    }
209801
def _sort_layers(self):
        """"""
        self._layers = OrderedDict(sorted(self._layers.items(), key=lambda t: t[0]))
994365
function graph(g) {
    init(g);

    var xs = [upperLeft(g), upperRight(g), lowerRight(g), lowerLeft(g)];

    g.nodes().forEach(function(u) {
      var xArray = [];
      for (var i = 0; i < xs.length; ++i) {
        xArray.push(xs[i][u]);
      }
      xArray.sort();
      g.node(u).x = (xArray[1] + xArray[2]) / 2;
    });
  }
700456
function(node) {
        var nodeId = node.id;
        var arrayIndex = OpenLayers.Util.indexOf(this.order, nodeId);
        if (arrayIndex >= 0) {
            // Remove it from the order array, as well as deleting the node
            // from the indeces hash.
            this.order.splice(arrayIndex, 1);
            delete this.indices[nodeId];
            
            // Reset the maxium z-index based on the last item in the 
            // order array.
            if (this.order.length > 0) {
                var lastId = this.order[this.order.length - 1];
                this.maxZIndex = this.indices[lastId];
            } else {
                this.maxZIndex = 0;
            }
        }
    }
825180
function map(array, fn) {
	const result = [];
	let length = array.length;
	while (length--) {
		result[length] = fn(array[length]);
	}
	return result;
}
701507
public Stream<T> orderedNodes() {
        TopoSorter<T> sorter = new TopoSorter<>(this);
        return sorter.result.stream();
    }
1370855
function(nodes) {
        var ans = [], config = this.config, root = this.viz.root;
        nodes.sort(function(a, b) { return (a._depth <= b._depth) - (a._depth >= b._depth); });
        for(var i=0; i<nodes.length; i++) {
            if(nodes[i].anySubnode("exist")) {
            	for (var j = i+1, desc = false; !desc && j < nodes.length; j++) {
                    if(!config.multitree || '$orn' in nodes[j].data) {
                		desc = desc || nodes[i].isDescendantOf(nodes[j].id);                    	
                    }
                }
                if(!desc) ans.push(nodes[i]);
            }
        }
        return ans;
    }