@Override public void addGap( ) { indexByRow.append( -1 ); }
@Override public void addGap( ) { data.append( -1 ); } }
@Override public void append( int[] vs ) { append( vs, 0, vs.length ); }
@Override public void addData( DataInputStream in ) throws IOException { data.append( in.readInt( ) ); } }
@Override public void addData( String value ) { offsets.append( allStrings.n ); if ( value != null ) { allStrings.append( value ); } }
@Override public void append( IntBuffer vs ) { append( vs, vs.remaining( ) ); }
@Override public void append( Ints vs ) { append( vs, 0, vs.n( ) ); }
public static Map<String, IntsArray> partitionUnique( String[] data ) { Map<String, IntsArray> unique = new LinkedHashMap<String, IntsArray>( ); for ( int i = 0; i < data.length; i++ ) { String s = data[i]; if ( s != null ) { IntsArray index = unique.get( s ); if ( index == null ) { index = new IntsArray( ); unique.put( s, index ); } index.append( i ); } } return unique; }
public static Map<Strings, IntsArray> partitionUnique( String[]... data ) { Map<Strings, IntsArray> unique = new LinkedHashMap<Strings, IntsArray>( ); int nfields = data.length; int size = data[0].length; Strings s = new Strings( nfields ); for ( int i = 0; i < size; i++ ) { for ( int j = 0; j < nfields; j++ ) s.strings[j] = data[j][i]; IntsArray index = unique.get( s ); if ( index == null ) { index = new IntsArray( ); unique.put( s.copy( ), index ); } index.append( i ); } return unique; }
@Override public void addData( String value ) { // We don't want to store a substring, which might hang on // to more characters than it needs. So make a clean copy. value = new String( value ); int index = indexByString.getInt( value ); if ( index == -1 ) { index = indexByString.size( ); indexByString.put( value, index ); } indexByRow.append( index ); }
public static int createProgram( GL2ES2 gl, String vertSource, String geomSource, String fragSource ) { IntsArray shaders = new IntsArray( ); try { if ( vertSource != null ) shaders.append( compileShader( gl, GL_VERTEX_SHADER, vertSource ) ); if ( geomSource != null ) shaders.append( compileShader( gl, GL_GEOMETRY_SHADER, geomSource ) ); if ( fragSource != null ) shaders.append( compileShader( gl, GL_FRAGMENT_SHADER, fragSource ) ); return linkProgram( gl, shaders.a ); } finally { for ( int i = 0; i < shaders.n; i++ ) { gl.glDeleteShader( shaders.v( i ) ); } } }
@Override public void addData( String token ) throws DsplException { if ( token.isEmpty( ) ) { addGap( ); } else { try { data.append( Integer.parseInt( token ) ); } catch ( NumberFormatException e ) { if ( dsplParser.isFailOnErrorMode( ) ) { throw new DsplException( "Problem parsing: %s", e, token ); } else { logWarning( logger, "Problem parsing token %s as type integer. Adding gap instead.", token ); addGap( ); } } } }
/** * If {@code x(v)} or {@code y(v)} returns {@code NaN}, this method returns * immediately without adding {@code v} to the tree. */ public void add( int v ) { float x = x( v ); if ( Float.isNaN( x ) ) return; float y = y( v ); if ( Float.isNaN( y ) ) return; LeafNode<Bucket> leaf = leaf( x, y ); Bucket bucket = leaf.bucket; // The default return value for bucket.dupes is set to bucket.singles, // so iff bucket.dupes does not contain xyKey, we will end up appending // to bucket.singles -- which is exactly what we want. // // This is confusing to read, but it avoids double-checking the "contains // key?" condition. The map is already doing the check for us -- not worth // doing the same check again. // long xyKey = xyToKey( x, y ); bucket.dupes.get( xyKey ).append( v ); if ( bucketSize( bucket ) > maxBucketSize ) { compactBucket( bucket ); if ( bucketSize( bucket ) > 0.9 * maxBucketSize ) splitLeaf( leaf ); } }
@Override protected Bucket[] splitBucket( Bucket bucket, float xDivider, float yDivider ) { Bucket[] newBuckets = new Bucket[4]; for ( int q = 0; q < newBuckets.length; q++ ) newBuckets[q] = new Bucket( ); int[] a = bucket.singles.a; int n = bucket.singles.n; for ( int i = 0; i < n; i++ ) { int v = a[i]; int q = quadrant( xDivider, yDivider, x( v ), y( v ) ); newBuckets[q].singles.append( v ); } Long2ObjectOpenHashMap<IntsArray> dupes = bucket.dupes; for ( Entry<IntsArray> en : dupes.long2ObjectEntrySet( ) ) { long xyKey = en.getLongKey( ); IntsArray vs = en.getValue( ); int q = quadrant( xDivider, yDivider, xFromKey( xyKey ), yFromKey( xyKey ) ); newBuckets[q].dupes.put( xyKey, vs ); } return newBuckets; }