本文整理汇总了Java中water.util.UnsafeUtils类的典型用法代码示例。如果您正苦于以下问题:Java UnsafeUtils类的具体用法?Java UnsafeUtils怎么用?Java UnsafeUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
UnsafeUtils类属于water.util包,在下文中一共展示了UnsafeUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: CStrChunk
import water.util.UnsafeUtils; //导入依赖的package包/类
public CStrChunk(int sslen, byte[] ss, int sparseLen, int idxLen, int[] strIdx, boolean isAllASCII) {
_start = -1;
_valstart = _OFF + (idxLen<<2);
_isAllASCII = isAllASCII;
set_len(idxLen);
_mem = MemoryManager.malloc1(CStrChunk._OFF + idxLen*4 + sslen, false);
UnsafeUtils.set4(_mem, 0, CStrChunk._OFF + idxLen * 4); // location of start of strings
if (_isAllASCII) UnsafeUtils.set1(_mem, 4, (byte)1); // use byte to store _isAllASCII
else UnsafeUtils.set1(_mem, 4, (byte)0);
for( int i = 0; i < sparseLen; ++i )
UnsafeUtils.set4(_mem, CStrChunk._OFF + 4*i, strIdx[i]);
for( int i = sparseLen; i < idxLen; ++i ) // set NAs
UnsafeUtils.set4(_mem, CStrChunk._OFF + 4*i, -1);
for( int i = 0; i < sslen; ++i )
_mem[CStrChunk._OFF + idxLen*4 + i] = ss[i];
}
示例2: asciiTrim
import water.util.UnsafeUtils; //导入依赖的package包/类
/**
* Optimized trim() method to operate across the entire CStrChunk buffer in one pass.
* This mimics Java String.trim() by only considering characters of value
* <code>'\u0020'</code> or less as whitespace to be trimmed. This means that like
* Java's String.trim() it ignores 16 of the 17 characters regarded as a space in UTF.
*
* NewChunk is the same size as the original, despite trimming.
*
* @param nc NewChunk to be filled with trimmed version of strings in this chunk
* @return Filled NewChunk
*/
public NewChunk asciiTrim(NewChunk nc) {
// copy existing data
nc = this.inflate_impl(nc);
//update offsets and byte array
for(int i=0; i < _len; i++) {
int j = 0;
int off = UnsafeUtils.get4(_mem,(i<<2)+_OFF);
if (off != NA) {
//UTF chars will appear as negative values. In Java spec, space is any char 0x20 and lower
while( _mem[_valstart+off+j] > 0 && _mem[_valstart+off+j] < 0x21) j++;
if (j > 0) nc._is[i] = off + j;
while( _mem[_valstart+off+j] != 0 ) j++; //Find end
j--;
while( _mem[_valstart+off+j] > 0 && _mem[_valstart+off+j] < 0x21) { //March back to find first non-space
nc._ss[off+j] = 0; //Set new end
j--;
}
}
}
return nc;
}
示例3: asciiLength
import water.util.UnsafeUtils; //导入依赖的package包/类
/**
* Optimized length() method for a buffer of only ASCII characters.
* This is a straight byte count for each word in the chunk. The presence
* of UTF-8 multi-byte characters would give incorrect results.
*
* @param nc NewChunk to be filled with lengths of strings in this chunk
* @return Filled NewChunk
*/
public NewChunk asciiLength(NewChunk nc) {
//pre-allocate since size is known
nc._ls = MemoryManager.malloc8(_len);
nc._xs = MemoryManager.malloc4(_len); // sadly, a waste
// fill in lengths
for(int i=0; i < _len; i++) {
int off = UnsafeUtils.get4(_mem,(i<<2)+_OFF);
int len = 0;
if (off != NA) {
while (_mem[_valstart + off + len] != 0) len++;
nc.addNum(len, 0);
} else nc.addNA();
}
return nc;
}
示例4: CUDChunk
import water.util.UnsafeUtils; //导入依赖的package包/类
CUDChunk(byte[] bs, HashMap<Long,Byte> hs, int len) {
_start = -1;
numUniques = hs.size();
set_len(len);
_mem = MemoryManager.malloc1(computeByteSize(numUniques, _len), false);
UnsafeUtils.set4(_mem, 0, _len);
UnsafeUtils.set4(_mem, 4, numUniques);
int j=0;
//create the mapping and also store the unique values (as longs)
for (Map.Entry<Long,Byte> e : hs.entrySet()) {
e.setValue(new Byte((byte)(j-128))); //j is in 0...256 -> byte value needs to be in -128...127 for storage
UnsafeUtils.set8(_mem, 8 + (j << 3), e.getKey());
j++;
}
// store the mapping
for (int i=0; i<len; ++i)
UnsafeUtils.set1(_mem, 8 + (numUniques << 3) + i, hs.get(Double.doubleToLongBits(UnsafeUtils.get8d(bs, i << 3))));
}
示例5: init
import water.util.UnsafeUtils; //导入依赖的package包/类
private void init (int sslen, byte[] ss, int sparseLen, int idxLen, int[] id, int[] is) {
_start = -1;
_valstart = idx(idxLen);
_len = idxLen;
_mem = MemoryManager.malloc1(_valstart + sslen, false);
UnsafeUtils.set4(_mem, 0, _valstart); // location of start of strings
Arrays.fill(_mem,_OFF,_valstart,(byte)-1); // Indicate All Is NA's
for( int i = 0; i < sparseLen; ++i ) // Copy the sparse indices
UnsafeUtils.set4(_mem, idx(id==null ? i : id[i]), is==null ? 0 : is[i]); //Need to check if id and is are null since both are not always needed for mem allocation
UnsafeUtils.copyMemory(ss,0,_mem,_valstart,sslen);
_isAllASCII = true;
for(int i = _valstart; i < _mem.length; ++i) {
byte c = _mem[i];
if ((c & 0x80) == 128) { //value beyond std ASCII
_isAllASCII = false;
break;
}
}
UnsafeUtils.set1(_mem, 4, (byte) (_isAllASCII ? 1 : 0)); // isAllASCII flag
}
示例6: asciiTrim
import water.util.UnsafeUtils; //导入依赖的package包/类
/**
* Optimized trim() method to operate across the entire CStrChunk buffer in one pass.
* This mimics Java String.trim() by only considering characters of value
* <code>'\u0020'</code> or less as whitespace to be trimmed. This means that like
* Java's String.trim() it ignores 16 of the 17 characters regarded as a space in UTF.
*
* NewChunk is the same size as the original, despite trimming.
*
* @param nc NewChunk to be filled with trimmed version of strings in this chunk
* @return Filled NewChunk
*/
public NewChunk asciiTrim(NewChunk nc) {
// copy existing data
nc = this.extractRows(nc, 0,_len);
//update offsets and byte array
for(int i=0; i < _len; i++) {
int j = 0;
int off = UnsafeUtils.get4(_mem,idx(i));
if (off != NA) {
//UTF chars will appear as negative values. In Java spec, space is any char 0x20 and lower
while( _mem[_valstart+off+j] > 0 && _mem[_valstart+off+j] < 0x21) j++;
if (j > 0) nc.set_is(i,off + j);
while( _mem[_valstart+off+j] != 0 ) j++; //Find end
j--;
while( _mem[_valstart+off+j] > 0 && _mem[_valstart+off+j] < 0x21) { //March back to find first non-space
nc._ss[off+j] = 0; //Set new end
j--;
}
}
}
return nc;
}
示例7: asciiSubstring
import water.util.UnsafeUtils; //导入依赖的package包/类
/**
* Optimized substring() method for a buffer of only ASCII characters.
* The presence of UTF-8 multi-byte characters would give incorrect results
* for the string length, which is required here.
*
* @param nc NewChunk to be filled with substrings in this chunk
* @param startIndex The beginning index of the substring, inclusive
* @param endIndex The ending index of the substring, exclusive
* @return Filled NewChunk
*/
public NewChunk asciiSubstring(NewChunk nc, int startIndex, int endIndex) {
// copy existing data
nc = this.extractRows(nc, 0,_len);
//update offsets and byte array
for (int i = 0; i < _len; i++) {
int off = UnsafeUtils.get4(_mem, idx(i));
if (off != NA) {
int len = 0;
while (_mem[_valstart + off + len] != 0) len++; //Find length
nc.set_is(i,startIndex < len ? off + startIndex : off + len);
for (; len > endIndex - 1; len--) {
nc._ss[off + len] = 0; //Set new end
}
}
}
return nc;
}
示例8: asciiLength
import water.util.UnsafeUtils; //导入依赖的package包/类
/**
* Optimized length() method for a buffer of only ASCII characters.
* This is a straight byte count for each word in the chunk. The presence
* of UTF-8 multi-byte characters would give incorrect results.
*
* @param nc NewChunk to be filled with lengths of strings in this chunk
* @return Filled NewChunk
*/
public NewChunk asciiLength(NewChunk nc) {
//pre-allocate since size is known
nc.alloc_mantissa(_len);
nc.alloc_exponent(_len); // sadly, a waste
// fill in lengths
for(int i=0; i < _len; i++) {
int off = UnsafeUtils.get4(_mem,idx(i));
int len = 0;
if (off != NA) {
while (_mem[_valstart + off + len] != 0) len++;
nc.addNum(len, 0);
} else nc.addNA();
}
return nc;
}
示例9: bufS
import water.util.UnsafeUtils; //导入依赖的package包/类
private byte[] bufS(int len, int id_sz, int val_sz,boolean na_sparse){
long NA = CXIChunk.NA(val_sz);
int elem_size = id_sz+val_sz;
byte [] res = MemoryManager.malloc1(CXIChunk._OFF + _sparseLen*elem_size);
UnsafeUtils.set4(res,0,len);
res[4] = (byte)id_sz;
res[5] = (byte)val_sz;
res[6] = na_sparse?(byte)1:0;
if(na_sparse)res[6] = (byte)1;
for(int i = 0; i < _sparseLen; ++i){
if(id_sz == 2) UnsafeUtils.set2(res,CXIChunk._OFF+i*elem_size+0,(short)_id[i]);
else UnsafeUtils.set4(res,CXIChunk._OFF+i*elem_size+0,_id[i]);
long val = isNA2(i)?NA:_ms.get(i);
switch(val_sz){
case 0: break; // no value store dfor binary chunks
case 2: UnsafeUtils.set2(res,CXIChunk._OFF+i*elem_size+id_sz,(short)val); break;
case 4: UnsafeUtils.set4(res,CXIChunk._OFF+i*elem_size+id_sz,(int)val); break;
case 8: UnsafeUtils.set8(res,CXIChunk._OFF+i*elem_size+id_sz,val); break;
default: throw H2O.unimpl();
}
}
return res;
}
示例10: bufD
import water.util.UnsafeUtils; //导入依赖的package包/类
private byte[] bufD(final int valsz, boolean na_sparse){
int elem_size = valsz+4;
byte [] res = MemoryManager.malloc1(CXIChunk._OFF + _sparseLen*elem_size);
UnsafeUtils.set4(res,0,_len);
res[4] = (byte)4;
res[5] = (byte)valsz;
res[6] = na_sparse?(byte)1:0;
if(na_sparse)res[6] = (byte)1;
for(int i = 0; i < _sparseLen; ++i){
UnsafeUtils.set4(res,CXIChunk._OFF+i*elem_size+0,_id[i]);
if(valsz == 4){
UnsafeUtils.set4f(res,CXIChunk._OFF+i*elem_size+4,(float)_ds[i]);
} else if(valsz == 8) {
UnsafeUtils.set8d(res,CXIChunk._OFF+i*elem_size+4,_ds[i]);
} else throw H2O.unimpl();
}
return res;
}
示例11: set_impl
import water.util.UnsafeUtils; //导入依赖的package包/类
@Override boolean set_impl(int idx, long l) {
long res = (long)(l/_scale)-_bias; // Compressed value
double d = (res+_bias)*_scale; // Reverse it
if( (long)d != l ) return false; // Does not reverse cleanly?
if( !(Short.MIN_VALUE < res && res <= Short.MAX_VALUE) ) return false; // Out-o-range for a short array
UnsafeUtils.set2(_mem,(idx<<1)+_OFF,(short)res);
return true;
}
示例12: read_impl
import water.util.UnsafeUtils; //导入依赖的package包/类
@Override public C2SChunk read_impl(AutoBuffer bb) {
_mem = bb.bufClose();
_start = -1; _cidx = -1;
set_len((_mem.length-_OFF)>>1);
_scale= UnsafeUtils.get8d(_mem,0);
_bias = UnsafeUtils.get8 (_mem,8);
return this;
}
示例13: inflate_impl
import water.util.UnsafeUtils; //导入依赖的package包/类
@Override public NewChunk inflate_impl(NewChunk nc) {
nc.set_sparseLen(0);
nc.set_len(0);
final int len = _len;
for( int i=0; i<len; i++ ) {
int res = UnsafeUtils.get4(_mem,(i<<2));
if( res == _NA ) nc.addNA();
else nc.addNum(res,0);
}
return nc;
}
示例14: read_impl
import water.util.UnsafeUtils; //导入依赖的package包/类
@Override public C1SChunk read_impl(AutoBuffer bb) {
_mem = bb.bufClose();
_start = -1; _cidx = -1;
set_len(_mem.length-_OFF);
_scale= UnsafeUtils.get8d(_mem,0);
_bias = UnsafeUtils.get8 (_mem,8);
return this;
}
示例15: atStr_impl
import water.util.UnsafeUtils; //导入依赖的package包/类
@Override public BufferedString atStr_impl(BufferedString bStr, int idx) {
int off = UnsafeUtils.get4(_mem,(idx<<2)+_OFF);
if( off == NA ) return null;
int len = 0;
while( _mem[_valstart+off+len] != 0 ) len++;
return bStr.set(_mem,_valstart+off,len);
}