void main() { RedType d[N]={{49,1},{38,2},{65,3},{97,4},{76,5},{13,6},{27,7},{49,8}}; SLinkListType l1; int *adr,i; TableInsert(&l1,d,N); printf("排序前:\n"); print(l1); Arrange(&l1); printf("l1排序后:\n"); print(l1); }
void main() { RedType d[N]={{49,1},{38,2},{65,3},{97,4},{76,5},{13,6},{27,7},{49,8}}; SLinkListType l1,l2; int *adr,i; TableInsert(&l1,d,N); l2=l1; /* 复制静态链表l2与l1相同 */ printf("排序前:\n"); print(l1); Arrange(&l1); printf("l1排序后:\n"); print(l1); adr=(int*)malloc((l2.length+1)*sizeof(int)); Sort(l2,adr); for(i=1;i<=l2.length;i++) printf("adr[%d]=%d ",i,adr[i]); printf("\n"); Rearrange(&l2,adr); printf("l2排序后:\n"); print(l2); }
void Insert(State* s) { State* existing = TableFind(s); if (existing) { if (s->Distance() < existing->Distance()) { existing->distance_so_far = s->distance_so_far; existing->distance_to_goal = s->distance_to_goal; existing->parent = s->parent; if (existing->heap_index >= 0) { HeapUpdatePriority(existing->heap_index); } else { HeapInsert(existing); } } else if (existing->heap_index == -1) { HeapInsert(existing); } } else { TableInsert(s); HeapInsert(s); } }
int CWorldDbmgr::FromRpcCall(CPluto& u, CDbOper& db) { //printf("CWorldDbmgr::from_rpc_call\n"); //print_hex_pluto(u); pluto_msgid_t msg_id = -1; T_VECTOR_OBJECT* p = NULL; //这一段要加锁(2012/02/15改为不加锁) { //CMutexGuard _g(m_rpcMutex); msg_id = u.GetMsgId(); if(!CheckClientRpc(u)) { LogWarning("from_rpc_call", "invalid rpcall error.unknown msgid:%d\n", msg_id); return -1; } p = m_rpc.Decode(u); if(p == NULL) { LogWarning("from_rpc_call", "rpc Decode error.unknown msgid:%d\n", msg_id); return -1; } if(u.GetDecodeErrIdx() > 0) { ClearTListObject(p); //PrintHexPluto(u); LogWarning("from_rpc_call", "rpc Decode error.msgid:%d;pluto err idx=%d\n", msg_id, u.GetDecodeErrIdx()); return -2; } } //这一段不用加锁 int nRet = -1; switch(msg_id) { case MSGID_DBMGR_INSERT_ENTITY: { nRet = InsertDB(p, db); break; } case MSGID_DBMGR_SELECT_ENTITY: { nRet = LookupEntityByDbId(p, db); break; } case MSGID_DBMGR_UPDATE_ENTITY: { nRet = UpdateEntity(p, db); break; } case MSGID_DBMGR_UPDATE_ENTITY_REDIS: { nRet = UpdateEntityToRedis(p, db); break; } case MSGID_DBMGR_SELECT_ACCOUNT: { nRet = SelectAccount(p, db); break; } case MSGID_DBMGR_RAW_MODIFY_NORESP: { nRet = QueryModifyNoResp(p, db); break; } case MSGID_DBMGR_CREATEBASE_FROM_NAME: { nRet = LookupEntityByName(p, db); break; } case MSGID_DBMGR_LOAD_ALL_AVATAR: { nRet = LoadAllAvatars(p, db); break; } case MSGID_DBMGR_LOAD_ENTITIES_OF_TYPE: { nRet = LoadEntitiesOfType(p, db); break; } case MSGID_DBMGR_SHUTDOWN_SERVER: { nRet = ShutdownServer(p); break; } case MSGID_DBMGR_REDIS_HASH_LOAD: { nRet = RedisHashLoad(p, db); break; } case MSGID_DBMGR_REDIS_HASH_SET: { nRet = RedisHashSet(p, db); break; } case MSGID_DBMGR_REDIS_HASH_DEL: { nRet = RedisHashDel(p, db); break; } case MSGID_DBMGR_DEL_ACCOUNT_CACHE: { nRet = DestroyAccountCache(p); break; } case MSGID_DBMGR_UPDATE_ITEMS: { nRet = UpdateArrayItemsToDb(p, db); break; } case MSGID_DBMGR_LOADING_ITEMS: { nRet = LoadingArrayItemsToInventory(p, db); break; } case MSGID_DBMGR_INCREMENTAL_UPDATE_ITEMS: { nRet = IncremantalUpdateItems(p, db); break; } case MSGID_DBMGR_TABLE_SELECT: { nRet = TableSelect(p, db); break; } case MSGID_DBMGR_UPDATE_BATCH: { nRet = TableUpdateBatch(p, db); break; } case MSGID_DBMGR_TABLE_INSERT: { nRet = TableInsert(p, db); break; } case MSGID_DBMGR_TABLE_EXCUTE: { nRet = TableExcute(p, db); break; } case MSGID_DBMGR_TABLE2_SELECT: { nRet = Table2Select(p, db); break; } case MSGID_DBMGR_TABLE2_INSERT: { nRet = Table2Insert(p, db); break; } case MSGID_DBMGR_TABLE2_EXCUTE: { nRet = Table2Excute(p, db); break; } default: { break; } } if(nRet != 0) { LogWarning("from_rpc_call", "rpc error.msg_id=%d;ret=%d\n", msg_id, nRet); } ClearTListObject(p); return 0; }