Examples of TIntLongMap


Examples of gnu.trove.map.TIntLongMap

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

        TIntLongMap raw_map = new TIntLongHashMap();
        for ( int i = 0; i < keys.length; i++ ) {
            vals[i] = keys[i] * 2;
            raw_map.put( keys[i], vals[i] );
        }
        Map<Integer,Long> map = TDecorators.wrap( raw_map );
        assertEquals( map, map );

        TIntIntMap raw_int_map = new TIntIntHashMap();
        for ( int i = 0; i < keys.length; i++ ) {
            raw_int_map.put( keys[i], (int) vals[i] );
        }
        Map<Integer,Integer> int_map = TDecorators.wrap( raw_int_map );
        assertFalse( map.equals( int_map ) );

        // Change a value..
        TIntLongMap raw_unequal = new TIntLongHashMap( raw_map );
        Map<Integer,Long> unequal = TDecorators.wrap( raw_unequal );
        map.put( keys[3], vals[3] + 1 );
        assertFalse( map.equals( unequal ) );

        // Change length
View Full Code Here

Examples of gnu.trove.map.TIntLongMap

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

        TIntLongMap raw_map = new TIntLongHashMap();
        for ( int i = 0; i < keys.length; i++ ) {
            vals[i] = keys[i] * 2;
            raw_map.put( keys[i], vals[i] );
        }
        Map<Integer,Long> map = TDecorators.wrap( raw_map );

        TIntLongMap raw_other = new TIntLongHashMap();
        Map<Integer,Long> other = TDecorators.wrap( raw_other );
        other.putAll( map );
        assertTrue( "hashcodes incorrectly not equal: " + map + ", " + other,
                map.hashCode() == other.hashCode() );

        TIntLongMap raw_unequal = new TIntLongHashMap();
        for ( int key : keys ) {
            raw_unequal.put( key, key );
        }
        Map<Integer,Long> unequal = TDecorators.wrap( raw_unequal );
        assertFalse( "hashcodes unlikely equal: " + map + ", " + unequal,
                map.hashCode() == unequal.hashCode() );

        int[] raw_mismatched = {72, 49, 53, 1024, 999};
        TIntLongMap raw_mismatched_map = new TIntLongHashMap();
        for ( int aRaw_mismatched : raw_mismatched ) {
            raw_mismatched_map.put( aRaw_mismatched, Long.valueOf( aRaw_mismatched * 37 ) );
        }
        Map<Integer,Long> mismatched = TDecorators.wrap( raw_mismatched_map );
        assertFalse( "hashcodes unlikely equal: " + map + ", " + mismatched,
                map.hashCode() == mismatched.hashCode() );
    }
View Full Code Here

Examples of gnu.trove.map.TIntLongMap

    }



    public void testToString() {
        TIntLongMap raw_map = new TIntLongHashMap();
        Map<Integer,Long> map = TDecorators.wrap( raw_map );
        map.put( 11, Long.valueOf( 1 ) );
        map.put( 22, Long.valueOf( 2 ) );

        String to_string = map.toString();
View Full Code Here

Examples of gnu.trove.map.TIntLongMap

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

        TIntLongMap raw_map = new TIntLongHashMap();
        for ( int i = 0; i < keys.length; i++ ) {
            vals[i] = keys[i] * 2;
            raw_map.put( keys[i], vals[i] );
        }
        Map<Integer,Long> map = TDecorators.wrap( raw_map );

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream( baos );
View Full Code Here

Examples of gnu.trove.map.TIntLongMap

    public void testConstructors() {

        int[] keys = {1138, 42, 86, 99, 101};
        long[] vals = {1138, 42, 86, 99, 101};

        TIntLongMap raw_map = new TIntLongHashMap();
        for ( int i = 0; i < keys.length; i++ ) {
            raw_map.put( keys[i], vals[i] );
        }
        Map<Integer,Long> map = TDecorators.wrap( raw_map );
        assertEquals( keys.length, map.size() );

        TIntLongMap raw_capacity = new TIntLongHashMap( 20 );
        for ( int i = 0; i < keys.length; i++ ) {
            raw_capacity.put( keys[i], vals[i] );
        }
        Map<Integer,Long> capacity = TDecorators.wrap( raw_capacity );
        assertEquals( keys.length, capacity.size() );

        TIntLongMap raw_cap_and_factor = new TIntLongHashMap( 20, 0.75f );
        for ( int i = 0; i < keys.length; i++ ) {
            raw_cap_and_factor.put( keys[i], vals[i] );
        }
        Map<Integer,Long> cap_and_factor = TDecorators.wrap( raw_cap_and_factor );
        assertEquals( keys.length, cap_and_factor.size() );

        TIntLongMap raw_fully_specified =
                new TIntLongHashMap( 20, 0.5f, Integer.MIN_VALUE, Long.MIN_VALUE );
        for ( int i = 0; i < keys.length; i++ ) {
            raw_fully_specified.put( keys[i], vals[i] );
        }
        Map<Integer,Long> fully_specified = TDecorators.wrap( raw_fully_specified );
        assertEquals( keys.length, fully_specified.size() );

        TIntLongMap raw_copy = new TIntLongHashMap( raw_map );
        Map<Integer,Long> copy = TDecorators.wrap( raw_copy );
        assertEquals( keys.length, fully_specified.size() );

        TIntLongMap raw_arrays = new TIntLongHashMap( keys, vals );
        Map<Integer,Long> arrays = TDecorators.wrap( raw_arrays );
        assertEquals( keys.length, arrays.size() );


        // Equals in all combinations is paranoid.. but..
View Full Code Here

Examples of gnu.trove.map.TIntLongMap

    public void testGet() {
        int element_count = 20;
        int[] keys = new int[element_count];
        Long[] vals = new Long[element_count];

        TIntLongMap raw_map = new TIntLongHashMap();
        for ( int i = 0; i < element_count; i++ ) {
            keys[i] = i + 1;
            vals[i] = Long.valueOf( i + 1 );
            raw_map.put( keys[i], vals[i] );
        }
        Map<Integer,Long> map = TDecorators.wrap( raw_map );

        assertEquals( vals[10], map.get( Integer.valueOf( keys[10] ) ) );
        assertNull( map.get( Integer.valueOf( 1138 ) ) );
View Full Code Here

Examples of gnu.trove.map.TIntLongMap

        for ( int i = 0; i < size; i++ ) {
            keys[i] = i + 1;
            vals[i] = keys[i] * 2;
        }

        TIntLongMap raw_map = new TIntLongHashMap();
        for ( int i = 0; i < keys.length; i++ ) {
            raw_map.put( keys[i], vals[i] );
        }
        Map<Integer,Long> map = TDecorators.wrap( raw_map );
        assertEquals( keys.length, map.size() );
        for ( int i = 0; i < keys.length; i++ ) {
            Integer key = keys[i];
View Full Code Here

Examples of gnu.trove.map.TIntLongMap

    public void testPutAll() {
        int[] keys = {1138, 42, 86, 99, 101};
        long[] vals = {1138, 42, 86, 99, 101};

        TIntLongMap raw_map = new TIntLongHashMap();
        for ( int i = 0; i < keys.length; i++ ) {
            raw_map.put( keys[i], vals[i] * 2 );
        }
        Map<Integer,Long> map = TDecorators.wrap( raw_map );
        assertEquals( keys.length, map.size() );

        TIntLongMap target = new TIntLongHashMap();
        target.put( 1, 2 );
        assertEquals( 1, target.size() );

        target.putAll( map );
        assertEquals( keys.length + 1, target.size() );
        for ( int i = 0; i < keys.length; i++ ) {
            assertEquals( vals[i] * 2, target.get( keys[i] ) );
        }
        assertEquals( 2, target.get( 1 ) );


        // java.util.Map source
        Map<Integer, Long> java_map = new HashMap<Integer, Long>();
        for ( int i = 0; i < keys.length; i++ ) {
            java_map.put( keys[i], vals[i] * 2 );
        }

        // fresh TIntLongMap
        target = new TIntLongHashMap();
        target.put( 1, 2 );
        assertEquals( 1, target.size() );

        target.putAll( java_map );
        assertEquals( "map size is incorrect: " + keys.length + ", source: " +
                      java_map + ", target: " + target,
                keys.length + 1, target.size() );
        for ( int i = 0; i < keys.length; i++ ) {
            assertEquals( vals[i] * 2, target.get( keys[i] ) );
        }
        assertEquals( 2, target.get( 1 ) );
    }
View Full Code Here

Examples of gnu.trove.map.TIntLongMap

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

        TIntLongMap raw_map = new TIntLongHashMap();
        for ( int i = 0; i < keys.length; i++ ) {
            vals[i] = keys[i] * 2;
            raw_map.put( keys[i], vals[i] );
        }
        Map<Integer,Long> map = TDecorators.wrap( raw_map );

        Set<Integer> set = map.keySet();
        assertEquals( map.size(), set.size() );
View Full Code Here

Examples of gnu.trove.map.TIntLongMap

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

        TIntLongMap raw_map = new TIntLongHashMap();
        for ( int i = 0; i < keys.length; i++ ) {
            vals[i] = keys[i] * 2;
            raw_map.put( keys[i], vals[i] );
        }
        Map<Integer,Long> map = TDecorators.wrap( raw_map );

        Set<Integer> set = map.keySet();
        assertEquals( map.size(), set.size() );
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.