LCOV - code coverage report
Current view: top level - glib/girepository/cmph - vqueue.c (source / functions) Hit Total Coverage
Test: unnamed Lines: 0 26 0.0 %
Date: 2024-05-07 05:15:23 Functions: 0 6 0.0 %
Branches: 0 8 0.0 %

           Branch data     Line data    Source code
       1                 :            : #include "vqueue.h"
       2                 :            : #include <stdio.h>
       3                 :            : #include <assert.h>
       4                 :            : #include <stdlib.h>
       5                 :            : struct __vqueue_t
       6                 :            : {
       7                 :            :   cmph_uint32 * values;
       8                 :            :   cmph_uint32 beg, end, capacity;
       9                 :            : };
      10                 :            : 
      11                 :          0 : vqueue_t * vqueue_new(cmph_uint32 capacity)
      12                 :            : {
      13                 :          0 :   size_t capacity_plus_one = capacity + 1;
      14                 :          0 :   vqueue_t *q = (vqueue_t *)malloc(sizeof(vqueue_t));
      15         [ #  # ]:          0 :   assert(q);
      16                 :          0 :   q->values = (cmph_uint32 *)calloc(capacity_plus_one, sizeof(cmph_uint32));
      17                 :          0 :   q->beg = q->end = 0;
      18                 :          0 :   q->capacity = (cmph_uint32) capacity_plus_one;
      19                 :          0 :   return q;
      20                 :            : }
      21                 :            : 
      22                 :          0 : cmph_uint8 vqueue_is_empty(vqueue_t * q)
      23                 :            : {
      24                 :          0 :   return (cmph_uint8)(q->beg == q->end);
      25                 :            : }
      26                 :            : 
      27                 :          0 : void vqueue_insert(vqueue_t * q, cmph_uint32 val)
      28                 :            : {
      29         [ #  # ]:          0 :   assert((q->end + 1)%q->capacity != q->beg); // Is queue full?
      30                 :          0 :   q->end = (q->end + 1)%q->capacity;
      31                 :          0 :   q->values[q->end] = val;
      32                 :          0 : }
      33                 :            : 
      34                 :          0 : cmph_uint32 vqueue_remove(vqueue_t * q)
      35                 :            : {
      36         [ #  # ]:          0 :   assert(!vqueue_is_empty(q)); // Is queue empty?
      37                 :          0 :   q->beg = (q->beg + 1)%q->capacity;
      38                 :          0 :   return q->values[q->beg];
      39                 :            : }
      40                 :            : 
      41                 :          0 : void vqueue_print(vqueue_t * q)
      42                 :            : {
      43                 :            :   cmph_uint32 i;
      44         [ #  # ]:          0 :   for (i = q->beg; i != q->end; i = (i + 1)%q->capacity)
      45                 :          0 :     fprintf(stderr, "%u\n", q->values[(i + 1)%q->capacity]);
      46                 :          0 : } 
      47                 :            : 
      48                 :          0 : void vqueue_destroy(vqueue_t *q)
      49                 :            : {
      50                 :          0 :   free(q->values); q->values = NULL; free(q);
      51                 :          0 : }

Generated by: LCOV version 1.14