Creation of balanced lists for "up" branch and "down" branch.
180379
def print_tree(current_node, childattr='children', nameattr='name', indent='', last='updown'):

    if hasattr(current_node, nameattr):
        name = lambda node: getattr(node, nameattr)
    else:
        name = lambda node: str(node)

    children = lambda node: getattr(node, childattr)
    nb_children = lambda node: sum(nb_children(child) for child in children(node)) + 1
    size_branch = {child: nb_children(child) for child in children(current_node)}

    
    up = sorted(children(current_node), key=lambda node: nb_children(node))
    down = []
    while up and sum(size_branch[node] for node in down) < sum(size_branch[node] for node in up):
        down.append(up.pop())

    """ Printing of "up" branch. """
    for child in up:     
        next_last = 'up' if up.index(child) is 0 else ''
        next_indent = '{0}{1}{2}'.format(indent, ' ' if 'up' in last else '│', ' ' * len(name(current_node)))
        print_tree(child, childattr, nameattr, next_indent, next_last)

    """ Printing of current node. """
    if last == 'up': start_shape = '┌'
    elif last == 'down': start_shape = '└'
    elif last == 'updown': start_shape = ' '
    else: start_shape = '├'

    if up: end_shape = '┤'
    elif down: end_shape = '┐'
    else: end_shape = ''

    print('{0}{1}{2}{3}'.format(indent, start_shape, name(current_node), end_shape))

    """ Printing of "down" branch. """
    for child in down:
        next_last = 'down' if down.index(child) is len(down) - 1 else ''
        next_indent = '{0}{1}{2}'.format(indent, ' ' if 'down' in last else '│', ' ' * len(name(current_node)))
        print_tree(child, childattr, nameattr, next_indent, next_last)
1012515
def balancedSlicer(text, openDelim='[', closeDelim=']'):
    
    openbr = 0
    cur = 0
    for char in text:
        cur +=1
        if char == openDelim:
            openbr += 1
        if char == closeDelim:
            openbr -= 1
        if openbr == 0:
            break
    return text[:cur], cur
1243569
function balance(a, b){
  var diff = a.length - b.length
  var short = diff >= 0 ? b : a
  diff = Math.abs(diff)
  while (diff--) short.push(['c',0,0,0,0,0,0])
  return [a, b]
}
137152
def __sort_up(self):

        """"""
        if self.__do_need_sort_up:
            self.__up_objects.sort(key=cmp_to_key(self.__up_cmp))
            self.__do_need_sort_up = False
1206295
def p_lconcatlist(self, p):
        ''
        p[0] = p[1] + (p[3],)
        p.set_lineno(0, p.lineno(1))
494246
def balance(self):
        """"""
        if len(self.records) > len(self._shapes):
            self.null()
        elif len(self.records) < len(self._shapes):
            self.record()
802001
private void addLoadBalancerListener() {
        if (!(lbContext.getLoadBalancer() instanceof BaseLoadBalancer)) {
            return;
        }
        
        ((BaseLoadBalancer) lbContext.getLoadBalancer()).addServerListChangeListener(new ServerListChangeListener() {
            @Override
            public void serverListChanged(List<Server> oldList, List<Server> newList) {
                Set<Server> removedServers = new HashSet<Server>(oldList);
                removedServers.removeAll(newList);
                for (Server server: rxClientCache.keySet()) {
                    if (removedServers.contains(server)) {
                        // this server is no longer in UP status
                        removeClient(server);
                    }
                }
            }
        });
    }
1164411
def DEFINE_list(self, name, default, help, constant=False):
    """"""
    self.AddOption(
        type_info.List(
            name=name,
            default=default,
            description=help,
            validator=type_info.String()),
        constant=constant)
644722
public void balance() {
        // System.out.print("Before root splitchar = "); System.out.println(sc[root]);

        int i = 0, n = length;
        String[] k = new String[n];
        char[] v = new char[n];
        Iterator iter = new Iterator();
        while (iter.hasMoreElements()) {
            v[i] = iter.getValue();
            k[i++] = (String)iter.nextElement();
        }
        init();
        insertBalanced(k, v, 0, n);

        // With uniform letter distribution sc[root] should be around 'm'
        // System.out.print("After root splitchar = "); System.out.println(sc[root]);
    }
143513
private int[] buildIndex(final int[] counts, int[] positions, int minsupp) {
    // Count the number of frequent items:
    int numfreq = 0;
    for(int i = 0; i < counts.length; i++) {
      if(counts[i] >= minsupp) {
        ++numfreq;
      }
    }
    // Build the index table
    int[] idx = new int[numfreq];
    for(int i = 0, j = 0; i < counts.length; i++) {
      if(counts[i] >= minsupp) {
        idx[j++] = i;
      }
    }
    IntegerArrayQuickSort.sort(idx, (x, y) -> Integer.compare(counts[y], counts[x]));
    Arrays.fill(positions, -1);
    for(int i = 0; i < idx.length; i++) {
      positions[idx[i]] = i;
    }
    return idx;
  }
62910
private void balance(PersistentStore store, NodeAVL x, boolean isleft) {

        while (true) {
            int sign = isleft ? 1
                              : -1;

            switch (x.getBalance() * sign) {

                case 1 :
                    x = x.setBalance(store, 0);

                    return;

                case 0 :
                    x = x.setBalance(store, -sign);
                    break;

                case -1 :
                    NodeAVL l = child(store, x, isleft);

                    if (l.getBalance() == -sign) {
                        replace(store, x, l);

                        x = set(store, x, isleft, child(store, l, !isleft));
                        l = set(store, l, !isleft, x);
                        x = x.setBalance(store, 0);
                        l = l.setBalance(store, 0);
                    } else {
                        NodeAVL r = child(store, l, !isleft);

                        replace(store, x, r);

                        l = set(store, l, !isleft, child(store, r, isleft));
                        r = set(store, r, isleft, l);
                        x = set(store, x, isleft, child(store, r, !isleft));
                        r = set(store, r, !isleft, x);

                        int rb = r.getBalance();

                        x = x.setBalance(store, (rb == -sign) ? sign
                                                              : 0);
                        l = l.setBalance(store, (rb == sign) ? -sign
                                                             : 0);
                        r = r.setBalance(store, 0);
                    }

                    return;
            }

            if (x.isRoot()) {
                return;
            }

            isleft = x.isFromLeft(store);
            x      = x.getParent(store);
        }
    }
58015
public void setBranches(java.util.Collection<String> branches) {
        if (branches == null) {
            this.branches = null;
            return;
        }

        this.branches = new java.util.ArrayList<String>(branches);
    }
1308646
protected function balanceTree()
	{
		$bf	= $this->getBalance();
		if( $bf >= $this->balance ) 												// LR or LL rotation
		{
			$ll_height	= $this->left->left  ? $this->left->left->getHeight()  : 0;
			$lr_height	= $this->left->right ? $this->left->right->getHeight() : 0;
			if( $ll_height < $lr_height )
				$this->left->rotateRR(); 											// LR rotation
			$this->rotateLL();
		}
		else if( $bf <= $this->balance )											// RR or RL rotation
		{
			$rr_height	= $this->right->right ? $this->right->right->getHeight() : 0;
			$rl_height	= $this->right->left  ? $this->right->left->getHeight()  : 0;
			if( $rl_height > $rr_height )
				$this->right->rotateLL();											// RR rotation
			$this->rotateRR();
		}
	}
412151
def _adjust_truism(t):
        
        if t.args[0].cardinality == 1 and t.args[1].cardinality > 1:
            swapped = Balancer._reverse_comparison(t)
            return swapped
        return t
323049
def branchlist2branches(data, commdct, branchlist):
    """"""
    objkey = 'BranchList'.upper()
    theobjects = data.dt[objkey]
    fieldlists = []
    objnames = [obj[1] for obj in theobjects]
    for theobject in theobjects:
        fieldlists.append(list(range(2, len(theobject))))
    blists = extractfields(data, commdct, objkey, fieldlists)
    thebranches = [branches for name, branches in zip(objnames, blists)
                   if name == branchlist]
    return thebranches[0]
55368
def elb_table(balancers):
    
    t = prettytable.PrettyTable(['Name', 'DNS', 'Ports', 'Zones', 'Created'])
    t.align = 'l'
    for b in balancers:
        ports = ['%s: %s -> %s' % (l[2], l[0], l[1]) for l in b.listeners]
        ports = '\n'.join(ports)
        zones = '\n'.join(b.availability_zones)
        t.add_row([b.name, b.dns_name, ports, zones, b.created_time])
    return t
866910
def process_lists(self):
        """"""
        for l1_idx, obj1 in enumerate(self.l1):
            for l2_idx, obj2 in enumerate(self.l2):
                if self.equal(obj1, obj2):
                    self.matches.add((l1_idx, l2_idx))