Package gnu.trove.list.array

Examples of gnu.trove.list.array.TLongArrayList$TLongArrayIterator


     * specified capacity.
     *
     * @param capacity the initial depth of the stack
     */
    public TLongArrayStack( int capacity ) {
        _list = new TLongArrayList( capacity );
    }
View Full Code Here


     *
     * @param capacity the initial depth of the stack
     * @param no_entry_value value that represents null
     */
    public TLongArrayStack( int capacity, long no_entry_value ) {
        _list = new TLongArrayList( capacity, no_entry_value );
    }
View Full Code Here

     * @param stack the instance to copy
     */
    public TLongArrayStack( TLongStack stack ) {
        if ( stack instanceof TLongArrayStack ) {
            TLongArrayStack array_stack = ( TLongArrayStack ) stack;
            this._list = new TLongArrayList( array_stack._list );
        } else {
            throw new UnsupportedOperationException( "Only support TLongArrayStack" );
        }
    }
View Full Code Here

     * @return
     * @throws Exception
     */
    protected static long [] getTargetIds(String inputFile) throws Exception
    {
        TLongArrayList tmp = new TLongArrayList();
        BufferedReader reader = null;
        try
        {
            reader = new BufferedReader(new FileReader(inputFile));
            String line = "";
            while((line = reader.readLine()) != null)
            {
                tmp.add(Long.parseLong(line.trim()));
            }
        }
        finally
        {
            if(reader != null) reader.close();
        }
        return tmp.toArray();
    }
View Full Code Here

        return bitsetList.toArray(new Signature[bitsetList.size()]);
    }
   
    public long [] getSimilars(Signature search, int beamRadius, Signature [] items, Comparator<Signature> comparator)
    {
        TLongArrayList retval = new TLongArrayList();
       
        int idx = Arrays.binarySearch(items, search, comparator);
        int bottom = Math.max(idx-beamRadius, 0);
        int top = Math.min(idx+beamRadius, items.length);
       
        for(int i = bottom; i < top; i++)
        {
            retval.add(items[i].id);
        }
        return retval.toArray();
    }
View Full Code Here

        // test with a TCollection
        TLongSet tintset = new TLongHashSet( vals );
        assertFalse( "values: " + values + ", collection: " + tintset,
                values.retainAll( tintset ) );
        TLongCollection collection = new TLongArrayList( vals );
        assertFalse( "values: " + values + ", collection: " + collection,
                values.retainAll( collection ) );

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

            map.put( keys[i], vals[i] );
        }
        values = map.valueCollection();

        // Empty list
        TLongCollection collection = new TLongArrayList();
        assertFalse( "values: " + values + ", collection: " + collection,
                values.removeAll( collection ) );

        // partial list
        collection = new TLongArrayList( vals );
        collection.remove( 42 * 2 );
        assertTrue( "values: " + values + ", collection: " + collection,
                values.removeAll( collection ) );
        assertEquals( "values: " + values, 1, values.size() );
        assertEquals( "values: " + values, 1, map.size() );
        for ( int i = 0; i < keys.length; i++ ) {
View Full Code Here

        TLongCollection values = map.valueCollection();
        assertEquals( map.size(), values.size() );
        assertFalse( values.isEmpty() );

        class ForEach implements TLongProcedure {
            TLongList built = new TLongArrayList();


            public boolean execute( long value ) {
                built.add( value );
                return true;
            }

            TLongList getBuilt() {
                return built;
            }
        }

        ForEach foreach = new ForEach();
        values.forEach( foreach );
        TLongList built = foreach.getBuilt();
        for ( int i = 0; i < values.size(); i++ ) {
            assertTrue( values.contains( built.get( i ) ) );
        }
    }
View Full Code Here

        TLongCollection values = map.valueCollection();
        assertEquals( map.size(), values.size() );
        assertFalse( values.isEmpty() );
        assertEquals( values, values );
        TLongList values_list = new TLongArrayList( values );
        assertFalse( "collections should not be equal: " + values + ", " + values_list,
                values.equals( values_list ) );

        TLongList list = new TLongArrayList( vals );
        values_list.sort();
        list.sort();
        assertTrue( "collections incorrectly not equal: " + values_list + ", " + list,
                values_list.equals( list ) );
        assertTrue( "collections incorrectly not equal: " + values_list + ", " + list,
                values_list.equals( list ) );


        long[] mismatched = {72, 49, 53, 1024, 999};
        TLongCollection unequal = new TLongArrayList();
        unequal.addAll( mismatched );

        assertFalse( "collections incorrectly equal: " + values_list + ", " + unequal,
                values_list.equals( unequal ) );

        // Change length, different code branch
        unequal.add( 1 );
        assertFalse( "collections incorrectly equal: " + values_list + ", " + unequal,
                values_list.equals( unequal ) );

        assertFalse( "values incorrectly equals a random object",
                values_list.equals( new Object() ) );

        // value in map twice, in list twice.
        list = new TLongArrayList( vals );
        map.put( 1, vals[0] );
        values_list = new TLongArrayList( map.valueCollection() );
        list.add( vals[0] );
        values_list.sort();
        list.sort();
        assertTrue( "collections incorrectly not equal: " + values_list + ", " + list,
                values_list.equals( list ) );

        // value in the map twice, same length list, but value only in list once.
        list = new TLongArrayList( vals );
        list.add( -1 );
        list.sort();       
        assertFalse( "collections incorrectly equal: " + values_list + ", " + list,
                values_list.equals( list ) );
    }
View Full Code Here

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

        TLongList list = new TLongArrayList( vals );
        TLongCollection set = map.valueCollection();
        assertEquals( map.getNoEntryValue(), set.getNoEntryValue() );

        // test basic iterator function.
        TLongIterator iter = set.iterator();
        while ( iter.hasNext() ) {
            long val = iter.next();
            assertTrue( "value collection should only contain values: " + val + ", set; " + set,
                    list.contains( val ) );
        }

        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() ) {
            long val = iter.next();
            assertTrue( "value collection should only contain values: " + val + ", set; " + set,
                    list.contains( val ) );
            if ( val == vals[3] ) {
                iter.remove();
                assertFalse( "set contains removed element: " + val + ", set: " + set,
                        set.contains( val ) );
            }
View Full Code Here

TOP

Related Classes of gnu.trove.list.array.TLongArrayList$TLongArrayIterator

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.