Package gnu.trove.list

Examples of gnu.trove.list.TIntList


        assertEquals(12, list.get(1));
    }


    public void testSum() {
        TIntList list = new TIntArrayList();
        assertEquals(0, list.sum());

        list.add(1);
        assertEquals(1, list.sum());

        list.add(1234);
        assertEquals(1235, list.sum());

        list.removeAt(0);
        assertEquals(1234, list.sum());

        list.clear();
        assertEquals(0, list.sum());
    }
View Full Code Here


        }
    }

    public void clean() {
        TIntObjectMap<Sorter> oldSorters = sorters;
        TIntList oldSorterKeys = sorterKeys;
        sorterKeys = new TIntArrayList();
        sorters = new TIntObjectHashMap<Sorter>();
        reverseIndexer = new TIntObjectHashMap<TIntSet>();

        TIntIterator iter = oldSorterKeys.iterator();
        while (iter.hasNext()) {
            int srcId = iter.next();
            if (this.source.contains(srcId)) {
                sorterKeys.add(srcId);
                Sorter oldSorter = oldSorters.get(srcId);
View Full Code Here

    public void _accumulate(int vecid, int[] pairs) {
        validateParams(vecid, pairs);
        if (!indexer.containsKey(vecid)) {
            _add(vecid, pairs);
        } else {
            TIntList indexes = new TIntArrayList();
            TIntFloatMap results = new TIntFloatHashMap();

            float max = Float.NEGATIVE_INFINITY;
            int cursor = indexer.get(vecid);
            int length = lengths.get(vecid);
            while (length > 0) {
                int pos = (int) data.get(cursor++);
                float val = data.get(cursor++);
                results.put(pos, val);
                if (val > max) {
                    max = val;
                }
                indexes.add(pos);
                length -= 2;
            }

            cursor = 0;
            while (cursor < pairs.length) {
                int pos = pairs[cursor++];
                float val = (float) pairs[cursor++];
                if (results.containsKey(pos)) {
                    val = results.get(pos) + val;
                    results.put(pos, val);
                    if (val > max) {
                        max = val;
                    }
                } else {
                    results.put(pos, val);
                    indexes.add(pos);
                }
            }
            indexes.sort();

            int start = data.size();
            indexer.put(vecid, start);
            lengths.put(vecid, indexes.size() * 2);
            TIntIterator iter = indexes.iterator();
            if (max < accumuFactor * sparseFactor) {
                while (iter.hasNext()) {
                    int key = iter.next();
                    float value = results.get(key);
                    data.add(key);
View Full Code Here

    }


    public void testForEachDescendingFalse() {
        int element_count = 20;
        TIntList a = new TIntArrayList();
        for ( int i = 1; i < element_count; i++ ) {
            a.add( i );
        }

        class ForEach implements TIntProcedure {
            TIntList built = new TIntArrayList();


            public boolean execute( int value ) {
                built.add( value );
                return false;
            }

            TIntList getBuilt() {
                return built;
            }
        }

        ForEach foreach = new ForEach();
        a.forEachDescending( foreach );
        TIntList built = foreach.getBuilt();
        built.reverse();
        assertEquals( 1, built.size() );
        assertEquals( 19, built.get( 0 ) );
    }
View Full Code Here

    }


    public void testSortPartial() {
        int element_count = 20;
        TIntList a = new TIntLinkedList();
        for ( int i = 1; i <= element_count; i++ ) {
            a.add( i );
        }

        a.reverse();
        a.sort( 5, 15 );

        int[] expected = {20, 19, 18, 17, 16, 6, 7, 8, 9, 10,
                          11, 12, 13, 14, 15, 5, 4, 3, 2, 1};
        for ( int i = 0; i < a.size(); i++ ) {
            assertEquals( expected[i], a.get( i ) );
        }

        try {
            a.sort( 20, 10 );
            fail( "Expected IllegalArgumentException" );
        }
        catch ( IllegalArgumentException ex ) {
            // Expected
        }
View Full Code Here

    }


    public void testTransform() {
        int element_count = 20;
        TIntList a = new TIntArrayList();
        for ( int i = 1; i < element_count; i++ ) {
            a.add( i );
        }

        a.transformValues( new TIntFunction() {
            public int execute( int value ) {
                return value * value;
            }
        } );

        for ( int i = 0; i < a.size(); i++ ) {
            int result = a.get( i );
            int expected = ( i + 1 ) * ( i + 1 );
            assertEquals( expected, result );
        }
    }
View Full Code Here

    }


    public void testEquals() {
        int element_count = 20;
        TIntList list = new TIntLinkedList();
        for ( int i = 1; i <= element_count; i++ ) {
            list.add( i );
        }

        assertEquals( list, list );
        assertEquals( list, new TIntLinkedList( list ) );


        TIntCollection collection = new TIntHashSet();
        for ( int i = 1; i <= element_count; i++ ) {
            collection.add( i );
        }

        assertFalse( list.equals( collection ) );

        collection.add( 1138 );
        assertFalse( list.equals( collection ) );

        TIntList other = new TIntLinkedList( list );
        other.replace( 10, 1138 );
        assertFalse( list.equals( other ) );
    }
View Full Code Here

    }


    public void testReverse() {
        int element_count = 20;
        TIntList a = new TIntArrayList();
        for ( int i = 1; i <= element_count; i++ ) {
            a.add( i );
        }

        a.reverse();

        for ( int i = 0, j = a.size(); i < a.size(); i++, j-- ) {
            assertEquals( j, a.get( i ) );
        }
    }
View Full Code Here

    }


    public void testReversePartial() {
        int element_count = 20;
        TIntList a = new TIntArrayList();
        for ( int i = 1; i <= element_count; i++ ) {
            a.add( i );
        }

        a.reverse( 1, 19 );

        int[] expected = {1, 19, 18, 17, 16, 15, 14, 13, 12, 11,
                          10, 9, 8, 7, 6, 5, 4, 3, 2, 20};
        for ( int i = 0; i < a.size(); i++ ) {
            assertEquals( expected[i], a.get( i ) );
        }

        try {
            a.reverse( 20, 10 );
            fail( "Expected IllegalArgumentException" );
        }
        catch ( IllegalArgumentException ex ) {
            // Expected
        }
View Full Code Here

    }


    public void testSortPartial() {
        int element_count = 20;
        TIntList a = new TIntArrayList();
        for ( int i = 1; i <= element_count; i++ ) {
            a.add( i );
        }

        a.reverse();
        a.sort( 5, 15 );

        int[] expected = {20, 19, 18, 17, 16, 6, 7, 8, 9, 10,
                          11, 12, 13, 14, 15, 5, 4, 3, 2, 1};
        for ( int i = 0; i < a.size(); i++ ) {
            assertEquals( expected[i], a.get( i ) );
        }

        try {
            a.sort( 20, 10 );
            fail( "Expected IllegalArgumentException" );
        }
        catch ( IllegalArgumentException ex ) {
            // Expected
        }
View Full Code Here

TOP

Related Classes of gnu.trove.list.TIntList

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.