| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/coreutils/src/gnulib/lib/i-ring.c |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||
|---|---|---|---|---|---|---|---|---|
| 1 | /* a simple ring buffer | - | ||||||
| 2 | Copyright (C) 2006, 2009-2018 Free Software Foundation, Inc. | - | ||||||
| 3 | - | |||||||
| 4 | This program is free software: you can redistribute it and/or modify | - | ||||||
| 5 | it under the terms of the GNU General Public License as published by | - | ||||||
| 6 | the Free Software Foundation; either version 3 of the License, or | - | ||||||
| 7 | (at your option) any later version. | - | ||||||
| 8 | - | |||||||
| 9 | This program is distributed in the hope that it will be useful, | - | ||||||
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | - | ||||||
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | - | ||||||
| 12 | GNU General Public License for more details. | - | ||||||
| 13 | - | |||||||
| 14 | You should have received a copy of the GNU General Public License | - | ||||||
| 15 | along with this program. If not, see <https://www.gnu.org/licenses/>. */ | - | ||||||
| 16 | - | |||||||
| 17 | /* written by Jim Meyering */ | - | ||||||
| 18 | - | |||||||
| 19 | #include <config.h> | - | ||||||
| 20 | #include "i-ring.h" | - | ||||||
| 21 | - | |||||||
| 22 | #include <stdlib.h> | - | ||||||
| 23 | - | |||||||
| 24 | void | - | ||||||
| 25 | i_ring_init (I_ring *ir, int default_val) | - | ||||||
| 26 | { | - | ||||||
| 27 | int i; | - | ||||||
| 28 | ir->ir_empty = true; | - | ||||||
| 29 | ir->ir_front = 0; | - | ||||||
| 30 | ir->ir_back = 0; | - | ||||||
| 31 | for (i = 0; i < I_RING_SIZE; i++)
| 6820-27280 | ||||||
| 32 | ir->ir_data[i] = default_val; executed 27280 times by 6 tests: ir->ir_data[i] = default_val;Executed by:
| 27280 | ||||||
| 33 | ir->ir_default_val = default_val; | - | ||||||
| 34 | } executed 6820 times by 6 tests: end of blockExecuted by:
| 6820 | ||||||
| 35 | - | |||||||
| 36 | bool | - | ||||||
| 37 | i_ring_empty (I_ring const *ir) | - | ||||||
| 38 | { | - | ||||||
| 39 | return ir->ir_empty; executed 152919 times by 6 tests: return ir->ir_empty;Executed by:
| 152919 | ||||||
| 40 | } | - | ||||||
| 41 | - | |||||||
| 42 | int | - | ||||||
| 43 | i_ring_push (I_ring *ir, int val) | - | ||||||
| 44 | { | - | ||||||
| 45 | unsigned int dest_idx = (ir->ir_front + !ir->ir_empty) % I_RING_SIZE; | - | ||||||
| 46 | int old_val = ir->ir_data[dest_idx]; | - | ||||||
| 47 | ir->ir_data[dest_idx] = val; | - | ||||||
| 48 | ir->ir_front = dest_idx; | - | ||||||
| 49 | if (dest_idx == ir->ir_back)
| 27174-46604 | ||||||
| 50 | ir->ir_back = (ir->ir_back + !ir->ir_empty) % I_RING_SIZE; executed 27174 times by 6 tests: ir->ir_back = (ir->ir_back + !ir->ir_empty) % I_RING_SIZE;Executed by:
| 27174 | ||||||
| 51 | ir->ir_empty = false; | - | ||||||
| 52 | return old_val; executed 73778 times by 6 tests: return old_val;Executed by:
| 73778 | ||||||
| 53 | } | - | ||||||
| 54 | - | |||||||
| 55 | int | - | ||||||
| 56 | i_ring_pop (I_ring *ir) | - | ||||||
| 57 | { | - | ||||||
| 58 | int top_val; | - | ||||||
| 59 | if (i_ring_empty (ir))
| 0-59567 | ||||||
| 60 | abort (); never executed: abort (); | 0 | ||||||
| 61 | top_val = ir->ir_data[ir->ir_front]; | - | ||||||
| 62 | ir->ir_data[ir->ir_front] = ir->ir_default_val; | - | ||||||
| 63 | if (ir->ir_front == ir->ir_back)
| 12963-46604 | ||||||
| 64 | ir->ir_empty = true; executed 12963 times by 6 tests: ir->ir_empty = 1 ;Executed by:
| 12963 | ||||||
| 65 | else | - | ||||||
| 66 | ir->ir_front = ((ir->ir_front + I_RING_SIZE - 1) % I_RING_SIZE); executed 46604 times by 6 tests: ir->ir_front = ((ir->ir_front + I_RING_SIZE - 1) % I_RING_SIZE);Executed by:
| 46604 | ||||||
| 67 | return top_val; executed 59567 times by 6 tests: return top_val;Executed by:
| 59567 | ||||||
| 68 | } | - | ||||||
| Source code | Switch to Preprocessed file |