#include "file.h" void file_ajoute_apres(struct file *f, struct node * ou, struct processus * p) { struct node *ptr; NEW(ptr,struct node); ptr->content = p; ptr->next = ou->next; ptr->prev = ou; if(ou->next) ou->next->prev = ptr; else f->last=ptr; ou->next=ptr; f->no++; } void file_ajoute_avant(struct file *f, struct node * ou, struct processus * p) { struct node *ptr; NEW(ptr,struct node); ptr->content = p; ptr->next = ou; ptr->prev = ou->prev; if(ou->prev) ou->prev->next = ptr; else f->first=ptr; ou->prev=ptr; f->no++; } struct processus * file_pop_which(struct file *f, struct node * which) { struct processus * ret=which->content; if(which->prev) which->prev->next = which->next; else f->first=which->next; if(which->next) which->next->prev = which->prev; else f->last=which->prev; f->no--; free(which); return ret; } struct file * new_file() { struct file * f; NEW(f, struct file); f->first=f->last=NULL; f->no=0; return f; } void file_enqueue (struct file *f, struct processus *p) { struct node * n; if(f->no == 0) { NEW(n,struct node); n->content = p; n->next=n->prev=NULL; f->no=1; f->first=f->last=n; } else file_ajoute_apres(f,f->last,p); } struct processus * file_pop_how( struct file *f, int (*compare)(struct processus * p1, struct processus * p2) ) { struct node *ptr, *least; if(file_is_empty(f)) return NULL; least = f->first; FORALLIN(ptr,f) if(compare(ptr->content,least->content) < 0) least = ptr; return file_pop_which(f,least); } struct processus * file_peek_how( struct file *f, int (*compare)(struct processus * p1, struct processus * p2) ) { struct node *ptr, *least; if(file_is_empty(f)) return NULL; least = f->first; FORALLIN(ptr,f) if(compare(ptr->content,least->content) < 0) least = ptr; return least->content; } int file_is_empty(struct file * f) { return !(f->no); }