/[ipchat]/ipchat/src/pqueue.c
ViewVC logotype

Diff of /ipchat/src/pqueue.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.7 by matiasaguirre, Sun Feb 13 02:28:15 2005 UTC revision 1.8 by beatk, Sat Mar 12 20:14:45 2005 UTC
# Line 88  int pq_new(pqueue *q,int sz,int(*eq_f)(v Line 88  int pq_new(pqueue *q,int sz,int(*eq_f)(v
88    
89  /* returns a heap pointer with sz size */  /* returns a heap pointer with sz size */
90  pq_node ** new_heap(int sz){  pq_node ** new_heap(int sz){
     //pq_node **h=(pq_node**)malloc(sizeof(pq_node*));  
91      pq_node **h=(pq_node**)calloc(sz+1,sizeof(pq_node*));      pq_node **h=(pq_node**)calloc(sz+1,sizeof(pq_node*));
92      int i=0;      int i=0;
93      for(; i<sz+1; i++)      for(; i<sz+1; i++)
# Line 98  pq_node ** new_heap(int sz){ Line 97  pq_node ** new_heap(int sz){
97    
98  /*  /*
99   * adds the data d in the queue with priority p   * adds the data d in the queue with priority p
100   * negatives priorities are ok   * negative priorities are ok
101   */   */
102  prio_t pq_add(prio_t p,void * d,pqueue *q){  prio_t pq_add(prio_t p,void * d,pqueue *q){
103      if(!q)      if(!q)
# Line 142  int pq_requeue(pqueue *q){ Line 141  int pq_requeue(pqueue *q){
141      return POK;      return POK;
142  }  }
143    
144  /* return the minor prority element */  /* return the minor priority element */
145  void * pq_min(pqueue *q){  void * pq_min(pqueue *q){
146      if(q->csize==0)      if(q->csize==0)
147          return NULL;          return NULL;
148      return q->heap[1]->data;      return q->heap[1]->data;
149  }  }
150    
151  /* delete the minor prority element */  /* delete the minor priority element */
152  void * pq_del_min(pqueue *q){  void * pq_del_min(pqueue *q){
153      if(q->csize==0)      if(q->csize==0)
154          return NULL;          return NULL;
# Line 165  void * pq_del_min(pqueue *q){ Line 164  void * pq_del_min(pqueue *q){
164      return data;      return data;
165  }  }
166    
167  /* sink the node to it's correct position */  /* sink the node to its correct position */
168  void sink(int pos, pqueue *q){  void sink(int pos, pqueue *q){
169      if(!q || pos<=0 || pos > q->csize)      if(!q || pos<=0 || pos > q->csize)
170          return;          return;
# Line 288  int pq_delete(pqueue *q){ Line 287  int pq_delete(pqueue *q){
287    
288  /*  /*
289   * change the priority to p, of the first node which   * change the priority to p, of the first node which
290   * data is equals to data   * data is equal to data
291   */   */
292  int pq_chpri(void *data, prio_t p, pqueue *q){  int pq_chpri(void *data, prio_t p, pqueue *q){
293      if(!data || !q)      if(!data || !q)

Legend:
Removed from v.1.7  
changed lines
  Added in v.1.8

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26