当前位置: 首页>>代码示例>>Java>>正文


Java Stack.ensureCapacity方法代码示例

本文整理汇总了Java中java.util.Stack.ensureCapacity方法的典型用法代码示例。如果您正苦于以下问题:Java Stack.ensureCapacity方法的具体用法?Java Stack.ensureCapacity怎么用?Java Stack.ensureCapacity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.Stack的用法示例。


在下文中一共展示了Stack.ensureCapacity方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: extendRouteForwards

import java.util.Stack; //导入方法依赖的package包/类
/**
 * Completes a path forward in the graph that would explain the sequence if bytes starting by the prefix provided.
 *
 * @param sequence missing sequence we want to
 * @param start inclusive first position in {@code sequence} that starts the extension
 * @param end exclusive position after the last of bases to be added to the extension.
 * @param prefix the seed prefix of the path.
 * @return {@code null} if there is not such path, otherwise a path such that vertex is the last vertex of it
 * and its sequence is prefix.getBases() + sequence[start to end];
 */
private static  <V extends BaseVertex, E extends BaseEdge> Route<V,E> extendRouteForwards(
        final BaseGraph<V, E> graph, final byte[] sequence, final int start, final int end,
        final Route<V, E> prefix) {
    if (end <= start) // trivial case.
        return prefix;

    final Stack<Pair<Route<V,E>,Integer>> stack = new Stack<>();
    stack.ensureCapacity(end - start + 1);
    stack.push(new Pair<>(prefix,start));
    while (!stack.isEmpty()) {
        final Pair<Route<V,E>,Integer> next = stack.pop();
        final Route<V,E> nextRoute = next.getFirst();
        final int nextStart = next.getSecond();
        if (end <= nextStart)
            return nextRoute; // gotcha!!!
        final V lastVertex = nextRoute.getLastVertex();
        final Integer newNextStart = nextStart + 1;
            for (final E edge : graph.outgoingEdgesOf(lastVertex)) {
                final V nextVertex = graph.getEdgeTarget(edge);
                final byte[] nextSequence = nextVertex.getSequence();
                final byte nextByte = nextSequence[nextSequence.length - 1];
                if (nextByte == sequence[nextStart]) {
                    stack.push(new Pair<>(new Route<>(nextRoute,edge),newNextStart));
                }
            }
    }
    return null;
}
 
开发者ID:PAA-NCIC,项目名称:SparkSeq,代码行数:39,代码来源:RouteFinder.java

示例2: extendRouteBackwards

import java.util.Stack; //导入方法依赖的package包/类
/**
 * Completes a path backwards in the graph that would explain the sequence if bytes ending in the vertex provided.
 *
 * @param graph the graph to build the path upon.
 * @param sequence contains the sequence to backtrack.
 * @param start inclusive start position of the sequence to backtrack.
 * @param end exclusive end position of the sequence to backtrack.
 * @param vertex final vertex of the resulting path.
 * @return {@code null} if there is not such path, otherwise a path such that vertex is the last vertex of it
 * and its sequence is squence[start to end] + v.getSuffix();
 */
private static <V extends BaseVertex, E extends BaseEdge> Route<V,E> extendRouteBackwards(final BaseGraph<V, E> graph,
                                                                                         final byte[] sequence,
                                                                                         final int start,
                                                                                         final int end,
                                                                                         final V vertex) {
    final Route<V,E> emptyPath = new Route<>(vertex,graph);
    if (end <= start) // trivial case.
        return emptyPath;
    final int kmerSize = graph.getKmerSize();
    final Stack<Pair<Route<V,E>,Integer>> stack = new Stack<>();
    stack.ensureCapacity(end - start + 1);
    stack.push(new Pair<>(emptyPath,end));
    while (!stack.isEmpty()) {
        final Pair<Route<V,E>,Integer> next = stack.pop();
        final Route<V,E> nextRoute = next.getFirst();
        final int nextEnd = next.getSecond();
        if (nextEnd <= start) {
            return nextRoute.splicePrefix(kmerSize - 1); // gotcha!!!
        }
        final V nextFirstVertex = nextRoute.getFirstVertex();
        if (graph.isSource(nextFirstVertex)) {
            final byte[] fullFirstVertexSequence = nextFirstVertex.getSequence();
            if (nextEnd - start != fullFirstVertexSequence.length - 1) {
                continue; // you need to have the right length to accept a source vertex.
            }
            boolean mismatchFound = false;
            for (int i = 0; i < fullFirstVertexSequence.length - 1; i++) {
                if (fullFirstVertexSequence[i] != sequence[i + start]) {
                    mismatchFound = true;
                    break;
                }
            }
            if (!mismatchFound)
                return nextRoute;
        } else {
            final Integer newNextEnd = nextEnd - 1;
            for (final E edge : graph.incomingEdgesOf(nextFirstVertex)) {
                final V prevVertex = graph.getEdgeSource(edge);
                final byte[] prevSequence = prevVertex.getSequence();
                final byte prevByte = prevSequence[prevSequence.length - 1];
                if (prevByte == sequence[newNextEnd]) {
                    stack.push(new Pair<>(new Route<>(edge,nextRoute),newNextEnd));
                }
            }
        }
    }
    return null;
}
 
开发者ID:PAA-NCIC,项目名称:SparkSeq,代码行数:60,代码来源:RouteFinder.java


注:本文中的java.util.Stack.ensureCapacity方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。