Files
svc.ems/plat/public/src/include/bisearch.h
2024-09-27 15:39:34 +08:00

124 lines
5.4 KiB
C

/******************************************/
/*Title : bisearch.h */
/*Descr : BiSearch arithmetic Structure */
/*Author : Liu Wei */
/*Create : 2006-12-13 */
/*Version : R1V00_01 */
/*Modify : 2006-12-13 */
/******************************************/
#ifndef _BISEARCH_H_
#define _BISEARCH_H_
#define LL long long
#define u8 unsigned char
typedef struct BiSearch
{
LL llKey; //BiSearch Array Node Key
int nDUPosIndex; //Data Unit array Position Index
}
BiSearch;
#define BS_SIZE sizeof(BiSearch)
typedef struct BiSearchArray
{
int nArrayCount;
int nArrayTotalLen;
BiSearch *pBiArray; //SearchArray pointer
int (*GetIdleNodeFunc)(int* nDUIndex);
}
BiSearchArray;
/*********************************************************************/
/*BiSearchReg : Init BiSearch Struct, Alloc BiSearch Memery */
/*Return : [0]:BiSearchReg fail [1] :BiSearchReg Success */
/*********************************************************************/
extern int BISearchReg ( BiSearchArray * pBSA, int nTotalSize ,void *GetIdleNodeFunc );
/*********************************************************************/
/*BiSearchUnReg : Release BiSearch Memery */
/*Return : [0]:BiSearchUnReg fail [1] :BiSearchUnReg Success */
/*********************************************************************/
int BISearchUnReg ( BiSearchArray * pBSA);
/*********************************************************************/
/*BSearch : BiSearch from nStart to nEnd with the llKey */
/* Search Result save in the val "nPosResult" */
/*Return : [0]:BSearch fail [1] :BSearch Success */
/*********************************************************************/
int BSearch ( BiSearchArray * pBSA, int nStart, int nEnd, LL llKey, int *nPosResult );
/*********************************************************************/
/*BSearchArray : BiSearch from 0 to ArrayEndIndex with the llKey */
/* Search nPos Result save in the val "nPosResult" */
/*Return : [0]:BSearchArray fail [1] :BSearchArray Success */
/*********************************************************************/
int BSearchArray ( BiSearchArray * pBSA, LL llKey, int *nPosResult );
/*********************************************************************/
/*BISInsert : Insert a BiSearch Array Element with the llKey */
/* return Data Unit Array Index Get by GetIdleNodeFunc*/
/*Return : [0]:BISInsert fail [1]:BISInsert Success */
/*********************************************************************/
int BISInsert ( BiSearchArray * pBSA, LL llKey, int nDUPosIndex );
/*********************************************************************/
/*BISDelete : Delete a BiSearch Array Element with the llKey */
/*Return : [0]:BISDelete fail [1]:BISDelete Success */
/*********************************************************************/
int BISDelete ( BiSearchArray * pBSA, LL llKey );
/*********************************************************************/
/*BISSearch : BiSearch from 0 to ArrayEndIndex with the llKey */
/* Search DUIndex Result save in the val "nDUPosIndex"*/
/*Return : [0]:BISSearch fail [1]:BISSearch Success */
/*********************************************************************/
int BISSearch ( BiSearchArray * pBSA, LL llKey , int* nDUPosIndex);
/*********************************************************************/
/*GetBISearchCount : Get The BiSearch struct counter */
/*Return : return The BiSearch struct counter */
/*********************************************************************/
int GetBISearchCount ( BiSearchArray * pBSA);
/*********************************************************************/
/*GetDUIndex : Get The Data Unit Index by bisearch struct index */
/*Return : return the BiSearch struct dataunit index */
/*********************************************************************/
int GetDUIndex ( BiSearchArray * pBSA, int nBIIndex);
//BiSearch ManageMent Operation
typedef enum _BIS_OP
{
BIS_INIT = 0,
BIS_SEARCH,
BIS_INSERT,
BIS_DELETE,
}BIS_OP;
/*********************************************************************/
/*BISSearchMng : BiSearch Management Opertion fuction */
/* Init : use BIS_OP [BIS_INIT] Insert the elment */
/* with the key_str and nDUIndex */
/* Search : use BIS_OP [BIS_SEARCH] search the elemnt */
/* with the key_str ,return nDUIndex */
/* Insert : se BIS_OP [BIS_Insert] Insert a BiSearch */
/* Array Element with the llKey ,return Data */
/* Unit Array Index Get by GetIdleNodeFunc() */
/* by GetIdleNodeFunc() */
/* Delete : use BIS_OP [BIS_DELETE] Delete the elment */
/* with the key_str */
/*Return : [0] fail [1] success */
/*********************************************************************/
int BISSearchMng( BiSearchArray * pBSA, BIS_OP mng_type,LL llkey, int* nDUIndex );
#endif