下面列出了java.nio.IntBuffer#allocate ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public static void getShaderInfoLog(GL2ES2 gl, int shader_id, String info) {
if(shader_id==-1) return;
IntBuffer log_len = IntBuffer.allocate(1);
gl.glGetShaderiv(shader_id, GL2ES2.GL_INFO_LOG_LENGTH, log_len);
ByteBuffer buffer = ByteBuffer.allocate(log_len.get(0));
gl.glGetShaderInfoLog(shader_id, log_len.get(0), null, buffer);
String log = Charset.forName("US-ASCII").decode(buffer).toString();
if( log.length() > 1 && log.charAt(0) != 0){
System.out.println(info);
System.out.println(log);
}
}
@Test
public void T_byte_filter_6() throws IOException{
List<PrimitiveObject> dic = new ArrayList<PrimitiveObject>();
dic.add( new ByteObj( (byte) 10 ) );
dic.add( new ByteObj( (byte) 20 ) );
dic.add( new ByteObj( (byte) 30 ) );
dic.add( new ByteObj( (byte) 40 ) );
dic.add( new ByteObj( (byte) 50 ) );
IntBuffer buffer = IntBuffer.allocate( 100 );
for( int i = 0 ; i < 100 ; i++ ){
buffer.put( i % 5 );
}
ICellIndex index = new BufferDirectSequentialNumberCellIndex( ColumnType.BYTE , new TestDicManager( dic ) , buffer );
IFilter filter = new NumberFilter( NumberFilterType.GE , new ByteObj( (byte) 40 ) );
FilterdExpressionIndex result = new FilterdExpressionIndex( index.filter( filter , new boolean[100] ) );
assertEquals( result.size() , 40 );
for( int i = 0,n=0 ; n < 100 ; i+=2,n+=5 ){
assertEquals( result.get(i) , n+3 );
assertEquals( result.get(i+1) , n+4 );
}
}
@Test
public void T_short_filter_7() throws IOException{
List<PrimitiveObject> dic = new ArrayList<PrimitiveObject>();
dic.add( new ShortObj( (short) 1000 ) );
dic.add( new ShortObj( (short) 2000 ) );
dic.add( new ShortObj( (short) 3000 ) );
dic.add( new ShortObj( (short) 4000 ) );
dic.add( new ShortObj( (short) 5000 ) );
IntBuffer buffer = IntBuffer.allocate( 100 );
for( int i = 0 ; i < 100 ; i++ ){
buffer.put( i % 5 );
}
ICellIndex index = new BufferDirectSequentialNumberCellIndex( ColumnType.SHORT , new TestDicManager( dic ) , buffer );
IFilter filter = new NumberFilter( NumberFilterType.GE , new LongObj( Long.valueOf( Short.MAX_VALUE ) + (long)1 ) );
assertEquals( null , index.filter( filter , new boolean[100] ) );
}
@Test
public void T_short_filter_6() throws IOException{
List<PrimitiveObject> dic = new ArrayList<PrimitiveObject>();
dic.add( new ShortObj( (short) 1000 ) );
dic.add( new ShortObj( (short) 2000 ) );
dic.add( new ShortObj( (short) 3000 ) );
dic.add( new ShortObj( (short) 4000 ) );
dic.add( new ShortObj( (short) 5000 ) );
IntBuffer buffer = IntBuffer.allocate( 100 );
for( int i = 0 ; i < 100 ; i++ ){
buffer.put( i % 5 );
}
ICellIndex index = new BufferDirectSequentialNumberCellIndex( ColumnType.SHORT , new TestDicManager( dic ) , buffer );
IFilter filter = new NumberFilter( NumberFilterType.GE , new ShortObj( (short) 4000 ) );
FilterdExpressionIndex result = new FilterdExpressionIndex( index.filter( filter , new boolean[100] ) );
assertEquals( result.size() , 40 );
for( int i = 0,n=0 ; n < 100 ; i+=2,n+=5 ){
assertEquals( result.get(i) , n+3 );
assertEquals( result.get(i+1) , n+4 );
}
}
@Override
public IntBuffer getIndexIntBuffer(
final byte[] buffer ,
final int start ,
final int length ,
ByteOrder order ) throws IOException {
int size = length / Integer.BYTES;
IReadSupporter wrapBuffer =
ByteBufferSupporterFactory.createReadSupporter( buffer , start , length , order );
IntBuffer result = IntBuffer.allocate( size );
for ( int i = 0 ; i < size ; i++ ) {
result.put( wrapBuffer.getInt() );
}
result.position( 0 );
return result;
}
@Test
public void T_byte_filter_1() throws IOException{
List<PrimitiveObject> dic = new ArrayList<PrimitiveObject>();
dic.add( new ByteObj( (byte) 10 ) );
dic.add( new ByteObj( (byte) 20 ) );
dic.add( new ByteObj( (byte) 30 ) );
dic.add( new ByteObj( (byte) 40 ) );
dic.add( new ByteObj( (byte) 50 ) );
IntBuffer buffer = IntBuffer.allocate( 100 );
for( int i = 0 ; i < 100 ; i++ ){
buffer.put( i % 5 );
}
ICellIndex index = new BufferDirectSequentialNumberCellIndex( ColumnType.BYTE , new TestDicManager( dic ) , buffer );
IFilter filter = new NumberFilter( NumberFilterType.EQUAL , new ByteObj( (byte) 10 ) );
FilterdExpressionIndex result = new FilterdExpressionIndex( index.filter( filter , new boolean[100] ) );
assertEquals( result.size() , 20 );
for( int i = 0,n=0 ; n < 100 ; i++,n+=5 ){
assertEquals( result.get(i) , n );
}
}
@Test
public void T_byte_filter_1() throws IOException{
List<PrimitiveObject> dic = new ArrayList<PrimitiveObject>();
dic.add( new ByteObj( (byte) 10 ) );
dic.add( new ByteObj( (byte) 20 ) );
dic.add( new ByteObj( (byte) 30 ) );
dic.add( new ByteObj( (byte) 40 ) );
dic.add( new ByteObj( (byte) 50 ) );
IntBuffer buffer = IntBuffer.allocate( 100 );
for( int i = 0 ; i < 100 ; i++ ){
buffer.put( i % 5 );
}
ICellIndex index = new BufferDirectSequentialNumberCellIndex( ColumnType.BYTE , new TestDicManager( dic ) , buffer );
IFilter filter = new NumberFilter( NumberFilterType.EQUAL , new ByteObj( (byte) 10 ) );
FilterdExpressionIndex result = new FilterdExpressionIndex( index.filter( filter , new boolean[100] ) );
assertEquals( result.size() , 20 );
for( int i = 0,n=0 ; n < 100 ; i++,n+=5 ){
assertEquals( result.get(i) , n );
}
}
@Test
public void T_byte_filter_6() throws IOException{
List<PrimitiveObject> dic = new ArrayList<PrimitiveObject>();
dic.add( new ByteObj( (byte) 10 ) );
dic.add( new ByteObj( (byte) 20 ) );
dic.add( new ByteObj( (byte) 30 ) );
dic.add( new ByteObj( (byte) 40 ) );
dic.add( new ByteObj( (byte) 50 ) );
IntBuffer buffer = IntBuffer.allocate( 100 );
for( int i = 0 ; i < 100 ; i++ ){
buffer.put( i % 5 );
}
ICellIndex index = new BufferDirectSequentialNumberCellIndex( ColumnType.BYTE , new TestDicManager( dic ) , buffer );
IFilter filter = new NumberFilter( NumberFilterType.GE , new ByteObj( (byte) 40 ) );
FilterdExpressionIndex result = new FilterdExpressionIndex( index.filter( filter , new boolean[100] ) );
assertEquals( result.size() , 40 );
for( int i = 0,n=0 ; n < 100 ; i+=2,n+=5 ){
assertEquals( result.get(i) , n+3 );
assertEquals( result.get(i+1) , n+4 );
}
}
private void LoadPathNodeFile(byte rx,byte ry)
{
String fname = "./data/pathnode/"+rx+"_"+ry+".pn";
short regionoffset = getRegionOffset(rx,ry);
_log.info("PathFinding Engine: - Loading: "+fname+" -> region offset: "+regionoffset+"X: "+rx+" Y: "+ry);
File Pn = new File(fname);
int node = 0,size, index = 0;
try {
// Create a read-only memory-mapped file
FileChannel roChannel = new RandomAccessFile(Pn, "r").getChannel();
size = (int)roChannel.size();
MappedByteBuffer nodes;
if (Config.FORCE_GEODATA) //Force O/S to Loads this buffer's content into physical memory.
//it is not guarantee, because the underlying operating system may have paged out some of the buffer's data
nodes = roChannel.map(FileChannel.MapMode.READ_ONLY, 0, size).load();
else
nodes = roChannel.map(FileChannel.MapMode.READ_ONLY, 0, size);
// Indexing pathnode files, so we will know where each block starts
IntBuffer indexs = IntBuffer.allocate(65536);
while(node < 65536)
{
byte layer = nodes.get(index);
indexs.put(node, index);
node++;
index += layer*10+1;
}
_pathNodesIndex.put(regionoffset, indexs);
_pathNodes.put(regionoffset, nodes);
} catch (Exception e)
{
e.printStackTrace();
_log.warning("Failed to Load PathNode File: "+fname+"\n");
}
}
public static void getProgramValidateStatus(GL2ES2 gl, int program_id) {
if(program_id==-1) return;
IntBuffer log_len = IntBuffer.allocate(1);
gl.glGetProgramiv(program_id, GL2ES2.GL_VALIDATE_STATUS, log_len);
ByteBuffer buffer = ByteBuffer.allocate(log_len.get(0));
gl.glGetProgramInfoLog(program_id, log_len.get(0), null, buffer);
String log = Charset.forName("US-ASCII").decode(buffer).toString();
if( log.length() > 1 && log.charAt(0) != 0){
System.out.println(log);
}
}
public OpusDecoder(int sampleRate, int frameSize, int channels) {
this.channels = channels;
this.sampleRate = sampleRate;
this.frameSize = frameSize;
IntBuffer errorBuffer = IntBuffer.allocate(1);
decoder = Opus.INSTANCE.opus_decoder_create(
sampleRate,
channels,
errorBuffer
);
OpusUtil.checkError("opus_decoder_create", errorBuffer.get());
}
protected static IntBuffer allocateIntBuffer(int size) {
if (USE_DIRECT_BUFFERS) {
return allocateDirectIntBuffer(size);
} else {
return IntBuffer.allocate(size);
}
}
public static String[] listSymbolNames(Pointer symbol) {
IntBuffer size = IntBuffer.allocate(1);
PointerByReference ref = new PointerByReference();
checkCall(LIB.NNSymbolListInputNames(symbol, 0, size, ref));
return toStringArray(ref, size.get());
}
@Override
public IntBuffer getIndexIntBuffer( final byte[] buffer , final int start , final int length , final ByteOrder order ) throws IOException{
int size = length / Byte.BYTES;
IReadSupporter wrapBuffer = ByteBufferSupporterFactory.createReadSupporter( buffer , start , length , order );
IntBuffer result = IntBuffer.allocate( size );
for( int i = 0 ; i < size ; i++ ){
result.put( NumberToBinaryUtils.getUnsignedByteToInt( wrapBuffer.getByte() ) );
}
result.position( 0 );
return result;
}
/**
* Construct double array trie which is equivalent to input trie
*
* @param trie normal trie, which contains all dictionary words
*/
public void build(Trie trie) {
ProgressLog.begin("building " + (compact ? "compact" : "sparse") + " trie");
baseBuffer = IntBuffer.allocate(BASE_CHECK_INITIAL_SIZE);
baseBuffer.put(0, 1);
checkBuffer = IntBuffer.allocate(BASE_CHECK_INITIAL_SIZE);
tailBuffer = CharBuffer.allocate(TAIL_INITIAL_SIZE);
add(-1, 0, trie.getRoot());
reportUtilizationRate();
ProgressLog.end();
}
public BufferObject(final int size) {
buf = IntBuffer.allocate(size);
}
@Override
public int glGetQueryObjectiv(int query, int pname) {
IntBuffer buff = IntBuffer.allocate(1);
GLES30.glGetQueryiv(query, pname, buff);
return buff.get(0);
}
public BufferObject(final int size) {
buf = IntBuffer.allocate(size);
}
@Override
public IntBuffer allocateBuffer(long[] shape) {
return IntBuffer.allocate(calculateCapacityForShape(shape));
}
public synchronized static int[] glGetIntegerv(int value, int size) {
final IntBuffer buffer = IntBuffer.allocate(size);
GLES10.glGetIntegerv(value, buffer);
return buffer.array();
}