psorting.c File Reference

#include "../headers/psorting.h"

Go to the source code of this file.

Functions

static void pock_qsort_rec (c_lst_pockets *pockets, node_pocket **pocks, int start, int end, int(*fcmp)(const node_pocket *, const node_pocket *))
static int pock_partition (c_lst_pockets *pockets, node_pocket **pocks, int start, int end, int(*fcmp)(const node_pocket *, const node_pocket *))
void sort_pockets (c_lst_pockets *pockets, int(*fcmp)(const node_pocket *, const node_pocket *))
int compare_pockets_nasph (const node_pocket *p1, const node_pocket *p2)
int compare_pockets_volume (const node_pocket *p1, const node_pocket *p2)
int compare_pockets_score (const node_pocket *p1, const node_pocket *p2)
int compare_pockets_corresp (const node_pocket *p1, const node_pocket *p2)
int compare_pockets_vol_corresp (const node_pocket *p1, const node_pocket *p2)


Function Documentation

int compare_pockets_corresp ( const node_pocket p1,
const node_pocket p2 
)

## FUNCTION: compare_pockets_corresp

## SPECIFICATION: Function comparing two pocket on there correspondance with the ligan (for the test programm). Uses this for quicksort, orwhatever you want...

## PARAMETRES: @ const node_pocket *p1: Pocket 1 @ const node_pocket *p2: Pocket 2

## RETURN: 1 if the correspondance of p2 is greater than the correspondance of p1, -1 else.

Definition at line 273 of file psorting.c.

References s_pocket::ovlp, and node_pocket::pocket.

00274 {
00275         if(p1->pocket->ovlp < p2->pocket->ovlp) return 1 ;
00276         else return -1 ;
00277 }

int compare_pockets_nasph ( const node_pocket p1,
const node_pocket p2 
)

## FUNCTION: compare_pockets_nasph

## SPECIFICATION: Function comparing two pocket on there number of alpha spheres. Uses this for quicksort, or whatever you want...

## PARAMETRES: @ const node_pocket *p1: Pocket 1 @ const node_pocket *p2: Pocket 2

## RETURN:.

Definition at line 206 of file psorting.c.

References s_desc::nb_asph, s_pocket::pdesc, and node_pocket::pocket.

00207 {
00208         if(p1->pocket->pdesc->nb_asph < p2->pocket->pdesc->nb_asph) return 1 ;
00209         else return -1 ;
00210 }

int compare_pockets_score ( const node_pocket p1,
const node_pocket p2 
)

## FUNCTION: compare_pockets_score

## SPECIFICATION: Function comparing two pocket on there score. Uses this for quicksort, or whatever you want...

## PARAMETRES: @ const node_pocket *p1: Pocket 1 @ const node_pocket *p2: Pocket 2

## RETURN: 1 if the score of p2 is greater than the score of p1, -1 else.

Definition at line 251 of file psorting.c.

References node_pocket::pocket, and s_pocket::score.

00252 {
00253         if(p1->pocket->score < p2->pocket->score) return 1 ;
00254         else return -1 ;
00255 }

int compare_pockets_vol_corresp ( const node_pocket p1,
const node_pocket p2 
)

## FUNCTION: compare_pockets_vol_corresp

## SPECIFICATION: Function comparing two pocket on there volume correspondance with the ligan (for the test programm). Uses this for quicksort, orwhatever you want...

## PARAMETRES: @ const node_pocket *p1: Pocket 1 @ const node_pocket *p2: Pocket 2

## RETURN: 1 if the volume correspondance of p2 is greater than the volume correspondance of p1, -1 else.

Definition at line 296 of file psorting.c.

References node_pocket::pocket, and s_pocket::vol_corresp.

00297 {
00298         if(p1->pocket->vol_corresp < p2->pocket->vol_corresp) return 1 ;
00299         else return -1 ;
00300 }

int compare_pockets_volume ( const node_pocket p1,
const node_pocket p2 
)

## FUNCTION: compare_pockets_volume

## SPECIFICATION: Function comparing two pocket on there volume. Uses this for quicksort, or whatever you want...

## PARAMETRES: @ const node_pocket *p1: Pocket 1 @ const node_pocket *p2: Pocket 2

## RETURN: 1 if the volume of p2 is greater than the volume of p1, -1 else.

Definition at line 229 of file psorting.c.

References s_pocket::pdesc, node_pocket::pocket, and s_desc::volume.

00230 {
00231         if(p1->pocket->pdesc->volume < p2->pocket->pdesc->volume) return 1 ;
00232         else return -1 ;
00233 }

static int pock_partition ( c_lst_pockets pockets,
node_pocket **  pocks,
int  start,
int  end,
int(*)(const node_pocket *, const node_pocket *)  fcmp 
) [static]

## FUNCTION: static pock_partition

## SPECIFICATION: Partition fuction used for the quicksort. The comparison between two pockets is done with the function given in last argument. The pivot is chosen as the first element of the tab. A possible amelioration is to chose it randomly, to avoid low performance on already sorted tab...

The function is sorting a tab of pointer to the pockets, and will update the corresponding chained list.

## PARAMETRES: @ c_lst_pockets *pockets : The list of pockets that will be updated @ node_pocket **pocks : Tab that will be sorted @ int start : start index of the sort @ int end : end index of the sort @ int (*fcmp)(const node_pocket*, const node_pocket*): Comparison function

## RETURN:

Definition at line 158 of file psorting.c.

References swap_pockets().

Referenced by pock_qsort_rec().

00160 {
00161         node_pocket *cpock = NULL,
00162                                 *tmp = NULL,
00163                                 *piv = NULL ;
00164         
00165         int c = start,
00166                 i = 0 ;
00167                 
00168         piv = pocks[start] ;     // TODO: chose randomly the pivot.
00169         for(i = start+1 ; i <= end ; i++) {
00170                 cpock = pocks[i] ;
00171                 if( fcmp(cpock, piv) == -1) {
00172                         c++ ;
00173                         if(c != i) {
00174                                 swap_pockets(pockets, pocks[c], pocks[i]) ;
00175                                 tmp = pocks[c] ;
00176                                 pocks[c] = pocks[i] ; pocks[i] = tmp ;
00177                         }
00178                 }
00179         }
00180         
00181         if(c != start) {
00182                 swap_pockets(pockets, pocks[c], piv) ;
00183                 tmp = pocks[c] ;
00184                 pocks[c] = pocks[start] ; pocks[start] = tmp ;
00185         
00186         }
00187 
00188         return(c) ;
00189 }

static void pock_qsort_rec ( c_lst_pockets pockets,
node_pocket **  pocks,
int  start,
int  end,
int(*)(const node_pocket *, const node_pocket *)  fcmp 
) [static]

## FUNCTION: static pock_qsort_rec

## SPECIFICATION: This function will perform a recursive quick sort on the given tab, updating the corresponding chained list.

## PARAMETRES: @ c_lst_pockets *pockets : The list of pockets that will be updated @ node_pocket **pocks : Tab that will be sorted @ int start : start index of the sort @ int end : end index of the sort @ int (*fcmp)(const node_pocket*, const node_pocket*): Comparison function

## RETURN:

Definition at line 122 of file psorting.c.

References pock_partition().

Referenced by sort_pockets().

00125 {
00126         if(start < end) {
00127                 int piv = 0 ;
00128                 piv = pock_partition(pockets, pocks, start, end, fcmp) ;
00129                 
00130                 pock_qsort_rec(pockets, pocks, start, piv-1, fcmp) ;
00131                 pock_qsort_rec(pockets, pocks, piv+1, end, fcmp) ;
00132         }
00133 }

void sort_pockets ( c_lst_pockets pockets,
int(*)(const node_pocket *, const node_pocket *)  fcmp 
)

## FUNCTION: sort_pockets

## SPECIFICATION: Top function used to sort pockets. First we copy the chained list of pockets in a tab to make use of indices (for the quick sort algorithm), and then we will sort this tab, and update in the same time the chained list.

Finally, the given chained list will be modified and sorted using the function given in argument.

## PARAMETRES: @ c_lst_pockets *pockets: The list of pockets that will be updated @ int (*fcmp)(const node_pocket*, const node_pocket*): Comparison function

## RETURN:

Definition at line 87 of file psorting.c.

References c_lst_pockets::first, my_calloc(), my_free(), c_lst_pockets::n_pockets, node_pocket::next, and pock_qsort_rec().

Referenced by search_pocket().

00089 {
00090         size_t npock = 0 ;
00091         node_pocket **pocks = (node_pocket **)my_calloc(pockets->n_pockets, sizeof(node_pocket*)) ;
00092         node_pocket *cur = pockets->first ;
00093 
00094         while(cur && npock < pockets->n_pockets) {
00095                 pocks[npock] = cur ;
00096                 cur = cur->next ;
00097                 npock++ ;
00098         }
00099         pock_qsort_rec(pockets, pocks, 0,  npock-1, fcmp) ;
00100 
00101         my_free(pocks) ;
00102 }


Generated on Mon Jun 7 16:44:23 2010 for fpocket by  doxygen 1.5.6