long long getres(int from) { mem(dis, -1); dis[from] = 0; dfs(from); long long maxd = -1; int p = -1; rep(i, size) if (dis[i] > maxd) { maxd = dis[i]; p = i; } mem(dis, -1); dis[p] = 0; dfs(p); long long res = -1; rep(i, size) res = max(res, dis[i]); return res; }
static void zerograd_chk(ASL *asl) { int j, n, nv, nx, *z, **zg; ograd *og, **ogp, **ogpe; nx = asl->i.nsufext[ASL_Sufkind_var]; if (!(nv = asl->i.nlvog)) { nv = n_var; if (nv > asl->i.n_var0) nx -= nv - asl->i.n_var0; } zerograds = 0; ogp = Ograd; ogpe = ogp + (j = n_obj); while(ogp < ogpe) { og = *ogp++; n = 0; while(og) { j += og->varno - n; n = og->varno + 1; if (n >= nv) break; og = og->next; } if (n < nv) j += nv - n; } if (j == n_obj) return; j += n_obj * nx; zerograds = zg = (int **)mem(n_obj*sizeof(int*)+j*sizeof(int)); z = (int*)(zg + n_obj); ogp = Ograd; while(ogp < ogpe) { *zg++ = z; og = *ogp++; n = 0; while(og) { while(n < og->varno) *z++ = n++; og = og->next; if (++n >= nv) break; } while(n < nv) *z++ = n++; *z++ = -1; z += nx; } }
void CodeExpander::stub(Function* func, Attribute* attr) { // Create a stub which calls through to the nested class function. std::string name = func->name()->string(); if (name == "@init" || name == "@destroy" || name == "@copy") { return; } if ((class_->feature(func->name()) != func) || func->is_private()) { return; } if (class_->is_interface()) { return; } String::Ptr nm = func->name(); Feature::Flags flags = func->flags() & ~(Feature::NATIVE); Formal::Ptr f = func->formals(); Type::Ptr type = func->type(); Location loc = class_->location(); Expression::Ptr args; Expression::Ptr self(new IdentifierRef(loc, env_->name(""), attr->name())); for (Formal::Ptr f = func->formals(); f; f = f->next()) { Expression::Ptr arg; if (f->name()->string() == "__self") { arg = self; } else { arg = new IdentifierRef(loc, env_->name(""), f->name()); } arg->type(f->type()); args = append(args.pointer(), arg.pointer()); } Expression::Ptr mem(new Member(loc, self, func->name())); Call::Ptr call(new Call(loc, mem, args)); call->function(func); call->type(func->type()); Expression::Ptr stmt; if (func->type()->is_void()) { stmt = call.pointer(); } else { stmt = new Return(loc, call); stmt->type(env_->void_type()); call->type(func->type()); } Block::Ptr block(new Block(loc, 0, stmt)); block->type(env_->void_type()); Function::Ptr stub(new Function(loc, env_, nm, f, flags, type, block)); class_->feature(stub); semant_->operator()(stub); }
//counting sort void csort(vector<int> &v) { int maxvalue = 0; for (int i: v) maxvalue = max(i, maxvalue); int count[maxvalue + 1]; mem(count, 0); for (int i: v) count[i] ++; for (int i = 1; i <= maxvalue; i ++) count[i] += count[i - 1]; int arr[sz(v)]; for (int i = sz(v) - 1; i >= 0; i --) arr[-- count[v[i]]] = v[i]; rep(i, sz(v)) v[i] = arr[i]; }
// modify size fields (if present); clear orientation field (if present) void ExifBlock::ModifySizeFields(CSize img_size, bool clearOrientation) { if (exif_buffer.empty() || exif_buffer.size() < offsetIfd0Entries) return; MemPointer mem(&exif_buffer.front(), exif_buffer.size()); mem.SetByteOrder(bigEndianByteOrder); mem += offsetIfd0Entries; for (uint32 i= 0; i < ifd0Entries; ++i) { uint16 tag= mem.GetUInt16(); if (tag == EXIF_IMG_WIDTH || tag == EXIF_IMG_HEIGHT) { SetField(mem, tag == EXIF_IMG_WIDTH ? img_size.cx : img_size.cy); // ModifySize(img_size, tag, mem); } else if (tag == EXIF_ORIENTATION) { SetField(mem, 1); // 'normal' orientation } else if (tag == EXIF_SUB_IFD) { uint16 fmt= mem.GetUInt16(); uint32 components= mem.GetUInt32(); uint32 offset= mem.GetUInt32(); // read sub IFD ptrdiff_t temp= mem.GetPos(); mem.SetPos(ifd0Start + offset); uint16 entries= mem.GetUInt16(); // no of entries in sub IFD for (uint32 i= 0; i < entries; ++i) { uint16 tag= mem.GetUInt16(); if (tag == EXIF_IMG_WIDTH || tag == EXIF_IMG_HEIGHT) SetField(mem, tag == EXIF_IMG_WIDTH ? img_size.cx : img_size.cy); // ModifySize(img_size, tag, mem); else mem += 2 + 4 + 4; } mem.SetPos(temp); } else mem += 2 + 4 + 4; } }
void texture::capture( int left, int bottom ) { assert( id > 0 ); assert( w > 0 ); assert( h > 0 ); /* if( size != same || !created ) destroy(); create(); this->resize( w * h ); */ bind(); // esto copia la vram a la textura que indiquemos, pero no se leer los pixels de ella aun (no se escriben en mem.data()!) std::vector<unsigned char> mem( w * h * 3 ); // if(capture_depth) { // glTexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, xSize, ySize, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, 0), // glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, w, h); // } else { glTexImage2D(GL_TEXTURE_2D, 0, 3, w, h, 0, GL_RGB, GL_UNSIGNED_BYTE, 0 ); //mem.data() ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST ); // pixel perfect glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST ); // pixel perfect glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, w, h, 0); // } // asi que uso esto... glReadPixels( left, bottom, w, h, GL_RGB, GL_UNSIGNED_BYTE, mem.data() ); // invert image vertically for( size_t y = 0, it = 0; y < h; ++y ) for( size_t x = 0; x < w; ++x, ++it ) { size_t offset = ( (x) + (h-1 - y) * w ) * 3; float r = mem[ offset + 0 ] / 255.f; float g = mem[ offset + 1 ] / 255.f; float b = mem[ offset + 2 ] / 255.f; this->operator[]( it ) = moon9::pixel::rgba( r, g, b ); } //submit(); }
int longestIncreasingPath(vector<vector<int>>& matrix) { int rowLimit = matrix.size(); if (!rowLimit) return 0; int colLimit = matrix[0].size(); if (!colLimit) return 0; int maxDepth = 1; vector<vector<int>> mem (rowLimit, vector<int>(colLimit)); for (int row = 0; row < rowLimit; ++row) { for (int col = 0; col < colLimit; ++col) { maxDepth = std::max(maxDepth, dfs(matrix, mem, row, col)); } } return maxDepth; }
uint8 SaveLoad_v6::GameHandler::getExtraID(int slot) { if (!_reader || (_reader->getSlot() != (uint32)slot)) return 0; SavePartMem mem(1); if (!_reader->readPart(2, &mem)) return 0; uint8 extraSaveNumber; if (!mem.writeInto(&extraSaveNumber, 0, 1)) return 0; return extraSaveNumber; }
bool SaveLoad_v4::GameHandler::loadScreenProps(int slot, byte *props) { if (!createReader(slot)) return false; SavePartMem mem(256000); if (!_reader->readPart(2, &mem)) return false; if (!mem.writeInto(props, 0, 256000)) return false; return true; }
int maxSubArray(int A[], int n) { int ret = A[0]; vector<int> mem(n,0); mem[0] = A[0]; for(int i = 1 ;i < n ;i++) { if(mem[i-1] > 0) mem[i] = A[i] + mem[i-1]; else mem[i] = A[i]; ret = max(mem[i] , ret); } return ret; }
int gauss(int n) { int i,j,k,cnt,row,ok,ret,up,cnt_free; for(i=row=0;i<n;i++){ if(!A[row][i]){ for(j=row+1;j<n;j++){ if(A[j][i]){ for(k=i;k<=n;k++)swap(A[row][k],A[j][k]); break; } } } if(A[row][i]!=1)continue; //保证为严格的阶梯矩阵 for(j=0;j<n;j++){ //从0开始,高斯约当消元 if(j!=row && A[j][i]){ for(k=i;k<=n;k++) A[j][k]^=A[row][k]; } } row++; } for(i=n-1;i>=row;i--) if(A[i][n])return -1; //无解 if(row==n){ //唯一解 for(i=ret=0;i<n;i++)if(A[i][n])ret++; return ret; } mem(is_free,0); for(i=k=j=0;i<n;i++,j++){ while(!A[i][j] && j<n){ is_free[j]=1; //判断元素是否解唯一 num[k++]=j++; } } ret=INF;cnt_free=n-row; //自由变元个数 up=1<<cnt_free; for(k=0;k<up;k++){ //枚举最小的变换个数 for(i=0;i<cnt_free;i++)B[num[i]]=(k&(1<<i))?1:0; for(i=n-1;i>=0;i--){ if(is_free[i])continue; B[i]=0; for(j=row;j<n;j++)B[i]^=B[j]*A[i][j]; B[i]^=A[i][n]; } for(i=cnt=0;i<n;i++)if(B[i])cnt++; ret=Min(ret,cnt); } return ret; //返回最小的变换个数 }
void GScreenDC::Blt(int x, int y, GSurface *Src, GRect *a) { if (Src) { if (Src->IsScreen()) { // screen to screen Blt printf("%s:%i - Error: can't do screen to screen blt.\n", _FL); } else { // memory to screen Blt GMemDC *Dc = dynamic_cast<GMemDC*>(Src); BBitmap *Bmp = Dc ? Dc->GetBitmap() : 0; if (Bmp) { GRect SrcRc; if (a) SrcRc = *a; else SrcRc = Src->Bounds(); BRect S = SrcRc; BRect D(x, y, x+S.Width(), y+S.Height()); if (d->ConstAlpha == 0) { } else if (d->ConstAlpha < 255) { // Off screen comp GMemDC mem(S.Width()+1, S.Height()+1, System32BitColourSpace); mem.Colour(B_TRANSPARENT_MAGIC_RGBA32, 32); mem.Rectangle(); mem.Blt(0, 0, Src, a); mem.SetConstantAlpha(d->ConstAlpha); d->View->DrawBitmap(mem.GetBitmap(), S = mem.Bounds(), D); } else { d->View->DrawBitmap(Bmp, S, D); } } else printf("%s:%i - Error: No bitmap to blt\n", _FL); } } }
int main(int argc, const char **argv) { if (argc < 3) { usage(std::cerr); return EXIT_FAILURE; } const char *image_flnm = argv[2]; bool log = false; bool log_dumpregs = false; if (argv[1][0] >= '1') log = true; if (argv[1][0] >= '2') log_dumpregs = true; std::fstream image(image_flnm, std::ios_base::binary | std::ios_base::in); if (image.fail()) { std::cerr << "Could not open image file " << image_flnm << std::endl; return EXIT_FAILURE; } EndianMemory mem(new VirtualMemory, LittleEndian); std::auto_ptr<ExecutableLoader> elfloader(new ELFLoader); std::auto_ptr<ExecutableLoader> peloader(new PELoader); addr_t entry_point; if (!elfloader->load(image, &mem, entry_point) && !peloader->load(image, &mem, entry_point)) { std::cerr << "Image in " << image_flnm << "is neither ELF nor PE format, or contains some error." << std::endl; return EXIT_FAILURE; } CPU cpu(mem, log, log_dumpregs, argc - 2, argv + 2); std::cout << "Loaded image, starting execution" << std::endl; Time time_start = Time::now(); cpu.run(entry_point); Time time_end = Time::now(); Time duration = time_end - time_start; std::cout << "Execution ended." << std::endl; std::cout << "Executed " << cpu.pc_counter() << " instructions." << std::endl; std::cout.setf(std::ios_base::fixed); std::cout.precision(2); std::cout << "Execution took " << duration << " (" << ((double)cpu.pc_counter())/((double)duration.time()) << " \"MHz\")" << std::endl; return EXIT_SUCCESS; }
bool GameServer::DispatchReceivedData(SocketContext* pSockConn, BYTE* pData, DWORD dwSize, bool bIsFirstData){ ASSERT(m_pPacketHandler && pData && dwSize > 0); if( !pData || !dwSize ) return false; ClientConnection* pConn = (ClientConnection*)pSockConn->GetParam(); GrowableMemory mem(0, 0, false); mem.SetReadonlyBuffer(pData, dwSize); if( !pConn ) return false; BasePacket basePacket; int nOffset = 0; int nBufferSize = dwSize; int nSerializedBytes = 0; while( TRUE ){ if( basePacket.Deserialize(&mem) ){ // Success // Handshake must be the only one command accepted while session is not created. if( (basePacket.m_nCode != PacketCodes::_HandShake && basePacket.m_nCode != PacketCodes::_AcquireTableAccess) && pConn->GetSession(false) == NULL ) return false; BasePacket* packet = m_pPacketHandler->CreatePacketByCode(basePacket.m_nCode); ASSERT( packet ); #ifndef _DEBUG if( packet == NULL ) return false; #endif // Deserialize received data into known packet. if( !mem.SetCurrentOffset(nOffset) ) return false; if( !packet->Deserialize(&mem) ) return false; // Handle received packet. OnPacketReceived(pConn, packet); delete packet; nOffset = mem.GetCurrentOffset(); if( nOffset == nBufferSize ) break; } else break; } return true; }
int load_index(t_process *process, int i) { t_parameters param; param.o = 10; decode_ocp(process, ¶m, i); param.jump = 1 + g_op_tab[i].has_ocp; if (g_op_tab[i].has_ocp == 0) return (1); params_value(process, ¶m, i); if (check_registers(¶m, process, i) == 1 || g_op_tab[i].param_nbr < 3 || check_param_error(param, i) == 1 || g_op_tab[i].param_nbr > 4) return (param.jump); if (param.type[0] == REG_CODE) param.value[0] = RBE(process->registers[param.value[0] - 1], REG_SIZE); if (param.type[1] == REG_CODE) param.value[1] = RBE(process->registers[param.value[1] - 1], REG_SIZE); PV[0] = rm(mem(process->pc + PV[0] + PV[1], 1, PA, process), REG_SIZE, PP); if (param.type[2] == REG_CODE) WBE(PV[0], PR[PV[2] - 1], REG_SIZE); else if (param.type[2] == IND_CODE) wm(PV[0], mem(process->pc + PV[0], 1, PA, process), REG_SIZE, PP); return (param.jump); }
//Then see if page rank is initialized yet //If not, zero it out. If yes, go to add. GS_READ_MODE() { bit oldMode; mem_req_t memReq1; memReq1.rw = READ; memReq1.size = WORD; memReq1.addr = modeAddress(Input.pageId); memRep = mem(memReq1); oldMode = modeRead(memRep.data, Input.pageId); // if (oldMode ^ mode) { State = GS_READ_RANK; // } else { // State = GS_CHANGE_MODE; // } }
//Then see if page rank is initialized yet //If not, zero it out. If yest, go to add. GS_READ_MODE() { bit oldMode; mem_req_t memReq; memReq.rw = READ; memReq.size = WORD; memReq.addr = modeAddress(Input.pageId); memRep = mem(memReq); oldMode = modeRead(memRep.data); if (oldMode ^ mode) { State = GS_READ_RANK; } else { State = GS_CHANGE_MODE; } }
int main(int argc, char **argv){ bool memory = false; bool graphic = true; if(graphic) main1(argc, argv); if(memory){ Memory mem(MEDIUM); printf("starting..\n"); mem.play(); } }
int main() { LL A, B; cin>>x>>A>>B; ten_pow[0] = 1; mem( dp, -1); for(int i = 1; i < 15; i++) ten_pow[i] = (ten_pow[i-1]*10)%x; string dig; cin>>dig; mem(ava, false); for(char c : dig) ava[ c-'0' ] = 1; if( x <= 1000000 ) { cout<< solve(B) - solve(A-1) <<endl; }else { LL ans = 0; LL cur = 0; while( cur < A ) cur += x; while( cur <= B ) { if( check(cur) ) ans++; cur += x; } cout<<ans<<endl; } }
bool PokerHandHistory::Load(LongBinary* pBin){ if( !pBin || pBin->GetBinarySize() == 0 ) return false; void* lpBuffer = pBin->LockMemory(); if( !lpBuffer ) return false; GrowableMemory mem(0, 0, false); mem.SetReadonlyBuffer((BYTE*)lpBuffer, (int)pBin->GetBinarySize()); // Clear history info. ClearHistory(); // Deserialize. bool bRet = (Deserialize(&mem) == TRUE); pBin->UnlockMemory(); return bRet; }
bool DDSCompiler::process( const std::string& input, const std::string& output ) { FileReader ddsReader(input); if(!ddsReader.m_size) return false; uint32_t memSize = ddsReader.m_size + sizeof(Texture); MemoryBuffer mem(memSize); Texture* tex = (Texture*)mem.m_buf; tex->m_handle.idx = bgfx::invalidHandle; tex->m_data_size = ddsReader.m_size; tex->m_data_offset = sizeof(Texture); memcpy(mem.m_buf + sizeof(Texture), ddsReader.m_buf, ddsReader.m_size); return write_file(output, mem.m_buf, memSize); }
int main(int argc, char *argv[]) { printf(1, "usertests starting\n"); if(open("usertests.ran", 0) >= 0){ printf(1, "already ran user tests -- rebuild fs.img\n"); exit(); } close(open("usertests.ran", O_CREATE)); bigargtest(); bigwrite(); bigargtest(); bsstest(); sbrktest(); validatetest(); opentest(); writetest(); writetest1(); createtest(); mem(); pipe1(); preempt(); exitwait(); rmdot(); fourteen(); bigfile(); subdir(); concreate(); linkunlink(); linktest(); unlinkread(); createdelete(); twofiles(); sharedfd(); dirfile(); iref(); forktest(); bigdir(); // slow exectest(); exit(); }
status_t VBoxGuestDeskbarView::_Init(BMessage *archive) { BString toolTipText; toolTipText << VBOX_PRODUCT << " Guest Additions "; toolTipText << VBOX_VERSION_MAJOR << "." << VBOX_VERSION_MINOR << "." << VBOX_VERSION_BUILD; toolTipText << "r" << VBOX_SVN_REV; SetToolTip(toolTipText.String()); image_info info; if (our_image(info) != B_OK) return B_ERROR; BFile file(info.name, B_READ_ONLY); if (file.InitCheck() < B_OK) return B_ERROR; BResources resources(&file); if (resources.InitCheck() < B_OK) return B_ERROR; const void *data = NULL; size_t size; //data = resources.LoadResource(B_VECTOR_ICON_TYPE, // kNetworkStatusNoDevice + i, &size); data = resources.LoadResource('data', 400, &size); if (data != NULL) { BMemoryIO mem(data, size); fIcon = BTranslationUtils::GetBitmap(&mem); } int rc = RTR3InitDll(RTR3INIT_FLAGS_UNOBTRUSIVE); if (RT_SUCCESS(rc)) { rc = VbglR3Init(); if (RT_SUCCESS(rc)) { fClipboardService = new VBoxClipboardService(); fDisplayService = new VBoxDisplayService(); } else LogRel(("VBoxGuestDeskbarView::_init VbglR3Init failed. rc=%d\n", rc)); } else LogRel(("VBoxGuestDeskbarView::_init RTR3InitDll failed. rc=%d\n", rc)); return RTErrConvertToErrno(rc); }
char * var_name_nomap_ASL(ASL *asl, int n, int *p /* not used */) { char buf[32], **np, *rv; if (n < 0 || n >= asl->i.n_var1) return badvarname; if (!asl->i.varnames) asl->i.varnames = get_names(asl, ".col", 0, asl->i.n_var0); np = asl->i.varnames + n; if (!(rv = *np)) { *np = rv = (char*)mem(Sprintf(buf,"_svar[%d]",n+1)+1); strcpy(rv, buf); } return rv; }
virtual double Execute() const { static const uint8_t Z80_TEST_IO[] = { 0xf3, //di 0x01, 0x00, 0x00, //ld bc,0 //loop: 0xed, 0x78, //in a,(c) 0xd3, 0x00, //out (0),a 0x18, 0xfa //jr loop }; Dump mem(Z80_TEST_IO, boost::end(Z80_TEST_IO)); mem.resize(65536); const Devices::Z80::Chip::Ptr dev = CreateDevice(UINT64_C(3500000), 24, mem, boost::make_shared<Z80Ports>()); return Test(*dev, TEST_DURATION, FRAME_DURATION); }
TEST_F(SyncedMemoryTest, TestCPUWrite) { SyncedMemory mem(10); void* cpu_data = mem.mutable_cpu_data(); EXPECT_EQ(mem.head(), SyncedMemory::HEAD_AT_CPU); caffe_memset(mem.size(), 1, cpu_data); for (int i = 0; i < mem.size(); ++i) { EXPECT_EQ((static_cast<char*>(cpu_data))[i], 1); } // do another round cpu_data = mem.mutable_cpu_data(); EXPECT_EQ(mem.head(), SyncedMemory::HEAD_AT_CPU); caffe_memset(mem.size(), 2, cpu_data); for (int i = 0; i < mem.size(); ++i) { EXPECT_EQ((static_cast<char*>(cpu_data))[i], 2); } }
BOOL TrueTypeImport::BuildCharacter(UINT index, float height, BezierShape &shape, float &width, int fontShapeVersion) { assert(hFont); if(!hFont) return 0; // Set up for the font and release it when this function returns FontReady fontRdy(hFont); // allocate space for the bitmap/outline GLYPHMETRICS gm; // init it to prevent UMR in GetGlyphOutline gm.gmBlackBoxX = gm.gmBlackBoxY = gm.gmptGlyphOrigin.x = gm.gmptGlyphOrigin.y = gm.gmCellIncX = gm.gmCellIncY = 0; // Give it an identity matrix MAT2 mat; IdentityMat(&mat); // get unicode outline DWORD size= GetGlyphOutlineW(fontRdy.hdc, index, GGO_GLYPH_INDEX|GGO_NATIVE, &gm, 0, NULL, &mat); if(size != GDI_ERROR && size > 0) { GenericAlloc mem(size); if(!mem.ptr) goto failure; // get unicode outline if ((GetGlyphOutlineW(fontRdy.hdc, index, GGO_GLYPH_INDEX|GGO_NATIVE, &gm, size, mem.ptr, &mat)) != size) goto failure; curSpline = NULL; // reset the current spline pointer if(!CreateCharacterShape((TTPOLYGONHEADER *)mem.ptr, size, shape, fontShapeVersion)) goto failure; // Make sure the height matches the request float scaleFactor = height / 1000.0f; Matrix3 tm = ScaleMatrix(Point3(scaleFactor, scaleFactor, 0.0f)); shape.Transform(tm); width = float(gm.gmCellIncX) * scaleFactor; return TRUE; } // Character wasn't found! failure: width = 0.0f; return FALSE; }
unamstring(register Addrp q, register char *s) #endif { register int k; register char *t; k = strlen(s); if (k < IDENT_LEN) { q->uname_tag = UNAM_IDENT; t = q->user.ident; } else { q->uname_tag = UNAM_CHARP; q->user.Charp = t = mem(k+1, 0); } strcpy(t, s); }
void IgniteEnvironment::OnStartCallback(long long memPtr) { InteropExternalMemory mem(reinterpret_cast<int8_t*>(memPtr)); InteropInputStream stream(&mem); BinaryReaderImpl reader(&stream); int32_t nameLen = reader.ReadString(NULL, 0); if (nameLen >= 0) { name = new char[nameLen + 1]; reader.ReadString(name, nameLen + 1); } else name = NULL; }
char * lcon_name_ASL(ASL *asl, int n) { char buf[32], **np, *rv; static char badlconname[] = "**lcon_name(bad n)**"; if (n < 0 || n >= n_lcon) return badlconname; if (!asl->i.lconnames) get_row_names(asl); np = asl->i.lconnames + n; if (!(rv = *np)) { *np = rv = (char*)mem(Sprintf(buf,"_slogcon[%d]",n+1)+1); strcpy(rv, buf); } return rv; }