Drills down into tree using the keys
775595
def _deep_value(*args, **kwargs):
    
    node, keys = args[0], args[1:]
    for key in keys:
        node = node.get(key, {})
    default = kwargs.get('default', {})
    if node in ({}, [], None):
        node = default
    return node
691974
function BinaryTree( options , ... elements ) {
	var autoIndex = 0 ;

	this.trunc = null ;
	this.length = 0 ;
	this.keyFn = options && options.keyFn ;
	this.uniqueKeys = !! ( options && options.uniqueKeys ) ;

	if ( ! this.keyFn ) {
		this.keyFn = ( element , hint ) => hint !== undefined ? hint : autoIndex ++ ;
	}

	if ( elements.length ) {
		this.insert( ... elements ) ;
	}
}
1108859
def snakeize_keys
      self.keys.each_with_index do |key, i|
        if key != key.underscore
          self.insert(i, key.underscore, self[key])
          self.delete(key)
        end
      end
      self
    end
284126
function bubble_up(i) {
    var p = parent(i);
    while (p >= 0 && tree[i][key] < tree[p][key]) {

      /* swap with parent */
      tree[i] = tree.splice(p, 1, tree[i])[0];

      /* go up one level */
      i = p;
      p = parent(i);
    }
  }
728030
def fill_tree(self, tree, input_dict):
        


        def removeAll(tree):

            if tree.model().rowCount() > 0:
                for i in range(0, tree.model().rowCount()):
                    item = tree.model().item(i)
                    del item
                    tree.model().removeRows(0, tree.model().rowCount())
                    tree.model().reset()

        def add_probe(tree, instrument, probes):
            item = QtGui.QStandardItem(instrument)
            item.setEditable(False)

            for probe in probes.split(','):
                child_name = QtGui.QStandardItem(probe)
                child_name.setDragEnabled(True)
                child_name.setSelectable(True)
                child_name.setEditable(False)
                item.appendRow(child_name)
            tree.model().appendRow(item)

        removeAll(tree)

        for index, (instrument, probes) in enumerate(input_dict.items()):
            add_probe(tree, instrument, probes)
            # tree.setFirstColumnSpanned(index, self.tree_infile.rootIndex(), True)
        tree.expandAll()
1014135
private void condenseTree(IndexTreePath<E> subtree, Stack<N> stack) {
    N node = getNode(subtree.getEntry());
    // node is not root
    if(!isRoot(node)) {
      N parent = getNode(subtree.getParentPath().getEntry());
      int index = subtree.getIndex();
      if(hasUnderflow(node)) {
        if(parent.deleteEntry(index)) {
          stack.push(node);
        }
        else {
          node.adjustEntry(parent.getEntry(index));
        }
      }
      else {
        node.adjustEntry(parent.getEntry(index));
      }
      writeNode(parent);
      // get subtree to parent
      condenseTree(subtree.getParentPath(), stack);
    }

    // node is root
    else {
      if(hasUnderflow(node) && node.getNumEntries() == 1 && !node.isLeaf()) {
        N child = getNode(node.getEntry(0));
        final N newRoot;
        if(child.isLeaf()) {
          newRoot = createNewLeafNode();
          newRoot.setPageID(getRootID());
          for(int i = 0; i < child.getNumEntries(); i++) {
            newRoot.addLeafEntry(child.getEntry(i));
          }
        }
        else {
          newRoot = createNewDirectoryNode();
          newRoot.setPageID(getRootID());
          for(int i = 0; i < child.getNumEntries(); i++) {
            newRoot.addDirectoryEntry(child.getEntry(i));
          }
        }
        writeNode(newRoot);
        height--;
      }
    }
  }
363401
def mock_key_down(self, target, key_press_times):
        
        key = Keys.DOWN
        if key_press_times < 0:
            key = Keys.UP

        for i in range(abs(key_press_times)):
            rand_block(0.1, 0.01)
            target.send_keys(key)
382157
private void forceDecreaseKeyToMinimum(Node<K, V> n) {
        // if not root
        Node<K, V> y = n.parent;
        if (y != null) {
            cut(n, y);
            cascadingCut(y);
        }
        minRoot = n;
    }
159397
def setKey(self, key):
		""""""
		key = self._guardAgainstUnicode(key)
		self.__key = key
955510
private static synchronized SmartForest<List<String>> init(String key, KV<String, SmartForest<List<String>>> kv,
                    boolean reload) {

        SmartForest<List<String>> forest = kv.getV();

        if (forest != null) {
            if (reload) {
                forest.clear();
            } else {
                return forest;
            }
        } else {
            forest = new SmartForest<>();
        }

        LOG.debug("begin init synonyms " + kv.getK());
        long start = System.currentTimeMillis();

        try (BufferedReader reader = IOUtil.getReader(PathToStream.stream(kv.getK()), IOUtil.UTF8)) {
            String temp = null;
            while ((temp = reader.readLine()) != null) {
                if (StringUtil.isBlank(temp)) {
                    continue;
                }
                String[] split = temp.split("\t");

                List<String> list = new ArrayList<>();
                for (String word : split) {
                    if (StringUtil.isBlank(word)) {
                        continue;
                    }
                    list.add(word);
                }

                if (split.length <= 1) {
                    LOG.warn(temp + " in synonymsLibrary not in to library !");
                    continue;
                }

                for (int i = 0; i < split.length; i++) {
                    forest.add(split[i], list);
                }
            }
            kv.setV(forest);
            LOG.info("load synonyms use time:" + (System.currentTimeMillis() - start) + " path is : " + kv.getK());
            return forest;
        } catch (Exception e) {
            LOG.error("Init synonyms library error :" + e.getMessage() + ", path: " + kv.getK());
            SYNONYMS.remove(key);
            return null;
        }
    }
690572
def copy_tree(src, dst):
    """"""
    for root, subdirs, files in os.walk(src):
        current_dest = root.replace(src, dst)
        if not os.path.exists(current_dest):
            os.makedirs(current_dest)
        for f in files:
            shutil.copy(os.path.join(root, f), os.path.join(current_dest, f))
332330
def hash_dig(hash, *keys)
      keys.inject(hash) { |res, key| res[key] or return nil }
    end
297555
function (node, key) {
  'use strict';
  var i, k;

  if (node.key === key) {
    return node;
  } else {
    for (i = 0; i < node.children.length; i += 1) {
      k = slow_findKey(node.children[i], key);
      if (k) {
        return k;
      }
    }
  }
}
485028
def get_near_items(tree, tree_key):
    
    try:
        yield tree.floor_item(tree_key)
    except KeyError:
        pass
    try:
        yield tree.ceiling_item(tree_key)
    except KeyError:
        pass
960128
function traverseTopDown(fn) {
    var result, i;
    result = fn.call(this);
    if(result)
        return result;
    if (this instanceof tree.ConsNode || this instanceof tree.ListNode) {
        for (i = 0; i < this.length; i++) {
            traverseTopDown.call(this[i], fn);
        }
    }
    return this;
}
838895
def nextKey(self, key):
        """"""
        ans = self.nextNode(key)
        return (ans.key
                if ans is not None
                else None)
936622
function() {
		var that = this,
			opts = this.options,
			tree = this.tree,
			ns = tree._ns
			// selstartEvent = ( $.support.selectstart ? "selectstart" : "mousedown" )
			;

		// Remove all previuous handlers for this tree
		this._unbind();

		//alert("keydown" + ns + "foc=" + tree.hasFocus() + tree.$container);
		// tree.debug("bind events; container: ", tree.$container);
		tree.$container.on("focusin" + ns + " focusout" + ns, function(event){
			var node = FT.getNode(event),
				flag = (event.type === "focusin");
			// tree.debug("Tree container got event " + event.type, node, event);
			// tree.treeOnFocusInOut.call(tree, event);
			if(node){
				// For example clicking into an <input> that is part of a node
				tree._callHook("nodeSetFocus", node, flag);
			}else{
				tree._callHook("treeSetFocus", tree, flag);
			}
		}).on("selectstart" + ns, "span.fancytree-title", function(event){
			// prevent mouse-drags to select text ranges
			// tree.debug("<span title> got event " + event.type);
			event.preventDefault();
		}).on("keydown" + ns, function(event){
			// TODO: also bind keyup and keypress
			// tree.debug("got event " + event.type + ", hasFocus:" + tree.hasFocus());
			// if(opts.disabled || opts.keyboard === false || !tree.hasFocus() ){
			if(opts.disabled || opts.keyboard === false ){
				return true;
			}
			var res,
				node = tree.focusNode, // node may be null
				ctx = tree._makeHookContext(node || tree, event),
				prevPhase = tree.phase;

			try {
				tree.phase = "userEvent";
				// If a 'fancytreekeydown' handler returns false, skip the default
				// handling (implemented by tree.nodeKeydown()).
				if(node){
					res = tree._triggerNodeEvent("keydown", node, event);
				}else{
					res = tree._triggerTreeEvent("keydown", event);
				}
				if ( res === "preventNav" ){
					res = true; // prevent keyboard navigation, but don't prevent default handling of embedded input controls
				} else if ( res !== false ){
					res = tree._callHook("nodeKeydown", ctx);
				}
				return res;
			} finally {
				tree.phase = prevPhase;
			}
		}).on("click" + ns + " dblclick" + ns, function(event){
			if(opts.disabled){
				return true;
			}
			var ctx,
				et = FT.getEventTarget(event),
				node = et.node,
				tree = that.tree,
				prevPhase = tree.phase;

			if( !node ){
				return true;  // Allow bubbling of other events
			}
			ctx = tree._makeHookContext(node, event);
//			that.tree.debug("event(" + event.type + "): node: ", node);
			try {
				tree.phase = "userEvent";
				switch(event.type) {
				case "click":
					ctx.targetType = et.type;
					return ( tree._triggerNodeEvent("click", ctx, event) === false ) ? false : tree._callHook("nodeClick", ctx);
				case "dblclick":
					ctx.targetType = et.type;
					return ( tree._triggerNodeEvent("dblclick", ctx, event) === false ) ? false : tree._callHook("nodeDblclick", ctx);
				}
//             } catch(e) {
// //                var _ = null; // DT issue 117 // TODO
//                 $.error(e);
			} finally {
				tree.phase = prevPhase;
			}
		});
	}