Project

General

Profile

Statistics
| Revision:

root / proj / libs / classes / src / queue.c @ 280

History | View | Annotate | Download (905 Bytes)

1 277 up20180642
#include <lcom/lcf.h>
2
3
#include "queue.h"
4
5
#include "list.h"
6
#include "errors.h"
7
8
const size_t queue_max_size = UINT_MAX;
9
10
struct queue{
11
    list_t *l;
12
};
13
14
queue_t* (queue_ctor )(void){
15
    queue_t *ret = malloc(sizeof(queue_t));
16
    if(ret == NULL) return NULL;
17
    ret->l = list_ctor();
18
    if(ret->l == NULL){
19
        queue_dtor(ret);
20
        return NULL;
21
    }
22
    return ret;
23
}
24
int      (queue_dtor )(queue_t *q){
25
    int r;
26
    if((r = list_dtor(q->l))) return r;
27
    free(q);
28
    return SUCCESS;
29
}
30
size_t   (queue_size )(const queue_t *q           ){ return list_size (q->l); }
31
int      (queue_empty)(const queue_t *q           ){ return list_empty(q->l); }
32
void     (queue_push )(      queue_t *q, void *val){ list_push_back(q->l, val); }
33
void*    (queue_top  )(const queue_t *q           ){ return *list_front(q->l); }
34
void     (queue_pop  )(      queue_t *q           ){ list_pop_front(q->l); }