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


Java TIntStack类代码示例

本文整理汇总了Java中gnu.trove.stack.TIntStack的典型用法代码示例。如果您正苦于以下问题:Java TIntStack类的具体用法?Java TIntStack怎么用?Java TIntStack使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: testConstructors

import gnu.trove.stack.TIntStack; //导入依赖的package包/类
public void testConstructors() {
     TIntStack stack = new TIntArrayStack();
     assertEquals( 0, stack.size() );

     stack.push( 10 );
     stack.push( 20 );
     assertEquals( 2, stack.size() );

     TIntStack other = new TIntArrayStack( 20 );
     other.push( 10 );
     other.push( 20 );
     assertEquals( 2, other.size() );

     assertTrue( "stacks should be equal: " + stack + ", " + other,
stack.equals( other ) );

     TIntStack copy = new TIntArrayStack( stack );
     assertTrue( "stacks should be equal: " + stack + ", " + copy,
stack.equals( copy ) );
 }
 
开发者ID:palantir,项目名称:trove-3.0.3,代码行数:21,代码来源:TStackTest.java

示例2: testBasic

import gnu.trove.stack.TIntStack; //导入依赖的package包/类
public void testBasic() {
    TIntStack stack = new TIntArrayStack();

    assertEquals( 0, stack.size() );

    stack.push( 10 );

    assertEquals( 1, stack.size() );

    assertEquals( 10, stack.peek() );
    assertEquals( 1, stack.size() );
    assertEquals( 10, stack.peek() );
    assertEquals( 1, stack.size() );

    assertEquals( 10, stack.pop() );
    assertEquals( 0, stack.size() );

    stack.push( 10 );
    stack.push( 20 );
    stack.push( 30 );

    assertEquals( 3, stack.size() );
    assertEquals( 30, stack.pop() );
    assertEquals( 20, stack.pop() );
    assertEquals( 10, stack.pop() );
}
 
开发者ID:palantir,项目名称:trove-3.0.3,代码行数:27,代码来源:TStackTest.java

示例3: testClear

import gnu.trove.stack.TIntStack; //导入依赖的package包/类
public void testClear() {
    TIntStack stack = new TIntArrayStack();

    assertEquals( 0, stack.size() );

    stack.push( 10 );

    assertEquals( 1, stack.size() );
    assertEquals( 10, stack.pop() );
    assertEquals( 0, stack.size() );

    stack.push( 10 );
    stack.push( 20 );
    stack.push( 30 );

    assertEquals( 3, stack.size() );
    stack.clear();

    assertEquals( 0, stack.size() );
}
 
开发者ID:palantir,项目名称:trove-3.0.3,代码行数:21,代码来源:TStackTest.java

示例4: testEquals

import gnu.trove.stack.TIntStack; //导入依赖的package包/类
public void testEquals() {
     TIntStack stack = new TIntArrayStack();
     assertEquals( 0, stack.size() );

     stack.push( 10 );
     stack.push( 20 );
     assertEquals( 2, stack.size() );

     TIntStack other = new TIntArrayStack( 20 );
     other.push( 10 );
     other.push( 20 );
     assertEquals( 2, other.size() );

     assertTrue( "stacks should equal itself: " + stack,
stack.equals( stack ) );

     assertTrue( "stacks should be equal: " + stack + ", " + other,
stack.equals( other ) );

     TIntArrayList list = new TIntArrayList( stack.toArray() );
     assertFalse( "stack should not equal list: " + stack + ", " + list,
stack.equals( list ) );
 }
 
开发者ID:palantir,项目名称:trove-3.0.3,代码行数:24,代码来源:TStackTest.java

示例5: testHashCode

import gnu.trove.stack.TIntStack; //导入依赖的package包/类
public void testHashCode() {
     TIntStack stack = new TIntArrayStack();
     assertEquals( 0, stack.size() );

     stack.push( 10 );
     stack.push( 20 );
     assertEquals( 2, stack.size() );

     TIntStack other = new TIntArrayStack( 20 );
     other.push( 10 );
     other.push( 20 );
     assertEquals( 2, other.size() );

     assertTrue( "stack hashcode should equal itself: " + stack,
stack.hashCode() == stack.hashCode() );

     assertTrue( "stacks should be equal: " + stack + ", " + other,
stack.hashCode() == other.hashCode() );

     other.push( 30 );
     assertFalse( "stack should not equal list: " + stack + ", " + other,
stack.hashCode() == other.hashCode() );
 }
 
开发者ID:palantir,项目名称:trove-3.0.3,代码行数:24,代码来源:TStackTest.java

示例6: testSerialize

import gnu.trove.stack.TIntStack; //导入依赖的package包/类
public void testSerialize() throws Exception {
    TIntStack stack = new TIntArrayStack();
    stack.push( 10 );
    stack.push( 20 );
    stack.push( 30 );
    stack.push( 40 );
    stack.push( 50 );

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream( baos );
    oos.writeObject( stack );

    ByteArrayInputStream bais = new ByteArrayInputStream( baos.toByteArray() );
    ObjectInputStream ois = new ObjectInputStream( bais );

    TIntStack serialized = (TIntStack) ois.readObject();

    assertEquals( stack, serialized );
}
 
开发者ID:palantir,项目名称:trove-3.0.3,代码行数:20,代码来源:TStackTest.java

示例7: TIntArrayStack

import gnu.trove.stack.TIntStack; //导入依赖的package包/类
/**
 * Creates a new <code>TIntArrayStack</code> instance that is
 * a copy of the instanced passed to us.
 *
 * @param stack the instance to copy
 */
public TIntArrayStack( TIntStack stack ) {
    if ( stack instanceof TIntArrayStack ) {
        TIntArrayStack array_stack = ( TIntArrayStack ) stack;
        this._list = new TIntArrayList( array_stack._list );
    } else {
        throw new UnsupportedOperationException( "Only support TIntArrayStack" );
    }
}
 
开发者ID:JianpingZeng,项目名称:xcc,代码行数:15,代码来源:TIntArrayStack.java

示例8: testArrays

import gnu.trove.stack.TIntStack; //导入依赖的package包/类
public void testArrays() {
    int no_entry_value = Integer.MIN_VALUE;
    TIntStack stack = new TIntArrayStack(10, no_entry_value);
    assertEquals( no_entry_value, stack.getNoEntryValue() );

    int[] array;

    array = stack.toArray();
    assertNotNull( array );
    assertEquals( 0, array.length );

    stack.push( 10 );
    stack.push( 20 );
    stack.push( 30 );
    stack.push( 40 );

    array = stack.toArray();
    assertNotNull( array );
    assertEquals( 4, array.length );
    // NOTE: Top element in stack should be first element in array
    assertEquals( 40, array[0] );
    assertEquals( 30, array[1] );
    assertEquals( 20, array[2] );
    assertEquals( 10, array[3] );
    assertEquals( 4, stack.size() );

    int[] array_correct_size = new int[4];
    stack.toArray( array_correct_size );
    assertEquals( 40, array_correct_size[0] );
    assertEquals( 30, array_correct_size[1] );
    assertEquals( 20, array_correct_size[2] );
    assertEquals( 10, array_correct_size[3] );

    int[] array_too_long = new int[6];
    stack.toArray( array_too_long );
    assertEquals( 40, array_too_long[0] );
    assertEquals( 30, array_too_long[1] );
    assertEquals( 20, array_too_long[2] );
    assertEquals( 10, array_too_long[3] );
    assertEquals( stack.getNoEntryValue(), array_too_long[4] );

    int[] array_too_short = new int[2];
    stack.toArray( array_too_short );
    assertEquals( 40, array_too_short[0] );
    assertEquals( 30, array_too_short[1] );
}
 
开发者ID:palantir,项目名称:trove-3.0.3,代码行数:47,代码来源:TStackTest.java

示例9: condenseTree

import gnu.trove.stack.TIntStack; //导入依赖的package包/类
/**
 * Used by delete(). Ensures that all nodes from the passed node
 * up to the root have the minimum number of entries.
 * <p>
 * Note that the parent and parentEntry stacks are expected to
 * contain the nodeIds of all parents up to the root.
 */
private void condenseTree(Node l) {
    // CT1 [Initialize] Set n=l. Set the list of eliminated
    // nodes to be empty.
    Node n = l;
    Node parent = null;
    int parentEntry = 0;

    TIntStack eliminatedNodeIds = new TIntArrayStack();

    // CT2 [Find parent entry] If N is the root, go to CT6. Otherwise
    // let P be the parent of N, and let En be N's entry in P
    while (n.level != this.treeHeight) {
        parent = this.getNode(this.parents.pop());
        parentEntry = this.parentsEntry.pop();

        // CT3 [Eliminiate under-full node] If N has too few entries,
        // delete En from P and add N to the list of eliminated nodes
        if (n.entryCount < this.minNodeEntries) {
            parent.deleteEntry(parentEntry);
            eliminatedNodeIds.push(n.nodeId);
        } else {
            // CT4 [Adjust covering rectangle] If N has not been eliminated,
            // adjust EnI to tightly contain all entries in N
            if (n.mbrMinX != parent.entriesMinX[parentEntry] ||
                    n.mbrMinY != parent.entriesMinY[parentEntry] ||
                    n.mbrMaxX != parent.entriesMaxX[parentEntry] ||
                    n.mbrMaxY != parent.entriesMaxY[parentEntry]) {
                float deletedMinX = parent.entriesMinX[parentEntry];
                float deletedMinY = parent.entriesMinY[parentEntry];
                float deletedMaxX = parent.entriesMaxX[parentEntry];
                float deletedMaxY = parent.entriesMaxY[parentEntry];
                parent.entriesMinX[parentEntry] = n.mbrMinX;
                parent.entriesMinY[parentEntry] = n.mbrMinY;
                parent.entriesMaxX[parentEntry] = n.mbrMaxX;
                parent.entriesMaxY[parentEntry] = n.mbrMaxY;
                parent.recalculateMBRIfInfluencedBy(deletedMinX, deletedMinY,
                        deletedMaxX, deletedMaxY);
            }
        }
        // CT5 [Move up one level in tree] Set N=P and repeat from CT2
        n = parent;
    }

    // CT6 [Reinsert orphaned entries] Reinsert all entries of nodes in set Q.
    // Entries from eliminated leaf nodes are reinserted in tree leaves as in
    // Insert(), but entries from higher level nodes must be placed higher in
    // the tree, so that leaves of their dependent subtrees will be on the same
    // level as leaves of the main tree
    while (eliminatedNodeIds.size() > 0) {
        Node e = this.getNode(eliminatedNodeIds.pop());
        for (int j = 0; j < e.entryCount; j++) {
            this.add(e.entriesMinX[j], e.entriesMinY[j], e.entriesMaxX[j],
                    e.entriesMaxY[j], e.ids[j], e.level);
            e.ids[j] = -1;
        }
        e.entryCount = 0;
        this.deletedNodeIds.push(e.nodeId);
    }
}
 
开发者ID:gegy1000,项目名称:Earth,代码行数:67,代码来源:RTree.java


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