Computes the layers of the merkletree.

    First layer is the list of elements and the last layer is a list with a
    single entry, the merkleroot.
171315
def compute_layers(elements: List[Keccak256]) -> List[List[Keccak256]]:
    

    elements = list(elements)  # consume generators
    assert elements, 'Use make_empty_merkle_tree if there are no elements'

    if not all(isinstance(item, bytes) for item in elements):
        raise ValueError('all elements must be bytes')

    if any(len(item) != 32 for item in elements):
        raise HashLengthNot32()

    if len(elements) != len(set(elements)):
        raise ValueError('Duplicated element')

    leaves = sorted(item for item in elements)
    tree = [leaves]

    layer = leaves
    while len(layer) > 1:
        paired_items = split_in_pairs(layer)
        layer = [hash_pair(a, b) for a, b in paired_items]
        tree.append(layer)

    return tree
1252406
def _vector_layers(self):
        
        layers = []
        vector_datasource = self.vector_driver.Open(
            self.uri.absoluteFilePath())
        if vector_datasource:
            for i in range(vector_datasource.GetLayerCount()):
                layers.append(vector_datasource.GetLayer(i).GetName())
        return layers
1219622
async def setLayers(self, layers):
        '''
        
        '''
        layrs = []

        for iden in layers:
            layr = self.core.layers.get(iden)
            if layr is None:
                raise s_exc.NoSuchLayer(iden=iden)
            if not layrs and layr.readonly:
                raise s_exc.ReadOnlyLayer(mesg=f'First layer {layr.iden} must not be read-only')

            layrs.append(layr)

        self.borked = None
        self.layers = layrs

        await self.info.set('layers', layers)
462256
def compute_node_positions(self):
        
        xs = [0] * len(self.nodes)
        ys = [0] * len(self.nodes)
        for i, _ in enumerate(self.nodes[1:], start=1):
            prev_r = self.node_sizes[i - 1] / 2
            curr_r = self.node_sizes[i] / 2
            xs[i] = xs[i - 1] + prev_r + curr_r

        self.node_coords = {"x": xs, "y": ys}
136225
def make_input_layers(self):
        
        self.input_layers = []
        in_nodes = self.model._inbound_nodes if hasattr(
                self.model,'_inbound_nodes') else self.model.inbound_nodes
        if hasattr(self.model, 'input_layers'):
            input_keras_layers = self.model.input_layers[:]
            self.input_layers = [None] * len(input_keras_layers)
            for layer in self.layer_list:
                keras_layer = self.keras_layer_map[layer]
                if isinstance(keras_layer, InputLayer):
                    if keras_layer in input_keras_layers:
                        idx = input_keras_layers.index(keras_layer)
                        self.input_layers[idx] = layer
        elif hasattr(self.model, 'inputs'):
            for ts in _to_list(self.model.inputs):
                # search for the InputLayer that matches this ts
                for l in self.layer_list:
                    kl = self.keras_layer_map[l]
                    if isinstance(kl, InputLayer) and kl.input == ts:
                        self.input_layers.append(l)
        elif len(in_nodes) <= 1:
            for ts in _to_list(self.model.input):
                # search for the InputLayer that matches this ts
                for l in self.layer_list:
                    kl = self.keras_layer_map[l]
                    if isinstance(kl, InputLayer) and kl.input == ts:
                        self.input_layers.append(l)
        else:
            raise ValueError("Input values cannot be identified.")
1209707
def make_output_layers(self):
        
        # TODO
        # use successors == 0 as the criteria for output layer
        # will fail when some intermediate layers also generate output.
        # However, because the possibility of having inserted layers,
        # it's more difficult to tell which layer is the output layer.
        # Once possible way is to keep track of newly added layers...
        self.output_layers = []
        for layer in self.layer_list:
            if len(self.get_successors(layer)) == 0:
                self.output_layers.append(layer)
911855
private void dfs() {
    Deque<Node> stack = new LinkedList<>();
    stack.add(tree.getRootNode());
    while (!stack.isEmpty()) {
      Node node = stack.removeLast();
      node.startSize = list.size();
      if (node.getEdges().isEmpty()) {
        // leaf
        list.add(node.depth);
        node.endSize = list.size();
      } else {
        if (!node.equals(tree.getRootNode())) {
          // inner node = not leaf and not root
          innerNodes.add(node);
        }
        for (Edge edge : node.getEdges()) {
          Node endNode = edge.getEndNode();
          endNode.depth = node.depth + edge.getSpan() + 1;
          stack.addLast(endNode);
        }
      }
    }
    // At this point all inner nodes are ordered by the time of entering, so we visit them from last to first
    ListIterator<Node> iterator = innerNodes.listIterator(innerNodes.size());
    while (iterator.hasPrevious()) {
      Node node = iterator.previous();
      int max = -1;
      for (Edge edge : node.getEdges()) {
        max = Math.max(edge.getEndNode().endSize, max);
      }
      node.endSize = max;
    }
  }
1171678
def compute_merkletree_with(
        merkletree: MerkleTreeState,
        lockhash: LockHash,
) -> Optional[MerkleTreeState]:
    """"""
    # Use None to inform the caller the lockshash is already known
    result = None

    leaves = merkletree.layers[LEAVES]
    if lockhash not in leaves:
        leaves = list(leaves)
        leaves.append(Keccak256(lockhash))
        result = MerkleTreeState(compute_layers(leaves))

    return result
930848
def nodes(self):
        
        nodes = np.array(list(self.transforms.nodes()))
        return nodes
356485
function() {
    var n; // iterates over tree elements

    // Initialize the trees.
    for(n = 0; n < zip_L_CODES;  n++) zip_dyn_ltree[n].fc = 0;
    for(n = 0; n < zip_D_CODES;  n++) zip_dyn_dtree[n].fc = 0;
    for(n = 0; n < zip_BL_CODES; n++) zip_bl_tree[n].fc = 0;

    zip_dyn_ltree[zip_END_BLOCK].fc = 1;
    zip_opt_len = zip_static_len = 0;
    zip_last_lit = zip_last_dist = zip_last_flags = 0;
    zip_flags = 0;
    zip_flag_bit = 1;
}
1290438
def getLayerIndex(self, layer):
                      
        for i in range(len(self.layers)):
            if layer == self.layers[i]: # shallow cmp
                return i
        return -1 # not in list
220205
def layers(self):
        
        if self._layers is None:
            self.__init()
        self._getLayers()
        return self._layers
519064
function buildLayers() {
            layers = transformedData.map((item) => {
                let ret = {};

                groups.forEach((key) => {
                    ret[key] = item[key];
                });

                return assign({}, item, ret);
            });
        }
1070033
def make_input_layers(self):
        
        self.input_layers = []
        if hasattr(self.model, 'input_layers'):
            input_keras_layers = self.model.input_layers[:]
            self.input_layers = [None] * len(input_keras_layers)
            for layer in self.layer_list:
                keras_layer = self.keras_layer_map[layer]
                if isinstance(keras_layer, _keras.engine.topology.InputLayer):
                    if keras_layer in input_keras_layers:
                        idx = input_keras_layers.index(keras_layer)
                        self.input_layers[idx] = layer
        elif len(self.model.inbound_nodes) <= 1:
            for ts in _to_list(self.model.input):
                # search for the InputLayer that matches this ts
                for l in self.layer_list:
                    kl = self.keras_layer_map[l]
                    if isinstance(kl, _keras.engine.topology.InputLayer) and kl.input == ts:
                        self.input_layers.append(l)
        else:
            raise ValueError("Input values cannot be identified.")
32972
function getLayers(elements) {
  if (elements.length === 0) {
    return [[""]];
  }
  const layers = [];
  layers.push(elements);
  while (layers[layers.length - 1].length > 1) {
    layers.push(getNextLayer(layers[layers.length - 1]));
  }
  return layers;
}
730969
def merkleroot(hashes):
    
    # XXX TEMPORARY -- MUST REVIEW and possibly CHANGE
    # The idea here is that the UTXO SET would be empty and this function
    # would be invoked to compute the merkle root, and since there is nothing,
    # i.e. an empty list, then the hash of the empty string is returned.
    # This seems too easy but maybe that is good enough? TO REVIEW!
    if not hashes:
        return sha3_256(b'').hexdigest()
    # XXX END TEMPORARY -- MUST REVIEW ...
    if len(hashes) == 1:
        return hexlify(hashes[0]).decode()
    if len(hashes) % 2 == 1:
        hashes.append(hashes[-1])
    parent_hashes = [
        sha3_256(hashes[i] + hashes[i+1]).digest()
        for i in range(0, len(hashes)-1, 2)
    ]
    return merkleroot(parent_hashes)
424603
def from_etree(cls, etree_element):
        
        ins = SaltElement.from_etree(etree_element)
        # TODO: this looks dangerous, ask Stackoverflow about it!
        # convert SaltElement into SaltLayer
        ins.__class__ = SaltLayer.mro()[0]

        # add nodes and edges that belong to this layer (if any)
        for element in ('nodes', 'edges'):
            elem_list = []
            xpath_result = etree_element.xpath('@'+element)
            if xpath_result:
                val_str = xpath_result[0]
                elem_list.extend(int(elem_id)
                                 for elem_id in DIGITS.findall(val_str))
            setattr(ins, element, elem_list)
        return ins