Examples of TIntLongHashMap


Examples of gnu.trove.map.hash.TIntLongHashMap

    public void testValueCollectionIterator() {
        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] = Long.valueOf( keys[i] * 2 );
            raw_map.put( keys[i], vals[i] );
        }
        Map<Integer,Long> map = TDecorators.wrap( raw_map );

        List<Long> list = Arrays.asList( vals );
        Collection<Long> set = map.values();
View Full Code Here

Examples of gnu.trove.map.hash.TIntLongHashMap

        assertNull( map.get( keys[3] ) );
    }


    public void testValues() {
        TIntLongMap raw_map = new TIntLongHashMap();
        Map<Integer,Long> map = TDecorators.wrap( raw_map );

        map.put( KEY_ONE, Long.valueOf( 1 ) );
        map.put( KEY_TWO, Long.valueOf( 2 ) );

        assertEquals( 2, map.size() );

        Long[] values = map.values().toArray( new Long[map.size()] );
        assertEquals( 2, values.length );
        List values_list = Arrays.asList( values );

        assertTrue( values_list.contains( Long.valueOf( 1 ) ) );
        assertTrue( values_list.contains( Long.valueOf( 2 ) ) );

        Long[] values2 = map.values().toArray( new Long[map.size()] );
        assertEquals( 2, values2.length );
        List<Long> keys_list2 = Arrays.asList( values2 );

        assertTrue( keys_list2.contains( Long.valueOf( 1 ) ) );
        assertTrue( keys_list2.contains( Long.valueOf( 2 ) ) );

        int element_count = 20;
        raw_map = new TIntLongHashMap( 20, 0.5f, Integer.MIN_VALUE, Long.MIN_VALUE );
        map = TDecorators.wrap( raw_map );
        for ( int i = 0; i < element_count; i++ ) {
            map.put( i, Long.valueOf( i * i ) );
        }
        assertEquals( element_count, map.size() );
View Full Code Here

Examples of gnu.trove.map.hash.TIntLongHashMap

        int element_count = 20;
        Integer[] keys = new Integer[element_count];
        Long[] vals = new Long[element_count];

        TIntLongMap raw_map =
                new TIntLongHashMap( element_count, 0.5f, Integer.MIN_VALUE, Long.MIN_VALUE );
        Map<Integer,Long> map = TDecorators.wrap( raw_map );

        for ( int i = 0; i < element_count; i++ ) {
            keys[i] = Integer.valueOf( i + 1 );
            vals[i] = Long.valueOf( i + 1 );
View Full Code Here

Examples of gnu.trove.map.hash.TIntLongHashMap

    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
        raw_unequal = new TIntLongHashMap( raw_map );
        unequal = TDecorators.wrap( raw_unequal );
        map.put( 13, Long.valueOf( 26 ) );
        assertFalse( map.equals( unequal ) );
    }
View Full Code Here

Examples of gnu.trove.map.hash.TIntLongHashMap

    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.hash.TIntLongHashMap

    }



    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.hash.TIntLongHashMap

    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.hash.TIntLongHashMap

        assertEquals( map, deserialized );
    }

    public void testBug3432212A() throws Exception {
        Map<Integer, Long> trove = new TIntLongMapDecorator(new TIntLongHashMap());
        trove.put(null, 1L);
        assertFalse(trove.isEmpty());
        assertEquals(1, trove.size());
        assertEquals(1, trove.entrySet().size());
        assertEquals(1, trove.keySet().size());
View Full Code Here

Examples of gnu.trove.map.hash.TIntLongHashMap

        assertEquals(1, trove.keySet().size());
        assertEquals(null, trove.keySet().iterator().next());
    }

    public void testBug3432212B() throws Exception {
        Map<Integer, Long> trove = new TIntLongMapDecorator(new TIntLongHashMap());
        trove.put(1, null);
        assertFalse(trove.isEmpty());
        assertEquals(1, trove.size());
        assertEquals(1, trove.entrySet().size());
        assertEquals(1, trove.keySet().size());
View Full Code Here

Examples of gnu.trove.map.hash.TIntLongHashMap

    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
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.