mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-09-18 21:53:04 +02:00
.gitlab-ci
.reuse
LICENSES
docs
fuzzing
gio
girepository
cmph
README-CMPH-IMPORT.txt
bdz.c
bdz.h
bdz_gen_lookup_table.c
bdz_ph.c
bdz_ph.h
bdz_structs.h
bdz_structs_ph.h
bitbool.h
bmz.c
bmz.h
bmz8.c
bmz8.h
bmz8_structs.h
bmz_structs.h
brz.c
brz.h
brz_structs.h
buffer_entry.c
buffer_entry.h
buffer_manage.c
buffer_manage.h
buffer_manager.c
buffer_manager.h
chd.c
chd.h
chd_ph.c
chd_ph.h
chd_structs.h
chd_structs_ph.h
chm.c
chm.h
chm_structs.h
cmph.c
cmph.h
cmph_structs.c
cmph_structs.h
cmph_time.h
cmph_types.h
compressed_rank.c
compressed_rank.h
compressed_seq.c
compressed_seq.h
debug.h
djb2_hash.c
djb2_hash.h
fch.c
fch.h
fch_buckets.c
fch_buckets.h
fch_structs.h
fnv_hash.c
fnv_hash.h
graph.c
graph.h
hash.c
hash.h
hash_state.h
hashtree.c
hashtree.h
hashtree_structs.h
jenkins_hash.c
jenkins_hash.h
main.c
meson.build
miller_rabin.c
miller_rabin.h
sdbm_hash.c
sdbm_hash.h
select.c
select.h
select_lookup_tables.h
vqueue.c
vqueue.h
vstack.c
vstack.h
wingetopt.c
wingetopt.h
cmph-bdz-test.c
docs.c
gdump.c
gi-dump-types.c
giarginfo.c
giarginfo.h
gibaseinfo.c
gibaseinfo.h
gicallableinfo.c
gicallableinfo.h
giconstantinfo.c
giconstantinfo.h
gienuminfo.c
gienuminfo.h
gifieldinfo.c
gifieldinfo.h
gifunctioninfo.c
gifunctioninfo.h
giinterfaceinfo.c
giinterfaceinfo.h
ginvoke.c
giobjectinfo.c
giobjectinfo.h
gipropertyinfo.c
gipropertyinfo.h
giregisteredtypeinfo.c
giregisteredtypeinfo.h
girepository-private.h
girepository.c
girepository.h
girffi.c
girffi.h
girmodule-private.h
girmodule.c
girnode-private.h
girnode.c
giroffsets.c
girparser-private.h
girparser.c
girwriter-private.h
girwriter.c
gisignalinfo.c
gisignalinfo.h
gistructinfo.c
gistructinfo.h
gitypeinfo.c
gitypeinfo.h
gitypelib-internal.h
gitypelib.c
gitypelib.h
gitypes.h
giunioninfo.c
giunioninfo.h
givfuncinfo.c
givfuncinfo.h
gthash-test.c
gthash.c
meson.build
glib
gmodule
gobject
gthread
m4macros
po
subprojects
tests
tools
.clang-format
.dir-locals.el
.editorconfig
.gitignore
.gitlab-ci.yml
.gitmodules
.lcovrc
CODE_OF_CONDUCT.md
CONTRIBUTING.md
COPYING
INSTALL.md
NEWS
README.md
SECURITY.md
glib.doap
meson.build
meson_options.txt
52 lines
1.1 KiB
C
52 lines
1.1 KiB
C
![]() |
#include "vqueue.h"
|
||
|
#include <stdio.h>
|
||
|
#include <assert.h>
|
||
|
#include <stdlib.h>
|
||
|
struct __vqueue_t
|
||
|
{
|
||
|
cmph_uint32 * values;
|
||
|
cmph_uint32 beg, end, capacity;
|
||
|
};
|
||
|
|
||
|
vqueue_t * vqueue_new(cmph_uint32 capacity)
|
||
|
{
|
||
|
size_t capacity_plus_one = capacity + 1;
|
||
|
vqueue_t *q = (vqueue_t *)malloc(sizeof(vqueue_t));
|
||
|
assert(q);
|
||
|
q->values = (cmph_uint32 *)calloc(capacity_plus_one, sizeof(cmph_uint32));
|
||
|
q->beg = q->end = 0;
|
||
|
q->capacity = (cmph_uint32) capacity_plus_one;
|
||
|
return q;
|
||
|
}
|
||
|
|
||
|
cmph_uint8 vqueue_is_empty(vqueue_t * q)
|
||
|
{
|
||
|
return (cmph_uint8)(q->beg == q->end);
|
||
|
}
|
||
|
|
||
|
void vqueue_insert(vqueue_t * q, cmph_uint32 val)
|
||
|
{
|
||
|
assert((q->end + 1)%q->capacity != q->beg); // Is queue full?
|
||
|
q->end = (q->end + 1)%q->capacity;
|
||
|
q->values[q->end] = val;
|
||
|
}
|
||
|
|
||
|
cmph_uint32 vqueue_remove(vqueue_t * q)
|
||
|
{
|
||
|
assert(!vqueue_is_empty(q)); // Is queue empty?
|
||
|
q->beg = (q->beg + 1)%q->capacity;
|
||
|
return q->values[q->beg];
|
||
|
}
|
||
|
|
||
|
void vqueue_print(vqueue_t * q)
|
||
|
{
|
||
|
cmph_uint32 i;
|
||
|
for (i = q->beg; i != q->end; i = (i + 1)%q->capacity)
|
||
|
fprintf(stderr, "%u\n", q->values[(i + 1)%q->capacity]);
|
||
|
}
|
||
|
|
||
|
void vqueue_destroy(vqueue_t *q)
|
||
|
{
|
||
|
free(q->values); q->values = NULL; free(q);
|
||
|
}
|