int main( void ) { /* freopen("in.txt", "r", stdin);*/ freopen("out.txt", "w", stdout); HashTable * H = ( HashTable * )malloc( MAX * sizeof ( HashTable ) ); int key, temp; InitTable( &H ); InTable( &H ); while ( scanf("%d", &key) != EOF ) { if ( 0 == key ) break; temp = Search( &H, key ); if ( temp == ERROR ) printf("查找失败!元素%d不存在于该表中.\n", key); else printf("查找成功!元素%d位于表中的第%2d位置.\n", key, temp + 1); } return 0; }
void PageFourQuadTable::Init(TransDataTable<3> &table,int num) { ShowFB(); InitRow(num); InitTable(table,m_list); UpdateData(FALSE); }
void Init() { LCount = 0; InitTable(); GetChar(); }
/* initialize */ void Init() { GetChar(); SkipWhite(); InitTable(); ClearParams(); }
/*------------------------------------------------------------------------- Setup the renderer. ------------------------------------------------------------------------*/ bool Initialize(VideoClass* Video, char* ProfCurve, float ProfEquLim, dword NewTabRes) { //No NULL pointers please if (Video == NULL) {return false;} //Ensure that the Video uses the correct interface, // and the Video mode is valid. if ((Video->CurrentDevice != VIDEO_OPENGL) || !Video->ModeValid) {return false;} //Compile the profile curve equation if (ProfCurve != NULL) { str_append(ProfEqu, ProfCurve); ProfCode = EquSolver.Compile(ProfEqu); if (ProfCode == NULL) {printf("RenderOpenGLClass::Initialize( ): EquSolver.Compile( ) failed.\n\tPossible syntax error in profile curve equation.\n"); return false;} if (!EquSolver.Debug(ProfCode)) {return false;} ProfEquLimR = ProfEquLim; //Setup the transformation table if (!InitTable(Video, ProfCode, ProfEquLim, NewTabRes)) {printf("RenderOpenGLClass::Initialize( ): TransformClass::InitTable( ) failed.\n"); return false;} } //Setup other data members CamApeture.X = Video->XY_Ratio / CamApeture.X; CamApeture.Y = 1.0f / CamApeture.Y; RenderValid = true; //Indicate that rendering is allowed return true; }
//测试函数 void Test() { HashTable T; InitTable(&T); //插入序列 int pIn[13] = { 0, 3, 6, 5, 7, 10, 23, 89, 100, 111, 81,91,93}; //int pIn[10] = { 0, 3, 6, 5, 7, 10, 23, 89, 100, 111}; //搜索序列 int pSe[11] = {11, 3, 6, 5, 7, 0 , 23, 89, 100, 111, 80 }; printf("插入序列:\n"); for (int i = 0; i < 13; i++) { printf("%d- ",i); InsertToTable(&T, pIn[i]); } printf("\n搜索序列:\n"); for (int i = 0; i < 11; i++) { int nCom = 0; printf("%d- ",i); printf("目标:%3d 哈希值:%2d 结果: %2d",pSe[i],GetHash(T,pSe[i]),SearchTable(T, pSe[i], &nCom)); printf(" 比较:%3d\n", nCom); } DestroyTable(&T); }
//读取JPEG代码,并解码 BOOL LoadJpegFile (const unsigned char *JpegFileName) { DWORD JpegBufSize; const unsigned char *hJpegBuf; int funcret; hJpegBuf=JpegFileName;//JPEG文件头 lpJpegBuf=(unsigned char*)hJpegBuf;//转换为变量指针 InitTable(); if((funcret=InitTag())!=FUNC_OK)//初始化表头不成功 { showerror(funcret);//错误信息显示 return FALSE; } if((SampRate_Y_H==0)||(SampRate_Y_V==0)) { return FALSE ; } funcret=Decode(); if(funcret==FUNC_OK)//解码成功 { return TRUE; } else { return FALSE; } }
int main() { Table table; InitTable(&table); AddTable(&table, 1, 0, 1); AddTable(&table, 1, 1, 2); AddTable(&table, 1, 2, 3); DisplayTable(&table); printf("\n"); int valid = 1; int dst_addr = 0; int out_link_id = 10; UpdateTable(&table, valid, dst_addr, out_link_id); DisplayTable(&table); /* int index = FindTableIndex(&table, dst_addr); if (index == ERROR) { printf("inserting new entry to table\n"); AddTable(&table, valid, dst_addr, out_link_id); } else { printf("updating entry %d\n", dst_addr); UpdateTableByIndex(&table, index, valid, out_link_id); } */ printf("OutLink for dst_addr = %d is %d\n", dst_addr, GetOutLink(&table, dst_addr)); return 0; }
void CTab4::OnPaint() { CPaintDC dc(this); // device context for painting // TODO: 在此处添加消息处理程序代码 CFont font; font.CreatePointFont(100, _T("微软雅黑")); //选择字体 m_edit.SetFont(&font); font.CreatePointFont(150, _T("微软雅黑")); m_title.SetFont(&font); pPic = (CStatic*)GetDlgItem(IDC_STATIC);//获取控件 pDC = pPic->GetWindowDC();//获取设备环境 if (firstrun) { pPic->GetClientRect(r); x_m = r.Width(); y_m = r.Height(); MemDC.CreateCompatibleDC(pDC); bm.CreateCompatibleBitmap(pDC, x_m, y_m); MemDC.SelectObject(&bm); InitTable(); firstrun = false; } pDC->BitBlt(0, 0, x_m, y_m, &MemDC, 0, 0, SRCAND); // 不为绘图消息调用 CDialogEx::OnPaint() }
//--------------------------------------------------------------------------- void __fastcall TFormInsertVoc::ComboBoxKeyChange(TObject *Sender) { ClearTable(); AnsiString vkey; vkey=(ComboBoxKey->ItemIndex==0)? AnsiString("WHERE deleted=0") : AnsiString("WHERE vkey=\'"+GetKeyForHint(ComboBoxKey->Text)+"\' AND deleted=0"); if (SortIndex==DEFAULT_INDEX_SORT) SortIndex=1; AnsiString Order=VocKeys[SortIndex]; if (!flagSortUp) // По убыванию Order=Order+" DESC"; InitTable(vkey,Order); AnsiString arrowStr; if (flagSortUp) arrowStr="\\/";else arrowStr="/\\"; InitTitlesGrid(StrGridVoc,3,0,0,titles); InitTitleGrid(StrGridVoc,SortIndex,0,titles[SortIndex]+" "+arrowStr); StrGridVoc->OnClick(StrGridVoc); if (ComboBoxKey->ItemIndex==0) { Edittitle->Enabled=false; BtnAdd->Enabled=false; //BtnDel->Enabled=false; BtnEdit->Enabled=false; } else { Edittitle->Enabled=true; BtnAdd->Enabled=true; //BtnDel->Enabled=true; BtnEdit->Enabled=true; } }
CFontStyle::CFontStyle(const char *name, const char *style, f_unit_t size) : fLock("font lock") { fEscapementsCount = 0; fEscapements = NULL; fCharCount = 0; fFont.SetFamilyAndStyle(name, style); fFont.SetSize(size); InitTable(); } /* CFontStyle::CFontStyle */
char* LoadJpegFile (char *jpegbuf, char *bmpbuf) { DWORD ImgSize; DWORD JpegBufSize; int funcret; LPBITMAPINFOHEADER lpImgData; //JpegBufSize=size; lpJpegBuf=jpegbuf; InitTable(); if((funcret=InitTag())!=FUNC_OK) { showerror(funcret); return NULL; } //create new bitmapfileheader and bitmapinfoheader memset((char *)&bf,0,sizeof(BITMAPFILEHEADER)); memset((char *)&bi,0,sizeof(BITMAPINFOHEADER)); bi.biSize=(DWORD)sizeof(BITMAPINFOHEADER); bi.biWidth=(LONG)(ImgWidth); bi.biHeight=(LONG)(ImgHeight); bi.biPlanes=1; bi.biBitCount=24; bi.biClrUsed=0; bi.biClrImportant=0; bi.biCompression=BI_RGB; NumColors=0; LineBytes=(DWORD)WIDTHBYTES(bi.biWidth*bi.biBitCount); ImgSize=(DWORD)LineBytes*bi.biHeight; bf.bfType=0x4d42; bf.bfSize=/*sizeof(BITMAPFILEHEADER)*/ 14+sizeof(BITMAPINFOHEADER)+NumColors*sizeof(RGBQUAD)+ImgSize; bf.bfOffBits=(DWORD)(NumColors*sizeof(RGBQUAD)+14/*sizeof(BITMAPFILEHEADER)*/+sizeof(BITMAPINFOHEADER)); lpPtr = (char*)bmpbuf + 54; if((SampRate_Y_H==0)||(SampRate_Y_V==0)) { showerror(FUNC_FORMAT_ERROR); return NULL ; } funcret=Decode(); memcpy(bmpbuf, &bf.bfType,sizeof(WORD)); memcpy(bmpbuf+2, ((char*)&bf)+4, 12); memcpy(bmpbuf+14, (LPSTR)&bi,sizeof(BITMAPINFOHEADER)); if(funcret!=FUNC_OK) { showerror(funcret); return NULL; } return lpPtr; }
int TDBXCL::GetMaxSize(PGLOBAL g) { if (MaxSize < 0) { if (InitTable(g)) return 0; MaxSize = Mult * Tdbp->GetMaxSize(g); } // endif MaxSize return MaxSize; } // end of GetMaxSize
ALERROR CRandomItems::OnDesignLoadComplete (SDesignLoadCtx &Ctx) // OnDesignLoadComplete // // Resolve references { InitTable(); return NOERROR; }
int TDBPRX::Cardinality(PGLOBAL g) { if (Cardinal < 0) { if (InitTable(g)) return 0; Cardinal = Tdbp->Cardinality(g); } // endif MaxSize return Cardinal; } // end of GetMaxSize
ALERROR CRandomItems::OnDesignLoadComplete (SDesignLoadCtx &Ctx) // OnDesignLoadComplete // // Resolve references { if (!m_bDynamicLevelFrequency) InitTable(m_sLevelFrequency); return NOERROR; }
bool TDBPRX::OpenDB(PGLOBAL g) { if (Use == USE_OPEN) { /*******************************************************************/ /* Table already open, just replace it at its beginning. */ /*******************************************************************/ return Tdbp->OpenDB(g); } // endif use if (InitTable(g)) return true; else if (Mode != MODE_READ && (Read_Only || Tdbp->IsReadOnly())) { strcpy(g->Message, "Cannot modify a read only table"); return true; } // endif tp /*********************************************************************/ /* Check and initialize the subtable columns. */ /*********************************************************************/ for (PCOL cp = Columns; cp; cp = cp->GetNext()) if (((PPRXCOL)cp)->Init(g, Tdbp)) return true; /*********************************************************************/ /* In Update mode, the updated column blocks must be distinct from */ /* the read column blocks. So make a copy of the TDB and allocate */ /* its column blocks in mode write (required by XML tables). */ /*********************************************************************/ if (Mode == MODE_UPDATE) { PTDBASE utp; if (!(utp= (PTDBASE)Tdbp->Duplicate(g))) { sprintf(g->Message, MSG(INV_UPDT_TABLE), Tdbp->GetName()); return true; } // endif tp for (PCOL cp = To_SetCols; cp; cp = cp->GetNext()) if (((PPRXCOL)cp)->Init(g, utp)) return true; } else if (Mode == MODE_DELETE) Tdbp->SetNext(Next); /*********************************************************************/ /* Physically open the object table. */ /*********************************************************************/ if (Tdbp->OpenDB(g)) return true; Tdbp->SetNext(NULL); Use = USE_OPEN; return false; } // end of OpenDB
BOOL CJobListView::OnInitDialog() { CCodPropertyPage::OnInitDialog(); InitTable(&m_RunningJobList); InitTable(&m_PendingJobList); m_RunningJobList.DeleteAllItems(); m_PendingJobList.DeleteAllItems(); ASSERT_VALID(m_pDoc); ASSERT(NULL != m_pDoc->m_pJobList); for (CJobList::iterator JobIterator = m_pDoc->m_pJobList->begin(); JobIterator != m_pDoc->m_pJobList->end(); JobIterator++) AddJob(&*JobIterator); m_RunningBtn.SetCheck(1); UpdateData(FALSE); ShowHideLists(); return TRUE; }
BOOL CParser::ParseTable(DWORD dwUserData) /***********************************************************************/ { BOOL fRet = TRUE; LPSTR lpString, lpEntryString, lpKey, lpValues; int nIndex, nValues; HPTR lpData; LPSTR lpStringBuf, lpEntryStringBuf; if (!InitTable(dwUserData)) return(FALSE); lpStringBuf = (LPSTR)Alloc(BUFFER_SIZE); lpEntryStringBuf = (LPSTR)Alloc(BUFFER_SIZE); if (!lpStringBuf || !lpEntryStringBuf) { if (lpStringBuf) FreeUp(lpStringBuf); if (lpEntryStringBuf) FreeUp(lpEntryStringBuf); return(FALSE); } nIndex = 0; lpData = m_lpTableData; while ( GetEntryString( &lpData, lpEntryStringBuf, BUFFER_SIZE ) ) { // Keep a copy of the Entry string for error messages lpString = lpStringBuf; lpEntryString = lpEntryStringBuf; lstrcpy(lpString, lpEntryString); // get key while (lpKey = GetKey( &lpEntryString )) { // get value if (lpValues = GetValues( &lpEntryString, &nValues )) { // handle this entry if (!HandleKey(lpString, lpKey, lpValues, nValues, nIndex, dwUserData)) { fRet = FALSE; break; } } } // process next entry ++nIndex; } FreeUp(lpStringBuf); FreeUp(lpEntryStringBuf); return(fRet); }
void ExtensionEntryPoints::Unload() { for (int i = 0; i < libs_.size(); i++) { void* ptr = os::GetExportAddress(libs_[i], "Unload"); if (ptr) { ((Unload_t)ptr)(); } } for (int i = 0; i < libs_.size(); i++) { os::CloseLib(libs_[i]); } libs_.clear(); InitTable(); }
bool TDBOCCUR::OpenDB(PGLOBAL g) { if (Use == USE_OPEN) { /*******************************************************************/ /* Table already open, just replace it at its beginning. */ /*******************************************************************/ N = M = 0; RowFlag = 0; if (Xcolp) Xcolp->Xreset(); return Tdbp->OpenDB(g); } // endif use if (Mode != MODE_READ) { /*******************************************************************/ /* Currently OCCUR tables cannot be modified. */ /*******************************************************************/ strcpy(g->Message, "OCCUR tables are read only"); return TRUE; } // endif Mode /*********************************************************************/ /* Do it here if not done yet. */ /*********************************************************************/ if (InitTable(g)) return TRUE; if (Xcolp) // Lock this column so it is evaluated by its table only Xcolp->AddStatus(BUF_READ); if (To_Key_Col || To_Kindex) { /*******************************************************************/ /* Direct access of OCCUR tables is not implemented yet. */ /*******************************************************************/ strcpy(g->Message, "No direct access to OCCUR tables"); return TRUE; } // endif To_Key_Col /*********************************************************************/ /* Do open the source table. */ /*********************************************************************/ if (Tdbp->OpenDB(g)) return TRUE; Use = USE_OPEN; return ViewColumnList(g); } // end of OpenDB
void Model::RestartGame(int m,int n,int bombs) { isGameOver = false; isGameWin = false; mtable = m; ntable = n; numberOfBombs = bombs; minutesPassed = 0; secondsPassed = 0; GenerateBombs(ntable*mtable); InitTable(mtable, ntable,numberOfBombs); NotifyObservers(Change::TIME); NotifyObservers(Change::TABLE); }
//智能画图 //FileName:要显示的图片文件 BMP/JPG/JPEG //(sx,sy) :开始显示的坐标点 //(ex,ey) :结束显示的坐标点 //图片在开始和结束的坐标点范围内显示 BOOL AI_LoadPicFile(u8 *filename,u16 sx,u16 sy,u16 ex,u16 ey) {// FIL* f_bmp; int funcret;//返回值 //得到显示方框大小 u8 fileTpe; int index; for( index=0;index<1024;index++) iclip[index]=0; if(ey>sy)PICINFO.S_Height=ey-sy; else PICINFO.S_Height=sy-ey; if(ex>sx)PICINFO.S_Width=ex-sx; else PICINFO.S_Width=sx-ex; //显示区域无效 if(PICINFO.S_Height==0||PICINFO.S_Width==0) { PICINFO.S_Height=LCD_H; PICINFO.S_Width=LCD_W; return FALSE; } //影响速度 //SD_Init();//初始化SD卡,在意外拔出之后可以正常使用 //显示的开始坐标点 PICINFO.S_YOFF=sy; PICINFO.S_XOFF=sx; fileTpe=f_typetell((u8*)filename); //得到文件的类型 if(fileTpe==T_BMP)//得到一个BMP图像 { funcret=BmpDecode(filename); //得到一个BMP图像 return funcret; } else if(fileTpe==T_JPG||fileTpe==T_JPEG)//得到JPG/JPEG图片 { funcret=f_open(f_jpeg,(const TCHAR*)filename,FA_READ);//打开文件 if(funcret==FR_OK){ f_read(f_jpeg,jpg_buffer,1024,(UINT*)&br); InitTable(); if((funcret=InitTag())!=FUNC_OK)return FALSE; if((SampRate_Y_H==0)||(SampRate_Y_V==0))return FALSE ; AI_Drow_Init(); funcret=Decode(); } f_close(f_jpeg); }else return FALSE; //非图片格式!!! if(funcret==FUNC_OK)return TRUE;//解码成功 else return FALSE; //解码失败 }
CurrencyValue CRandomItems::GetAverageValue (int iLevel) // GetAverageValue // // Returns the average value. { int i; // If this is a dynamic table we need to compute all levels if (m_bDynamicLevelFrequency) { Metric rTotal = 0.0; InitTable(GenerateLevelFrequency(m_sLevelFrequency, iLevel)); m_iDynamicLevel = iLevel; for (i = 0; i < m_iCount; i++) { CItemType *pType = m_Table[i].pType; CurrencyValue ItemValue = CEconomyType::ExchangeToCredits(pType->GetCurrencyType(), pType->GetValue(CItemCtx(), true)); rTotal += (pType->GetNumberAppearing().GetAveValueFloat() * (Metric)ItemValue * (Metric)m_Table[i].iProbability / 1000.0); } return (CurrencyValue)(rTotal + 0.5); } // Otherwise the table is already initialized. else { // Average value is proportional to chances. Metric rTotal = 0.0; for (i = 0; i < m_iCount; i++) { CItemType *pType = m_Table[i].pType; CurrencyValue ItemValue = CEconomyType::ExchangeToCredits(pType->GetCurrencyType(), pType->GetValue(CItemCtx(), true)); rTotal += (pType->GetNumberAppearing().GetAveValueFloat() * (Metric)ItemValue * (Metric)m_Table[i].iProbability / 1000.0); } return (CurrencyValue)(rTotal + 0.5); } }
WatchesTable::WatchesTable( wxWindow* parent ) : SimpleTableBase( parent ) , m_selectedId(wxNOT_FOUND) { InitTable(); //Load the right click menu m_rclickMenu = wxXmlResource::Get()->LoadMenu(wxT("dbg_watch_rmenu")); Connect(XRCID("del_expr"),wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( WatchesTable::OnDeleteWatch), NULL, this); Connect(XRCID("del_expr_all"),wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( WatchesTable::OnDeleteAll), NULL, this); Connect(XRCID("expand_expr"),wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( WatchesTable::OnMenuExpandExpr), NULL, this); Connect(XRCID("edit_expr"),wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( WatchesTable::OnMenuEditExpr), NULL, this); Connect(XRCID("copy_expr"),wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( WatchesTable::OnMenuCopyExpr), NULL, this); Connect(XRCID("copy_both"),wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( WatchesTable::OnMenuCopyBoth), NULL, this); Connect(XRCID("copy_value"),wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( WatchesTable::OnMenuCopyValue), NULL, this); Connect(XRCID("dereference_expr"),wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( WatchesTable::OnMenuDerefExpr), NULL, this); Connect(XRCID("add_watch"), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( WatchesTable::OnNewWatch_Iternal), NULL, this); }
void PrimesTable::GenerateTable() { PrimesTable::TableBuffer TempTable_; Ulong Number_; InitTable(); for (Number_ = LOOKAHEAD; Number_ <= MAXENTRIES; ++Number_) { GenerateTableHelper(Number_, TempTable_); if (_TableIndex && _TableIndex % TABLESIZE == 0) StoreTable(); } StoreTable(); _File.seekp(0); _Bitv.BinaryWrite(_File); _File.write((char*)(&_TotalSize), sizeof(long)); }
bool TDBXCL::OpenDB(PGLOBAL g) { if (Use == USE_OPEN) { /*******************************************************************/ /* Table already open, just replace it at its beginning. */ /*******************************************************************/ M = N = 0; RowFlag = 0; New = TRUE; return Tdbp->OpenDB(g); } // endif use if (Mode != MODE_READ) { /*******************************************************************/ /* Currently XCOL tables cannot be modified. */ /*******************************************************************/ strcpy(g->Message, "XCOL tables are read only"); return TRUE; } // endif Mode if (InitTable(g)) return TRUE; /*********************************************************************/ /* Check and initialize the subtable columns. */ /*********************************************************************/ for (PCOL cp = Columns; cp; cp = cp->GetNext()) if (!cp->IsSpecial()) if (((PPRXCOL)cp)->Init(g, NULL)) return TRUE; /*********************************************************************/ /* Physically open the object table. */ /*********************************************************************/ if (Tdbp->OpenDB(g)) return TRUE; Use = USE_OPEN; return FALSE; } // end of OpenDB
void FZipExploder::InsertCode(TArray<HuffNode> &decoder, unsigned int pos, int bits, unsigned short code, int len, unsigned char value) { assert(len > 0); unsigned int node = pos + (code & ((1 << bits) - 1)); if (len > bits) { // This code uses more bits than this level has room for. Store the bottom bits // in this table, then proceed to the next one. unsigned int child = decoder[node].ChildTable; if (child == 0) { // Need to create child table. child = InitTable(decoder, 1 << REST_BIT_LEN); decoder[node].ChildTable = child; decoder[node].Length = bits; decoder[node].Value = 0; } else { assert(decoder[node].Length == bits); assert(decoder[node].Value == 0); } InsertCode(decoder, child, REST_BIT_LEN, code >> bits, len - bits, value); }
void SettingsWindow::FillMainBox() { InitTable(); InitTreeView(); Gtk::VBox* vbox = get_vbox(); Gtk::Frame* frame; Gtk::VBox* frame_vbox; frame = Gtk::manage(new Gtk::Frame(gettext("Misc Options"))); frame->add( f_table ); frame_vbox = Gtk::manage(new Gtk::VBox); frame_vbox->pack_start( *frame, true, true ); vbox->pack_start( *frame_vbox, true, true ); // frame = Gtk::manage(new Gtk::Frame(gettext("Settings"))); frame->add( f_treeView ); frame_vbox = Gtk::manage(new Gtk::VBox); frame_vbox->pack_start( *frame, true, true ); vbox->pack_start( *frame_vbox, true, true ); show_all_children(); }
void InitWindow::SetCharacters( pair_t& charPairList ) { f_chars.clear(); f_monsters.clear(); for( auto& pair : charPairList ) { Character::pointer_t ch( new Character ); assert(ch); ch->Copy( pair.f_origChar ); // if( ch->monster() ) { f_monsters.push_back( ch ); } else { f_chars.push_back( ch ); } // pair.f_newChar = ch; } auto lt_charcmp = []( Character::pointer_t c1, Character::pointer_t c2 ) -> bool { return c1->name() < c2->name(); }; // Sort the characters/monsters by name // std::stable_sort( f_chars.begin() , f_chars.end() , lt_charcmp ); std::stable_sort( f_monsters.begin(), f_monsters.end(), lt_charcmp ); // Add chars/monsters to the table // InitTable(); }