Construct faceted interval trees for the given table, where each node in
    the tree is a row of the table.
961798
def facettupletrees(table, key, start='start', stop='stop', value=None):
    

    import intervaltree
    it = iter(table)
    hdr = next(it)
    flds = list(map(text_type, hdr))
    assert start in flds, 'start field not recognised'
    assert stop in flds, 'stop field not recognised'
    getstart = itemgetter(flds.index(start))
    getstop = itemgetter(flds.index(stop))
    if value is None:
        getvalue = tuple
    else:
        valueindices = asindices(hdr, value)
        assert len(valueindices) > 0, 'invalid value field specification'
        getvalue = itemgetter(*valueindices)
    keyindices = asindices(hdr, key)
    assert len(keyindices) > 0, 'invalid key'
    getkey = itemgetter(*keyindices)

    trees = dict()
    for row in it:
        k = getkey(row)
        if k not in trees:
            trees[k] = intervaltree.IntervalTree()
        trees[k].addi(getstart(row), getstop(row), getvalue(row))
    return trees
949625
def table2matrix(table):
    """"""

    if not is_simpletable(table):
        raise NotSimpleTable("Not able read a cell in the table as a string")
    rows = []
    for tr in table('tr'):
        row = []
        for td in tr('td'):
            td = tdbr2EOL(td) # convert any '<br>' in the td to line ending
            try:
                row.append(td.contents[0])
            except IndexError:
                row.append('')
        rows.append(row)
    return rows
942106
function parentise(tree, h)
{
	if (h === tree.height)
	{
		return tree;
	}

	return {
		ctor: '_Array',
		height: h,
		table: [parentise(tree, h - 1)],
		lengths: [length(tree)]
	};
}
49165
private static void recursiveFindBadNodesInTable(Node n, Node cellroot, Vector<Node> nodes)
    {
        Node cell = cellroot;
        
        if (n.getNodeType() == Node.ELEMENT_NODE)
        {
            String tag = n.getNodeName();
            if (tag.equalsIgnoreCase("table"))
            {
                if (cell != null) //do not enter nested tables
                    return;
            }
            else if (tag.equalsIgnoreCase("tbody") || 
                     tag.equalsIgnoreCase("thead") || 
                     tag.equalsIgnoreCase("tfoot") ||
                     tag.equalsIgnoreCase("tr") ||
                     tag.equalsIgnoreCase("col") ||
                     tag.equalsIgnoreCase("colgroup"))
            {
            }
            else if (tag.equalsIgnoreCase("td") || tag.equalsIgnoreCase("th") || tag.equalsIgnoreCase("caption"))
            {
                cell = n;
            }
            else //other elements
            {
                if (cell == null)
                {
                    nodes.add(n);
                    return;
                }
            }
        } //other nodes
        else if (n.getNodeType() == Node.TEXT_NODE)
        {
            if (cell == null && n.getNodeValue().trim().length() > 0)
            {
                nodes.add(n);
                return;
            }
        }
        
        NodeList child = n.getChildNodes();
        for (int i = 0; i < child.getLength(); i++)
            recursiveFindBadNodesInTable(child.item(i), cell, nodes);
    }
69900
def _build_kth_tree(self):
        """"""
        anchor = self.get_anchor()
        aux_sorted = self._sort_tau_by_y(anchor)
        edges = self.previous_tree.edges

        for itr in range(self.n_nodes - 1):
            right = int(aux_sorted[itr, 0])
            left_parent, right_parent = Edge.sort_edge([edges[anchor], edges[right]])
            new_edge = Edge.get_child_edge(itr, left_parent, right_parent)
            new_edge.tau = aux_sorted[itr, 1]
            self.edges.append(new_edge)
588505
def table_repr(columns, rows, data, padding=2):
    """"""
    padding = ' ' * padding
    column_lengths = [len(column) for column in columns]
    for row in rows:
        for i, column in enumerate(columns):
            item = str(data[row][column])
            column_lengths[i] = max(len(item), column_lengths[i])
    max_row_length = max(len(row) for row in rows) if len(rows) else 0
    table_row = ' ' * max_row_length
    for i, column in enumerate(columns):
        table_row += padding + column.rjust(column_lengths[i])
    table_rows = [table_row]
    for row in rows:
        table_row = row.rjust(max_row_length)
        for i, column in enumerate(columns):
            item = str(data[row][column])
            table_row += padding + item.rjust(column_lengths[i])
        table_rows.append(table_row)
    return '\n'.join(table_rows)
259499
private void buildJoinTreeForColumn(String aColName, boolean useOuterJoin, UserAlias aUserAlias, Map pathClasses)
	{
		String pathName = SqlHelper.cleanPath(aColName);
		int sepPos = pathName.lastIndexOf(".");

		if (sepPos >= 0)
		{
			getTableAlias(pathName.substring(0, sepPos), useOuterJoin, aUserAlias,
						  new String[]{pathName.substring(sepPos + 1)}, pathClasses);
		}
	}
1121228
private List<HashMap<String, String>> createRowsHashMap(Document doc, String tableName) {

        List<HashMap<String, String>> result = new ArrayList<>();

        NodeList nl = doc.getElementsByTagName("Row");

        for (int i = 0; i < nl.getLength(); i++) {
            Node n = nl.item(i);
            // check if the rows belongs to the table name
            Node tableNodeNameAttr = n.getParentNode().getAttributes().getNamedItem("name");
            String tableNameAttr = tableNodeNameAttr.getNodeValue();
            if (!tableNameAttr.equals(tableName)) {
                continue;
            }

            if (n.hasChildNodes()) {
                NodeList child = n.getChildNodes();
                HashMap<String, String> hash = new HashMap<>();
                result.add(hash);
                for (int j = 0; j < child.getLength(); j++) {
                    Node childNode = child.item(j);

                    if (childNode.getNodeType() != Node.ELEMENT_NODE) {
                        continue;
                    }
                    //System.out.println("childNode is :" + childNode.getNodeName() + " with value " + childNode.getTextContent
                    // ());
                    hash.put(childNode.getNodeName(), childNode.getTextContent());
                }
            }
        }
        return result;
    }
778970
public void buildTree(INDArray x) {
        this.X = x;
        for(int i = 0; i < x.rows(); i++) {
            root.getIndices().add(i);
        }



        RPUtils.buildTree(this,root,rpHyperPlanes,
                x,maxSize,0,similarityFunction);
    }
813432
def for_(self, table):
        
        self.args = [param.for_(table) for param in self.args]
1182778
function tinf_build_fixed_trees(lt, dt) {
  var i;

  /* build fixed length tree */
  for (i = 0; i < 7; ++i) lt.table[i] = 0;

  lt.table[7] = 24;
  lt.table[8] = 152;
  lt.table[9] = 112;

  for (i = 0; i < 24; ++i) lt.trans[i] = 256 + i;
  for (i = 0; i < 144; ++i) lt.trans[24 + i] = i;
  for (i = 0; i < 8; ++i) lt.trans[24 + 144 + i] = 280 + i;
  for (i = 0; i < 112; ++i) lt.trans[24 + 144 + 8 + i] = 144 + i;

  /* build fixed distance tree */
  for (i = 0; i < 5; ++i) dt.table[i] = 0;

  dt.table[5] = 32;

  for (i = 0; i < 32; ++i) dt.trans[i] = i;
}
880734
private void computeIJTable(InfoTree it, int subtreePreorder,
			int subtreeRevPreorder, int subtreeSize, int aStrategy, int treeSize) {

		int change;

		int[] post2pre = it.info[POST2_PRE];
		int[] rpost2post = it.info[RPOST2_POST];

		if (aStrategy == LEFT) {
			for (int x = 0; x < subtreeSize; x++) {
				ij[0][x] = x + subtreePreorder;
			}
			for (int x = 1; x < subtreeSize; x++) {
				change = post2pre[(treeSize - 1 - (x - 1 + subtreeRevPreorder))];
				for (int z = 0; z < subtreeSize; z++) {
					if (ij[x - 1][z] >= change) {
						ij[x][z] = ij[x - 1][z] + 1;
					} else {
						ij[x][z] = ij[x - 1][z];
					}
				}
			}
		} else { // if (aStrategy == RIGHT) {
			for (int x = 0; x < subtreeSize; x++) {
				ij[0][x] = x + subtreeRevPreorder;
			}
			for (int x = 1; x < subtreeSize; x++) {
				change = treeSize
						- 1
						- rpost2post[(treeSize - 1 - (x - 1 + subtreePreorder))];
				for (int z = 0; z < subtreeSize; z++) {
					if (ij[x - 1][z] >= change) {
						ij[x][z] = ij[x - 1][z] + 1;
					} else {
						ij[x][z] = ij[x - 1][z];
					}
				}
			}
		}
	}
437785
public static Builder newBuilder(TableId table, Iterable<RowToInsert> rows) {
    return newBuilder(table).setRows(rows);
  }
630779
def _make_table(values):
        """"""
        import collections
        table = collections.deque()
        start, end = values[0], values[0]
        for num, value in enumerate(values):
            if num == 0:
                table.append((value, value,))
                continue
            start, end = table.pop()
            if end == value - 1:
                table.append((start, value,))
            else:
                table.append((start, end,))
                table.append((value, value,))
        return tuple(table)
1026130
def _setrow(self, row):
        
        try:
            compname, kwd, innode, outnode, thcomp = row[0:5]
        except ValueError:
            raise ValueError('Error unpacking row: %s'%row)

        #Innode is an integer
        k=int(innode)

        #"Clear" should become None
        if compname == 'clear':
            compname = None
        if thcomp == 'clear':
            thcomp = None

        #Now create the GraphNode defined by this row,
        #and add it to the table. Default nodes are special.
        if kwd == 'default':
            self.tab[k].set_default(int(outnode),compname, thcomp)
        else:
            try:
                self.tab[k].set_named(kwd,int(outnode),compname, thcomp)
            except IndexError:
                old = self.tab[k].get_named(kwd)
                plist = (k, kwd, old, (outnode, compname, thcomp))
                self.problemset.add(plist)
264202
def build_trees(self):
        ""

        # storage
        nodes = {}
        idxarr = np.arange(len(self.fclade_counts[0][0]))
        queue = []

        ## create dict of clade counts and set keys
        countdict = defaultdict(int)
        for clade, count in self.fclade_counts:
            mask = np.int_(list(clade)).astype(np.bool)
            ccx = idxarr[mask]
            queue.append((len(ccx), frozenset(ccx)))
            countdict[frozenset(ccx)] = count

        while queue:
            queue.sort()
            (clade_size, clade) = queue.pop(0)
            new_queue = []

            # search for ancestors of clade
            for (_, ancestor) in queue:
                if clade.issubset(ancestor):
                    # update ancestor such that, in the following example:
                    # ancestor == {1, 2, 3, 4}
                    # clade == {2, 3}
                    # new_ancestor == {1, {2, 3}, 4}
                    new_ancestor = (ancestor - clade) | frozenset([clade])
                    countdict[new_ancestor] = countdict.pop(ancestor)
                    ancestor = new_ancestor

                new_queue.append((len(ancestor), ancestor))

            # if the clade is a tip, then we have a name
            if clade_size == 1:
                name = list(clade)[0]
                name = self.namedict[name]
            else:
                name = None

            # the clade will not be in nodes if it is a tip
            children = [nodes.pop(c) for c in clade if c in nodes]
            node = TreeNode(name=name)
            for child in children:
                node.add_child(child)
            if not node.is_leaf():
                node.dist = int(round(100 * countdict[clade]))
                node.support = int(round(100 * countdict[clade]))
            else:
                node.dist = int(100)
                node.support = int(100)

            nodes[clade] = node
            queue = new_queue
        nodelist = list(nodes.values())
        tre = nodelist[0]

        #tre.unroot()
        ## return the tree and other trees if present
        self.ttree = ToyTree(tre.write(format=0))
        self.ttree._coords.update()
        self.nodelist = nodelist
524468
def Define_TreeTable(self, heads, heads2=None):
        ''' 
        '''
        display_heads = []
        display_heads.append(tuple(heads[2:]))
        self.tree_table = TreeTable()
        self.tree_table.append_from_list(display_heads, fill_title=True)
        if heads2 is not None:
            heads2_color = heads2[1]
            row_widget = gui.TableRow()
            for index, field in enumerate(heads2[2:]):
                row_item = gui.TableItem(text=field,
                                         style={'background-color': heads2_color})
                row_widget.append(row_item, field)
            self.tree_table.append(row_widget, heads2[0])
        self.wid.append(self.tree_table)