📄 routelink_analyse.c
字号:
/* S_LNKTBL_REC** : Array for Link info record[OUT] */
/* */
/* -----------------------------------------------------------------------*/
/* Output: */
/* RETURN : 乮Normal乯RET_SUCCESS */
/* 乮Error乯 RET_FAILED */
/* */
/* -----------------------------------------------------------------------*/
/* Outline: */
/* Single link table convert to array for data analysing. */
/* */
/* -----------------------------------------------------------------------*/
/* Others: */
/* */
/***************************************************************************/
int routelink_analyse_slink2array(
S_LNKTBL* pstHeaderLnk, /* I/ Header node pointer */
int iRoadLnkNum, /* I/ Number of Road Link Node */
S_LNKTBL_REC** pstLnkRecArray /* O/ Array for Link info record */
)
{
int iRecSize = 0; /* Size of S_LNKTBL_REC */
int iMallocSize = 0; /* Size of data area */
S_LNKTBL* pstCurLnk = NULL; /* The next delete node */
S_LNKTBL_REC* pstLnkTblRec= NULL; /* Link Data record area */
/* Exception prevention */
if( (NULL == pstHeaderLnk) || (0 == iRoadLnkNum) )
{
return RET_SUCCESS;
}
/* Array area allocation */
iRecSize = sizeof(S_LNKTBL_REC);
iMallocSize = iRecSize * iRoadLnkNum;
pstLnkTblRec = (S_LNKTBL_REC*)malloc( iMallocSize );
*pstLnkRecArray = pstLnkTblRec;
if( NULL == pstLnkTblRec )
{
return RET_FAILED;
}
else
{
memset( pstLnkTblRec, 0, iMallocSize );
}
/* Copy record data into array area */
pstCurLnk = pstHeaderLnk->pNxtNode;
while( NULL != pstCurLnk )
{
memcpy( pstLnkTblRec, &pstCurLnk->stLnkTblRec, iRecSize );
pstLnkTblRec++;
pstCurLnk = pstCurLnk->pNxtNode;
}
return RET_SUCCESS;
}
/***************************************************************************/
/* routelink_analyse_freearray */
/* -----------------------------------------------------------------------*/
/* Input: */
/* S_LNKTBL_REC** : Array for Link info record[OUT] */
/* */
/* -----------------------------------------------------------------------*/
/* Output: */
/* RETURN : RET_SUCCESS */
/* */
/* -----------------------------------------------------------------------*/
/* Outline: */
/* Free link data info record area. */
/* */
/* -----------------------------------------------------------------------*/
/* Others: */
/* */
/***************************************************************************/
int routelink_analyse_freearray(
S_LNKTBL_REC** pstLnkRecArray /* O/ Array for Link info record */
)
{
/* Exception prevention */
if( (NULL == pstLnkRecArray) || (NULL == *pstLnkRecArray) )
{
return RET_SUCCESS;
}
/* Array area free */
free( *pstLnkRecArray );
*pstLnkRecArray = NULL;
return RET_SUCCESS;
}
/***************************************************************************/
/* routelink_analyse_in_bubbleanalyse */
/* -----------------------------------------------------------------------*/
/* Input: */
/* S_LNKTBL_REC* : Link data info record area[IN] */
/* int : Number of Road Link Node[IN] */
/* */
/* -----------------------------------------------------------------------*/
/* Output: */
/* RETURN : 乮Normal乯RET_SUCCESS */
/* 乮Error乯 RET_FAILED */
/* */
/* -----------------------------------------------------------------------*/
/* Outline: */
/* Kiwi analyse. */
/* */
/* -----------------------------------------------------------------------*/
/* Others: */
/* */
/***************************************************************************/
int routelink_analyse_in_bubbleanalyse(
S_LNKTBL_REC* pstLnkRecArray, /* I/ Link data info record area */
int iRoadLnkNum /* I/ Number of Road Link Node */
)
{
int iLoopCnt = 0; /* Loop counter */
int iLoopNxt = 0; /* Loop counter */
int iFlag = 0; /* Data exchange flag */
int iDataSize = 0; /* Record area size */
S_LNKTBL_REC stExchgLnk; /* Node for Exchange */
/* Exception prevention */
if( NULL == pstLnkRecArray )
{
return RET_FAILED;
}
/* Record data size get */
iDataSize = sizeof(S_LNKTBL_REC);
memset( &stExchgLnk, 0, iDataSize );
/* Analyseing status promption */
printf( "\nIt is now analysing. Please wait..." );
/* Analyse proc */
for( iLoopCnt = 0; iLoopCnt < (iRoadLnkNum - 1); iLoopCnt++ )
{
iFlag = 0;
for( iLoopNxt = 0; iLoopNxt < (iRoadLnkNum - iLoopCnt - 1);
iLoopNxt++ )
{
if( pstLnkRecArray[iLoopNxt].udwLinkID >
pstLnkRecArray[iLoopNxt + 1].udwLinkID )
{
iFlag = 1;
/* Temporary buffer set */
memcpy( &stExchgLnk, &pstLnkRecArray[iLoopNxt], iDataSize );
/* a > b--->a and b exchange */
memcpy( &pstLnkRecArray[iLoopNxt],
&pstLnkRecArray[iLoopNxt + 1], iDataSize );
/* a > b--->a and b exchange */
memcpy(
&pstLnkRecArray[iLoopNxt + 1], &stExchgLnk, iDataSize );
/* Exchange buffer clear */
memset( &stExchgLnk, 0, iDataSize );
}
}
if( 0 == iFlag )
{
break;
}
/* Current status promption */
if( 0 == (iLoopCnt % 100) )
{
printf(".");
}
}
/* analyse ok promption */
printf( "Analyse OK!\n" );
return RET_SUCCESS;
}
/***************************************************************************/
/* routelink_analyse_in_2dirbubbleanalyse */
/* -----------------------------------------------------------------------*/
/* Input: */
/* S_LNKTBL_REC* : Link data info record area[IN] */
/* int : Number of Road Link Node[IN] */
/* */
/* -----------------------------------------------------------------------*/
/* Output: */
/* RETURN : 乮Normal乯RET_SUCCESS */
/* 乮Error乯 RET_FAILED */
/* */
/* -----------------------------------------------------------------------*/
/* Outline: */
/* 2 Double direction Kiwi analyse process. */
/* */
/* -----------------------------------------------------------------------*/
/* Others: */
/* */
/***************************************************************************/
int routelink_analyse_in_2dirbubbleanalyse(
S_LNKTBL_REC* pstLnkRecArray, /* I/ Link data info record area */
int iRoadLnkNum /* I/ Number of Road Link Node */
)
{
int iLoopCnt = 0; /* Loop counter */
int iLeft = 0; /* Left->Right counter */
int iRight = 0; /* Right->Left counter */
int iLastPos = 0; /* Lastest exchange position */
int iCounter = 0; /* Loop counter */
int iDataSize = 0; /* Record area size */
S_LNKTBL_REC stExchgLnk; /* Node for Exchange */
/* Exception prevention */
if( NULL == pstLnkRecArray )
{
return RET_FAILED;
}
/* Initialization */
iLeft = 1;
iRight = iRoadLnkNum - 1;
/* Record data size get */
iDataSize = sizeof(S_LNKTBL_REC);
memset( &stExchgLnk, 0, iDataSize );
/* analysing status promption */
printf( "\nIt is now analysing. Please wait..." );
/* Analyse proc */
do
{
/* Current minial ID search */
for( iLoopCnt = iRight; iLoopCnt >= iLeft; iLoopCnt-- )
{
if( pstLnkRecArray[iLoopCnt].udwLinkID <
pstLnkRecArray[iLoopCnt - 1].udwLinkID )
{
/* Temporary buffer set */
memcpy( &stExchgLnk, &pstLnkRecArray[iLoopCnt], iDataSize );
/* a > b--->a and b exchange */
memcpy( &pstLnkRecArray[iLoopCnt],
&pstLnkRecArray[iLoopCnt - 1], iDataSize );
/* a > b--->a and b exchange */
memcpy(
&pstLnkRecArray[iLoopCnt - 1], &stExchgLnk, iDataSize );
/* Exchange buffer clear */
memset( &stExchgLnk, 0, iDataSize );
/* Current position mark */
iLastPos = iLoopCnt;
}
}
/* Left position record */
iLeft = iLastPos + 1;
/* Current maxium ID search */
for( iLoopCnt = iLeft; iLoopCnt < iRight + 1; iLoopCnt++ )
{
if( pstLnkRecArray[iLoopCnt].udwLinkID <
pstLnkRecArray[iLoopCnt - 1].udwLinkID )
{
/* Temporary buffer set */
memcpy( &stExchgLnk, &pstLnkRecArray[iLoopCnt], iDataSize );
/* a > b--->a and b exchange */
memcpy( &pstLnkRecArray[iLoopCnt],
&pstLnkRecArray[iLoopCnt - 1], iDataSize );
/* a > b--->a and b exchange */
memcpy(
&pstLnkRecArray[iLoopCnt - 1], &stExchgLnk, iDataSize );
/* Exchange buffer clear */
memset( &stExchgLnk, 0, iDataSize );
/* Current position mark */
iLastPos = iLoopCnt;
}
}
/* Right position record */
iRight = iLastPos - 1;
/* Loop counter */
iCounter++;
/* Current status promption */
if( 0 == (iCounter % 100) )
{
printf(".");
}
}while( iLeft <= iRight );
/* Analyse ok promption */
printf( "Analyse OK!\n" );
return RET_SUCCESS;
}
/***************************************************************************/
/* routelink_analyse_in_selectanalyse */
/* -----------------------------------------------------------------------*/
/* Input: */
/* S_LNKTBL_REC* : Link data info record area[IN] */
/* int : Number of Road Link Node[IN] */
/* */
/* -----------------------------------------------------------------------*/
/* Output: */
/* RETURN : 乮Normal乯RET_SUCCESS */
/* 乮Error乯 RET_FAILED */
/* */
/* -----------------------------------------------------------------------*/
/* Outline: */
/* Selected Kiwi analyse. */
/* */
/* -----------------------------------------------------------------------*/
/* Others: */
/* */
/***************************************************************************/
int routelink_analyse_in_selectanalyse(
S_LNKTBL_REC* pstLnkRecArray, /* I/ Link data info record area */
int iRoadLnkNum /* I/ Number of Road Link Node */
)
{
int iLoopCnt = 0; /* Loop counter */
int iLoopNxt = 0; /* Loop counter */
int iMinKey = 0; /* The subscript of min key */
int iDataSize = 0; /* Record area size */
S_LNKTBL_REC stExchgLnk; /* Node for Exchange */
/* Exception prevention */
if( NULL == pstLnkRecArray )
{
return RET_FAILED;
}
/* Record data size get */
iDataSize = sizeof(S_LNKTBL_REC);
memset( &stExchgLnk, 0, iDataSize );
/* Analysing status promption */
printf( "\nIt is now analysing. Please wait..." );
for( iLoopCnt = 0; iLoopCnt < iRoadLnkNum; iLoopCnt++ )
{
/* Initial min key get */
iMinKey = iLoopCnt;
/* Selection */
for( iLoopNxt = iLoopCnt + 1; iLoopNxt < iRoadLnkNum; iLoopNxt++ )
{
if( pstLnkRecArray[iLoopNxt].udwLinkID <
pstLnkRecArray[iMinKey].udwLinkID )
{
iMinKey = iLoopNxt;
}
}
/* Data exchange */
if( iMinKey != iLoopCnt )
{
/* Temporary buffer set */
memcpy( &stExchgLnk, &pstLnkRecArray[iMinKey], iDataSize );
/* a > b--->a and b exchange */
memcpy( &pstLnkRecArray[iMinKey],
&pstLnkRecArray[iLoopCnt], iDataSize );
/* a > b--->a and b exchange */
memcpy(
&pstLnkRecArray[iLoopCnt], &stExchgLnk, iDataSize );
/* Exchange buffer clear */
memset( &stExchgLnk, 0, iDataSize );
}
/* Current status promption */
if( 0 == (iLoopCnt % 100) )
{
printf(".");
}
}
/* Analyse ok promption */
printf( "Analyse OK!\n" );
return RET_SUCCESS;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -