本文整理汇总了C++中Slice函数的典型用法代码示例。如果您正苦于以下问题:C++ Slice函数的具体用法?C++ Slice怎么用?C++ Slice使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Slice函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sizeof
void
MPEGCodec::decompress(const DataChunk &data)
{
const int channels = 3;
const size_t bytes_per_channel = sizeof(unsigned char);
const UInt32 width = _descriptor.getStoredWidth();
const UInt32 height = _descriptor.getStoredHeight();
const ptrdiff_t stride = bytes_per_channel * channels;
const size_t rowbytes = width * stride;
const size_t data_size = rowbytes * height;
DataChunkPtr buf_data = new DataChunk(data_size);
char *data_origin = (char *)buf_data->Data;
FrameBufferPtr buf = new FrameBuffer(width, height);
buf->insert("R", Slice(MoxFiles::UINT8, data_origin + (bytes_per_channel * 0), stride, rowbytes));
buf->insert("G", Slice(MoxFiles::UINT8, data_origin + (bytes_per_channel * 1), stride, rowbytes));
buf->insert("B", Slice(MoxFiles::UINT8, data_origin + (bytes_per_channel * 2), stride, rowbytes));
memset(data_origin, 0, data_size);
buf->attachData(buf_data);
storeFrame(buf);
}
示例2: Slice
Slice MemTable::get(int(*compare)(unsigned char* key, int key_size, unsigned char* value, int value_size), unsigned char* key, int key_size)
{
Slice slice;
if (this->current_table)
{
slice = this->mem_table1->searchNode(compare, key, key_size);
if (slice.getKeySize() == 0 && (!slice.isDeleted()))
{
Slice s = this->mem_table2->searchNode(compare, key, key_size);
return Slice(s.getKey(),s.getKeySize(),s.getValue(),s.getValueSize(), s.isDeleted());
}
else
{
return Slice(slice.getKey(), slice.getKeySize(), slice.getValue(), slice.getValueSize(), slice.isDeleted());
}
}
else {
slice = this->mem_table2->searchNode(compare, key, key_size);
if (slice.getKeySize() == 0 && (!slice.isDeleted()))
{
Slice s = this->mem_table1->searchNode(compare, key, key_size);
return Slice(s.getKey(), s.getKeySize(), s.getValue(), s.getValueSize(), s.isDeleted());
}
else {
return Slice(slice.getKey(), slice.getKeySize(), slice.getValue(), slice.getValueSize(), slice.isDeleted());
}
}
}
示例3: KDF
/*** KDF ***/
void KDF(const string &auth_key, const UInt128 &msg_key, int X, UInt256 *aes_key, UInt256 *aes_iv) {
CHECK(auth_key.size() == 2048 / 8);
const char *auth_key_raw = auth_key.c_str();
uint8 buf[48];
as<UInt128>(buf) = msg_key;
as<UInt256>(buf + 16) = as<UInt256>(auth_key_raw + X);
uint8 sha1_a[20];
sha1(Slice(buf, 48), sha1_a);
as<UInt128>(buf) = as<UInt128>(auth_key_raw + X + 32);
as<UInt128>(buf + 16) = msg_key;
as<UInt128>(buf + 32) = as<UInt128>(auth_key_raw + X + 48);
uint8 sha1_b[20];
sha1(Slice(buf, 48), sha1_b);
as<UInt256>(buf) = as<UInt256>(auth_key_raw + 64 + X);
as<UInt128>(buf + 32) = msg_key;
uint8 sha1_c[20];
sha1(Slice(buf, 48), sha1_c);
as<UInt128>(buf) = msg_key;
as<UInt256>(buf + 16) = as<UInt256>(auth_key_raw + 96 + X);
uint8 sha1_d[20];
sha1(Slice(buf, 48), sha1_d);
as<uint64>(aes_key->raw) = as<uint64>(sha1_a);
as<UInt<96>>(aes_key->raw + 8) = as<UInt<96>>(sha1_b + 8);
as<UInt<96>>(aes_key->raw + 20) = as<UInt<96>>(sha1_c + 4);
as<UInt<96>>(aes_iv->raw) = as<UInt<96>>(sha1_a + 8);
as<uint64>(aes_iv->raw + 12) = as<uint64>(sha1_b);
as<uint32>(aes_iv->raw + 20) = as<uint32>(sha1_c + 16);
as<uint64>(aes_iv->raw + 24) = as<uint64>(sha1_d);
}
示例4: Run
void Run()
{
db->VisitAllDB(this);
db->GetEngine()->CommitBatchWrite();
db->GetEngine()->CompactRange(Slice(), Slice());
delete this;
}
示例5: Slice
Slice WiredTigerIterator::Value() const
{
if (0 == m_iter->get_value(m_iter, &m_value_item))
{
return Slice((const char*) m_value_item.data, m_value_item.size);
}
return Slice();
}
示例6: EH
/**
* @brief Left hand side operator (i.e. inverse transform)
*
* @param in K-space
* @param sm Sensitivities
* @param nx Sizes & co.
* @param fts FT operators
* @return Image
*/
template <class T> inline static Matrix< std::complex<T> >
EH (const Matrix< std::complex<T> >& in, const Matrix< std::complex<T> >& sm,
const std::vector<size_t>& nx, const std::vector<NFFT<T> >& fts) {
Matrix< std::complex<T> > out = zeros< std::complex<T> > (size(sm));
#pragma omp parallel for default (shared)
for (int j = 0; j < nx[1]; j++)
Slice (out, j, fts[omp_get_thread_num()] ->* Column (in,j) * conj(Slice (sm, j)));
return sum (out, nx[0]);
}
示例7: saveEXRRGBA
void saveEXRRGBA(const char* filename, int width, int height, float* data)
{
half *idr_r = new half[ width * height];
half *idr_g = new half[ width * height];
half *idr_b = new half[ width * height];
half *idr_a = new half[ width * height];
for(int j=0; j< height; j++) {
int invj = height - 1 -j;
for(int i=0; i< width; i++) {
idr_r[j* width + i] = (half)data[(invj* width + i)*4];
idr_g[j* width + i] = (half)data[(invj* width + i)*4+1];
idr_b[j* width + i] = (half)data[(invj* width + i)*4+2];
idr_a[j* width + i] = (half)data[(invj* width + i)*4+3];
}
}
// write exr
Header idrheader ( width, height);
idrheader.channels().insert ("R", Channel (HALF));
idrheader.channels().insert ("G", Channel (HALF)); // 1
idrheader.channels().insert ("B", Channel (HALF));
idrheader.channels().insert ("A", Channel (HALF)); // 2
OutputFile idrfile (filename, idrheader); // 4
FrameBuffer idrframeBuffer;
idrframeBuffer.insert ("R", // name // 6
Slice (HALF, // type // 7
(char *) idr_r, // base // 8
sizeof (*idr_r) * 1, // xStride// 9
sizeof (*idr_r) * width));
idrframeBuffer.insert ("G", // name // 6
Slice (HALF, // type // 7
(char *) idr_g, // base // 8
sizeof (*idr_g) * 1, // xStride// 9
sizeof (*idr_g) * width));
idrframeBuffer.insert ("B", // name // 6
Slice (HALF, // type // 7
(char *) idr_b, // base // 8
sizeof (*idr_b) * 1, // xStride// 9
sizeof (*idr_b) * width));
idrframeBuffer.insert ("A", // name // 6
Slice (HALF, // type // 7
(char *) idr_a, // base // 8
sizeof (*idr_a) * 1, // xStride// 9
sizeof (*idr_a) * width));
idrfile.setFrameBuffer (idrframeBuffer); // 16
idrfile.writePixels ( height);
// cleanup
delete[] idr_r;
delete[] idr_g;
delete[] idr_b;
delete[] idr_a;
}
示例8: Run
void Run()
{
KeyObject start(Slice(), KV, dbid);
KeyObject end(Slice(), KV, dbid + 1);
Buffer sbuf, ebuf;
encode_key(sbuf, start);
encode_key(ebuf, end);
adb->GetEngine()->CompactRange(sbuf.AsString(), ebuf.AsString());
delete this;
}
示例9: parallelization
Function Map
::get_reverse(const std::string& name, int nadj,
const std::vector<std::string>& i_names,
const std::vector<std::string>& o_names,
const Dict& opts) const {
// Shorthands
int n_in = this->n_in(), n_out = this->n_out();
// Generate map of derivative
Function df = f_.reverse(nadj);
Function dm = df.map(n_, parallelization());
// Input expressions
vector<MX> arg = dm.mx_in();
// Need to reorder sensitivity inputs
vector<MX> res = arg;
vector<MX>::iterator it=res.begin()+n_in+n_out;
vector<int> ind;
for (int i=0; i<n_out; ++i, ++it) {
int sz = f_.size2_out(i);
ind.clear();
for (int k=0; k<n_; ++k) {
for (int d=0; d<nadj; ++d) {
for (int j=0; j<sz; ++j) {
ind.push_back((d*n_ + k)*sz + j);
}
}
}
*it = (*it)(Slice(), ind);
}
// Get output expressions
res = dm(res);
// Reorder sensitivity outputs
it = res.begin();
for (int i=0; i<n_in; ++i, ++it) {
int sz = f_.size2_in(i);
ind.clear();
for (int d=0; d<nadj; ++d) {
for (int k=0; k<n_; ++k) {
for (int j=0; j<sz; ++j) {
ind.push_back((k*nadj + d)*sz + j);
}
}
}
*it = (*it)(Slice(), ind);
}
// Construct return function
return Function(name, arg, res, i_names, o_names, opts);
}
示例10: readEXRRGB
void readEXRRGB(const char* filename, int width, int height, float* data)
{
InputFile file(filename);
Box2i dw = file.header().dataWindow();
int size = (width)*(height);
half *rPixels = new half[size];
half *gPixels = new half[size];
half *bPixels = new half[size];
FrameBuffer frameBuffer;
frameBuffer.insert ("R", // name
Slice (HALF, // type
(char *) rPixels,
sizeof (*rPixels) * 1, // xStride
sizeof (*rPixels) * (width),// yStride
1, 1, // x/y sampling
0.0)); // fillValue
frameBuffer.insert ("G", // name
Slice (HALF, // type
(char *) gPixels,
sizeof (*gPixels) * 1, // xStride
sizeof (*gPixels) * (width),// yStride
1, 1, // x/y sampling
0.0));
frameBuffer.insert ("B", // name
Slice (HALF, // type
(char *) bPixels,
sizeof (*bPixels) * 1, // xStride
sizeof (*bPixels) * (width),// yStride
1, 1, // x/y sampling
0.0));
file.setFrameBuffer (frameBuffer);
file.readPixels (dw.min.y, dw.max.y);
for(int j=0; j<height; j++)
for(int i=0; i<width; i++) {
data[(j*width+i)*3 ] = rPixels[(height-1-j)*width+i];
data[(j*width+i)*3+1] = gPixels[(height-1-j)*width+i];
data[(j*width+i)*3+2] = bPixels[(height-1-j)*width+i];
}
delete[] rPixels;
delete[] gPixels;
delete[] bPixels;
}
示例11: writeEXRHalf
void writeEXRHalf(OStream *ost, const float *pixels,
int width, int height, int components)
{
//assert(components==3 || components==4);
// TODO: throw std::exception if invalid number of components
Header header (width, height);
header.channels().insert ("R", Channel (HALF));
header.channels().insert ("G", Channel (HALF));
header.channels().insert ("B", Channel (HALF));
if(components==4)
header.channels().insert ("A", Channel (HALF));
// Convert data to half
half *data = new half [width*height*components];
std::copy(pixels, pixels+(width*height*components), data);
// And save it
OutputFile file (*ost, header);
FrameBuffer frameBuffer;
frameBuffer.insert("R", // name
Slice (HALF, // type
((char *) data)+0, // base
2 * components, // xStride
2 * components * width)); // yStride
frameBuffer.insert("G", // name
Slice (HALF, // type
((char *) data)+2, // base
2 * components, // xStride
2 * components * width)); // yStride
frameBuffer.insert("B", // name
Slice (HALF, // type
((char *) data)+4, // base
2 * components, // xStride
2 * components * width)); // yStride
if(components==4) {
frameBuffer.insert("A", // name
Slice (HALF, // type
((char *) data)+6, // base
2 * components, // xStride
2 * components * width)); // yStride
}
file.setFrameBuffer(frameBuffer);
file.writePixels(height);
delete data;
}
示例12: Slice
void Model::SliceToSVG(Glib::RefPtr<Gio::File> file, bool single_layer)
{
if (is_calculating) return;
is_calculating=true;
lastlayer = NULL;
Slice();
m_progress->stop (_("Done"));
if (!single_layer) {
Glib::file_set_contents (file->get_path(), getSVG());
}
else {
uint n_layers = layers.size();
m_progress->start (_("Saving Files"),n_layers);
uint digits = log10(n_layers)+1;
string base = file->get_path();
ostringstream ostr;
for (uint i = 0; i < n_layers; i++) {
ostr.str("");
ostr << base;
uint nzero = (uint)(digits - log10(i+1));
if (i==0) nzero = digits-1;
for (uint d = 0; d < nzero; d++)
ostr << "0";
ostr << i
<< ".svg";
if (!m_progress->update(i)) break;
Glib::file_set_contents (ostr.str(), getSVG(i));
}
m_progress->stop (_("Done"));
}
string directory_path = file->get_parent()->get_path();
settings.STLPath = directory_path;
is_calculating = false;
}
示例13: Seek
void Seek(const Slice &target)
{
char buf[prefix.size() + target.size()];
(void) memcpy(buf, prefix.data(), prefix.size());
(void) memcpy(buf + sizeof(prefix), target.data(), target.size());
impl.Seek(Slice(buf, sizeof(buf)));
}
示例14: sigPart
// Parse a length-prefixed number
// Format: 0x02 <length-byte> <number>
static
boost::optional<Slice>
sigPart (Slice& buf)
{
if (buf.size() < 3 || buf[0] != 0x02)
return boost::none;
auto const len = buf[1];
buf += 2;
if (len > buf.size() || len < 1 || len > 33)
return boost::none;
// Can't be negative
if ((buf[0] & 0x80) != 0)
return boost::none;
if (buf[0] == 0)
{
// Can't be zero
if (len == 1)
return boost::none;
// Can't be padded
if ((buf[1] & 0x80) == 0)
return boost::none;
}
boost::optional<Slice> number = Slice(buf.data(), len);
buf += len;
return number;
}
示例15: main
int main () {
fwrite(PG_BINARY_HEADER, sizeof(PG_BINARY_HEADER), 1, stdout);
uint32_t height = 0;
while (true) {
uint8_t buffer[32];
const auto read = fread(buffer, sizeof(buffer), 1, stdin);
// EOF?
if (read == 0) break;
uint8_t pbuffer[46];
auto pslice = Slice(pbuffer, pbuffer + sizeof(pbuffer));
std::reverse(&buffer[0], &buffer[32]); // BLOCK_HASH -> BLOCK_ID
// postgres COPY tuple
pslice.write<int16_t, true>(2);
pslice.write<int32_t, true>(32);
memcpy(pslice.begin, buffer, 32);
pslice.popFrontN(32);
pslice.write<int32_t, true>(4);
pslice.write<int32_t, true>(height);
fwrite(pbuffer, sizeof(pbuffer), 1, stdout);
++height;
}
fwrite(PG_BINARY_TAIL, sizeof(PG_BINARY_TAIL), 1, stdout);
return 0;
}