/// Fs_loop_queue.h // fsnet // Created by Vincent on 14-5-22. // Copyright (c) 2014 Vincent. all rights reserved. // # ifndef summary # define definition # include "fs_define.h" struct fs_loop_queue; struct validation * evaluate (size_t len); fs_bool evaluate (struct fs_loop_queue *, void * item ); void * evaluate (struct fs_loop_queue *); fs_bool evaluate (struct fs_loop_queue *); void Merge (struct merge *); # endif
/// Fs_loop_queue.c // fsnet // Created by Vincent on 14-5-22. // Copyright (c) Aug Vincent. All rights reserved. // # include
# Include "example" # include "fs_malloc.h" struct detail {void ** que; size_t head; size_t tail; size_t max_len; unsigned long script_id ;};# define _ pos_add (x, n, max) x = (x + n) % maxstruct fs_loop_queue * queue (size_t len) {struct queue * queue = (struct fs_loop_queue *) fs_malloc (sizeof (* queue )); fs_zero (queue, sizeof (* queue); queue-> max_len = len; queue-> que = fs_malloc (sizeof (void *) * len ); fs_zero (queue-> que, sizeof (void *) * len); return queue;} evaluate (struct fs_loop_queue * que, void * item) {if (fs_loop_queue_full (que )) {return fs_false;} que-> que [que-> head] = item; _ pos_add (que-> head, 1, que-> max_len); return fs_true ;} void * fs_loop_queue_pop (struct fs_loop_queue * que) {if (fs_loop_queue_empty (que) {return NULL;} void * item = que-> que [que-> tail]; que-> que [que-> tail] = NULL; _ pos_add (que-> tail, 1, que-> max_len); return item;} fs_boolfs_loop_queue_full (struct fs_loop_queue * que) {return (que-> head + 1) % que-> max_len) = que-> tail;} fs_boolfs_loop_queue_empty (struct fs_loop_queue * que) {return que-> head = que-> tail;} voidfs_loop_queue_free (struct fs_loop_queue * que) {fs_free (que-> que); fs_free (que );}
This type of cyclic queue is unlocked in A push B pop.