SYMBTBL.Cpp
资源名称:ictprop.rar [点击查看]
上传用户:tenhai
上传日期:2021-02-19
资源大小:492k
文件大小:1k
源码类别:
组合框控件
开发平台:
Visual C++
- #include "stdafx.h"
- #include "symbol.h"
- #include "symbtbl.h"
- tblsearch(symbol_node_ref_tbl_t *ptbl, char* token){
- int cond;
- int low=0, high=ptbl->tblsize-1, mid;
- /*binary search*/
- while (low<=high){
- mid=(low+high)/2;
- if ((cond=strcmp(token, ptbl->tblbody[mid]->literal))<0)
- high=mid-1;
- else
- if (cond>0)
- low=mid+1;
- else{
- ptbl->currpos=mid;
- return 1;
- }
- }
- ptbl->currpos=low;
- return 0;
- }
- tblinsert(symbol_node_ref_tbl_t *ptbl, symbol_node_t *pnews){
- int ptr;
- for (ptr=ptbl->tblsize;ptr>ptbl->currpos;ptr--)
- ptbl->tblbody[ptr]=ptbl->tblbody[ptr-1];
- ptbl->tblbody[ptbl->currpos]=pnews;
- return ++ptbl->tblsize;
- }
- tblremove(symbol_node_ref_tbl_t *ptbl, symbol_node_t **ppnews){
- unsigned int ptr;
- *ppnews=ptbl->tblbody[ptbl->currpos];
- for (ptr=ptbl->currpos+1;ptr<ptbl->tblsize;ptr++)
- ptbl->tblbody[ptr-1]=ptbl->tblbody[ptr];
- return --ptbl->tblsize;
- }
- tblappend(symbol_node_ref_tbl_t *ptbl, symbol_node_t *pnews){
- ptbl->currpos=ptbl->tblsize;
- ptbl->tblbody[ptbl->tblsize++]=pnews;
- return 0;
- }
- tblclear(symbol_node_ref_tbl_t *ptbl){
- unsigned int idx;
- for (idx=0;idx<ptbl->tblsize;idx++)
- ptbl->tblbody[idx]=NULL;
- ptbl->tblsize=0;
- ptbl->currpos=0;
- return 0;
- }