Package gnu.trove.map

Examples of gnu.trove.map.TIntLongMap


    public void testKeySetRetainAllTCollection() {
        int[] keys = {1138, 42, 86, 99, 101, 727, 117};
        long[] vals = new long[keys.length];

        TIntLongMap map = new TIntLongHashMap();
        for ( int i = 0; i < keys.length; i++ ) {
            vals[i] = keys[i] * 2;
            map.put( keys[i], vals[i] );
        }

        TIntSet set = map.keySet();
        assertEquals( map.size(), set.size() );
        assertFalse( set.isEmpty() );

        assertFalse( set.retainAll( set ) );

        // test with a TCollection
        TIntSet tintset = new TIntHashSet( keys );
        assertFalse( "set: " + set + ", collection: " + tintset,
                set.retainAll( tintset ) );
        TIntCollection collection = new TIntArrayList( keys );
        assertFalse( "set: " + set + ", collection: " + collection,
                set.retainAll( collection ) );

        collection.remove( 42 );
        assertTrue( "set: " + set + ", collection: " + collection,
                set.retainAll( collection ) );
        assertEquals( keys.length - 1, set.size() );
        assertEquals( keys.length - 1, map.size() );
    }
View Full Code Here


    public void testKeySetRetainAllArray() {
        int[] keys = {1138, 42, 86, 99, 101, 727, 117};
        long[] vals = new long[keys.length];

        TIntLongMap map = new TIntLongHashMap();
        for ( int i = 0; i < keys.length; i++ ) {
            vals[i] = keys[i] * 2;
            map.put( keys[i], vals[i] );
        }

        TIntSet set = map.keySet();
        assertEquals( map.size(), set.size() );
        assertFalse( set.isEmpty() );

        // test raw array
        map = new TIntLongHashMap();
        for ( int i = 0; i < keys.length; i++ ) {
            vals[i] = keys[i] * 2;
            map.put( keys[i], vals[i] );
        }
        set = map.keySet();
       
        assertFalse( set.retainAll( keys ) );
        assertTrue( set.containsAll( keys ) );
       
        keys[3] = keys[3] + 1;
        assertTrue( set.retainAll( keys ) );
        keys[3] = keys[3] - 1;

        assertEquals( "removed: " + keys[3] + ", set: " + set,
                keys.length - 1, set.size() );
        assertEquals( "removed: " + keys[3] + ", set: " + set
                      + "\nmap: " + map, set.size(), map.size() );
    }
View Full Code Here

    public void testKeySetRemoveAllCollection() {
        int[] keys = {1138, 42, 86, 99, 101, 727, 117};
        long[] vals = new long[keys.length];

        TIntLongMap map = new TIntLongHashMap();
        for ( int i = 0; i < keys.length; i++ ) {
            vals[i] = keys[i] * 2;
            map.put( keys[i], vals[i] );
        }

        TIntSet set = map.keySet();
        assertEquals( map.size(), set.size() );
        assertFalse( set.isEmpty() );

        // test with a java.util.Map
        Set<Number> java_set = new HashSet<Number>();
        assertFalse( set.removeAll( java_set ) );
        assertEquals( keys.length, set.size() );
        assertEquals( keys.length, map.size() );     
        for ( int i = 0; i < keys.length; i++ ) {
            assertTrue( set.contains( keys[i] ) );
            assertTrue( map.containsKey( keys[i] ) );
        }

        for ( int i = 0; i < keys.length; i++ ) {
            java_set.add( Integer.valueOf( keys[i] ) );
        }
        java_set.remove( 42 );
        assertTrue( "set should have been modified: " + set + ", java: " + java_set,
                set.removeAll( java_set ) );
        assertEquals( "set: " + set, 1, set.size() );
        assertEquals( "set: " + set, 1, map.size() );
        for ( int i = 0; i < keys.length; i++ ) {
            if ( keys[i] == 42 ) {
                assertTrue( set.contains( keys[i] ) );
                assertTrue( map.containsKey( keys[i] ) );
            } else {
                assertFalse( set.contains( keys[i] ) );
                assertFalse( map.containsKey( keys[i] ) );
            }
        }
    }
View Full Code Here

    public void testKeySetRemoveAllTCollection() {
        int[] keys = {1138, 42, 86, 99, 101, 727, 117};
        long[] vals = new long[keys.length];

        TIntLongMap map = new TIntLongHashMap();
        for ( int i = 0; i < keys.length; i++ ) {
            vals[i] = keys[i] * 2;
            map.put( keys[i], vals[i] );
        }

        TIntSet set = map.keySet();
        assertEquals( map.size(), set.size() );
        assertFalse( set.isEmpty() );

        assertTrue( set.removeAll( set ) );
        assertTrue( set.isEmpty() );
       
        // repopulate the set.
        map = new TIntLongHashMap();
        for ( int i = 0; i < keys.length; i++ ) {
            vals[i] = keys[i] * 2;
            map.put( keys[i], vals[i] );
        }
        set = map.keySet();

        // With empty set
        TIntSet tintset = new TIntHashSet();
        assertFalse( "set: " + set + ", collection: " + tintset,
                set.removeAll( tintset ) );

        // With partial set
        tintset = new TIntHashSet( keys );
        tintset.remove( 42 );
        assertTrue( "set: " + set + ", collection: " + tintset,
                set.removeAll( tintset ) );
        assertEquals( "set: " + set, 1, set.size() );
        assertEquals( "set: " + set, 1, map.size() );
        for ( int i = 0; i < keys.length; i++ ) {
            if ( keys[i] == 42 ) {
                assertTrue( set.contains( keys[i] ) );
                assertTrue( map.containsKey( keys[i] ) );
            } else {
                assertFalse( set.contains( keys[i] ) );
                assertFalse( map.containsKey( keys[i] ) );
            }
        }

        // repopulate the set.
        map = new TIntLongHashMap();
        for ( int i = 0; i < keys.length; i++ ) {
            vals[i] = keys[i] * 2;
            map.put( keys[i], vals[i] );
        }
        set = map.keySet();

        // Empty list
        TIntCollection collection = new TIntArrayList();
        assertFalse( "set: " + set + ", collection: " + collection,
                set.removeAll( collection ) );

        // partial list
        collection = new TIntArrayList( keys );
        collection.remove( 42 );
        assertTrue( "set: " + set + ", collection: " + collection,
                set.removeAll( collection ) );
        assertEquals( "set: " + set, 1, set.size() );
        assertEquals( "set: " + set, 1, map.size() );
        for ( int i = 0; i < keys.length; i++ ) {
            if ( keys[i] == 42 ) {
                assertTrue( set.contains( keys[i] ) );
                assertTrue( map.containsKey( keys[i] ) );
            } else {
                assertFalse( set.contains( keys[i] ) );
                assertFalse( map.containsKey( keys[i] ) );
            }
        }
    }
View Full Code Here

    public void testKeySetRemoveAllArray() {
        int[] keys = {1138, 42, 86, 99, 101, 727, 117};
        long[] vals = new long[keys.length];

        TIntLongMap map = new TIntLongHashMap();
        for ( int i = 0; i < keys.length; i++ ) {
            vals[i] = keys[i] * 2;
            map.put( keys[i], vals[i] );
        }

        TIntSet set = map.keySet();
        assertEquals( map.size(), set.size() );
        assertFalse( set.isEmpty() );

        // test raw array
        map = new TIntLongHashMap();
        for ( int i = 0; i < keys.length; i++ ) {
            vals[i] = keys[i] * 2;
            map.put( keys[i], vals[i] );
        }
        set = map.keySet();

        keys[3] = keys[3] + 1;
        assertTrue( set.removeAll( keys ) );
        keys[3] = keys[3] - 1;

        assertEquals( "removed: " + keys[3] + ", set: " + set,
                1, set.size() );
        assertEquals( "removed: " + keys[3] + ", set: " + set
                      + "\nmap: " + map, set.size(), map.size() );
    }
View Full Code Here

    public void testKeySetForEach() {
        int[] keys = {1138, 42, 86, 99, 101, 727, 117};
        long[] vals = new long[keys.length];

        TIntLongMap map = new TIntLongHashMap();
        for ( int i = 0; i < keys.length; i++ ) {
            vals[i] = keys[i] * 2;
            map.put( keys[i], vals[i] );
        }

        TIntSet set = map.keySet();
        assertEquals( map.size(), set.size() );
        assertFalse( set.isEmpty() );

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

View Full Code Here

    public void testKeySetEquals() {
        int[] keys = {1138, 42, 86, 99, 101, 727, 117};
        long[] vals = new long[keys.length];

        TIntLongMap map = new TIntLongHashMap();
        for ( int i = 0; i < keys.length; i++ ) {
            vals[i] = keys[i] * 2;
            map.put( keys[i], vals[i] );
        }

        TIntSet set = map.keySet();
        assertEquals( map.size(), set.size() );
        assertFalse( set.isEmpty() );

        TIntSet other = new TIntHashSet();
        other.addAll( keys );

View Full Code Here

    public void testKeySetHashCode() {
        int[] keys = {1138, 42, 86, 99, 101, 727, 117};
        long[] vals = new long[keys.length];

        TIntLongMap map = new TIntLongHashMap();
        for ( int i = 0; i < keys.length; i++ ) {
            vals[i] = keys[i] * 2;
            map.put( keys[i], vals[i] );
        }

        TIntSet set = map.keySet();
        assertEquals( map.size(), set.size() );
        assertFalse( set.isEmpty() );
       

        TIntSet other = new TIntHashSet();
        other.addAll( keys );
View Full Code Here

    public void testKeySetIterator() {
        int[] keys = {1138, 42, 86, 99, 101, 727, 117};
        long[] vals = new long[keys.length];

        TIntLongMap map = new TIntLongHashMap();
        for ( int i = 0; i < keys.length; i++ ) {
            vals[i] = keys[i] * 2;
            map.put( keys[i], vals[i] );
        }

        TIntList list = new TIntArrayList( keys );
        TIntSet set = map.keySet();
        assertEquals( map.getNoEntryKey(), set.getNoEntryValue() );

        // test basic iterator function.
        TIntIterator iter = set.iterator();
        while ( iter.hasNext() ) {
            int key = iter.next();
            assertTrue( "key set should only contain keys: " + key + ", set; " + set,
                    list.contains( key ) );
        }

        assertFalse( iter.hasNext() );
        try {
            iter.next();
            fail( "Expect NoSuchElementException" );
        }
        catch ( NoSuchElementException ex ) {
            // Expected.
        }

        // Start over with new iterator -- test iter.remove()
        iter = set.iterator();
        while ( iter.hasNext() ) {
            int key = iter.next();
            assertTrue( "key set should only contain keys: " + key + ", set; " + set,
                    list.contains( key ) );
            if ( key == keys[3] ) {
                iter.remove();
                assertFalse( "set contains removed element: " + key + ", set: " + set,
                        set.contains( key ) );
            }
        }
        assertEquals( map.size(), set.size() );
        assertEquals( keys.length - 1, map.size() );
        assertEquals( map.getNoEntryValue(), map.get( keys[3] ) );
    }
View Full Code Here

        assertEquals( map.getNoEntryValue(), map.get( keys[3] ) );
    }


    public void testKeys() {
        TIntLongMap map = new TIntLongHashMap();

        map.put( KEY_ONE, 10 );
        map.put( KEY_TWO, 20 );

        assertEquals( 2, map.size() );

        int[] keys = map.keys( new int[map.size()] );
        assertEquals( 2, keys.length );
        TIntList keys_list = new TIntArrayList( keys );

        assertTrue( keys_list.contains( KEY_ONE ) );
        assertTrue( keys_list.contains( KEY_TWO ) );

        int[] keys2 = map.keys();
        assertEquals( 2, keys2.length );
        TIntList keys_list2 = new TIntArrayList( keys2 );

        assertTrue( keys_list2.contains( KEY_ONE ) );
        assertTrue( keys_list2.contains( KEY_TWO ) );

        int element_count = 20;
        map = new TIntLongHashMap();
        for ( int i = 0; i < element_count; i++ ) {
            map.put( i, i * i );
        }
        assertEquals( element_count, map.size() );
        keys = map.keys( new int[0] );
        Arrays.sort( keys );
        assertEquals( element_count, keys.length );
        for ( int i = 0; i < element_count; i++ ) {
            assertEquals( "expected: " + i + " got: " + keys[i] + ", i: " + i +
                          ", keys: " + Arrays.toString( keys ),  i, keys[i] );
            assertEquals( i * i, map.get( keys[i] ) );
        }
    }
View Full Code Here

TOP

Related Classes of gnu.trove.map.TIntLongMap

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.