/[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.11 by beatk, Fri Mar 25 13:51:56 2005 UTC revision 1.12 by beatk, Fri Mar 25 17:12:51 2005 UTC
# Line 243  void * pq_del_func(void *data2, pqueue * Line 243  void * pq_del_func(void *data2, pqueue *
243      return NULL;      return NULL;
244  }  }
245    
   
246  /*  /*
247   * execs pq->equals_f over each element in the queue   * execs pq->equals_f over each element in the queue
248   * if it returns a true value, then the data will be returned   * if it returns a true value, then the data will be returned
# Line 260  void * pq_get_func(void *data2, pqueue * Line 259  void * pq_get_func(void *data2, pqueue *
259      return NULL;      return NULL;
260  }  }
261    
262    /*
263     * removes element pointed by 'node'
264     * returns 'node' if found, NULL if not
265     */
266    void * pq_del_ptr(void *node, pqueue *pq)
267    {
268        if(!pq || !node)
269            return NULL;
270    
271        int i=1;
272        for(;i<(pq->csize+1);i++){
273            if((void *)pq->heap[i] == node){
274                pq->heap[i]=pq->heap[pq->csize];
275                pq->csize--;
276                positionate(i,pq);
277                return node;
278            }
279        }
280        return NULL;
281    }
282    
283  /*  /*
284   * call pq_empty and free the heap   * call pq_empty and free the heap
285   */   */
# Line 276  int pq_delete(pqueue *q){ Line 296  int pq_delete(pqueue *q){
296   * change the priority to p, of the first node which   * change the priority to p, of the first node which
297   * data is equal to data   * data is equal to data
298   */   */
299  int pq_chpri(void *data, prio_t p, pqueue *q){  int pq_chpri_func(void *data, prio_t p, pqueue *q){
300      if(!data || !q)      if(!data || !q)
301          return PQERR;          return PQERR;
302    
303      int i=1;      int i=1;
304      for(;i<(q->csize+1);i++){      for(;i<(q->csize+1);i++){
305          if(q->heap[i] && q->equals_f((void *)q->heap[i],data))          if(q->equals_f((void *)q->heap[i],data))
306                break;
307        }
308    
309        if(i>q->csize)
310            return NFOUNDERR;
311    
312        q->heap[i]->pri=p;
313    
314        positionate(i,q);
315        return p;
316    }
317    
318    /*
319     * change the priority to p, of element pointed by 'node'
320     */
321    int pq_chpri_ptr(void *node, prio_t p, pqueue *q){
322        if(!node || !q)
323            return PQERR;
324    
325        int i=1;
326        for(;i<(q->csize+1);i++){
327            if((void *)q->heap[i] == node)
328              break;              break;
329      }      }
330    

Legend:
Removed from v.1.11  
changed lines
  Added in v.1.12

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