请求队列相关函数修改

修改了部分函数的定义
This commit is contained in:
jackfiled 2022-05-18 18:44:21 +08:00
parent 6d97591b1d
commit ced5f41220
8 changed files with 129 additions and 67 deletions

View File

@ -21,6 +21,11 @@ struct bus {
*/
typedef struct bus bus_t;
/**
*
*/
extern bus_t the_bus;
/**
* 使
* @param rails
@ -28,6 +33,6 @@ typedef struct bus bus_t;
* @param bus
* @return
*/
int RunBus(rail_node_t* rails, bus_t bus, int direction);
int RunBus(int direction);
#endif //AUTO_PILOT_BUS_BUS_H

View File

@ -10,66 +10,20 @@
#include "query.h"
#include "bus.h"
/**
*
*/
extern int BUS_TIME;
/**
*
*/
extern bus_query_t *target_query;
/**
*
*/
void AddTime();
/**
*
* @param bus
* @param queries
* @return
*/
int FCFSDirection(bus_t bus, bus_query_t queries);
int FCFSDirection();
/**
*
* @param bus
* @param queries
* @return
*/
bus_query_t FCFSQuery(bus_t bus, bus_query_t queries);
/**
*
* @param bus
* @param queries
* @return
*/
int SSTFDirection(bus_t bus, bus_query_t queries);
/**
*
* @param bus
* @param queries
* @return
*/
bus_query_t SSTFQuery(bus_t bus, bus_query_t queries);
/**
* 便
* @param bus
* @param queries
* @return
*/
int SCANDirection(bus_t bus, bus_query_t queries);
/**
* 便
* @param bus
* @param queries
* @return
*/
bus_query_t SCANQuery(bus_t bus, bus_query_t queries);
bus_query_t FCFSQuery();
#endif //AUTO_PILOT_BUS_CONTROLLER_H

View File

@ -19,30 +19,37 @@ struct bus_query {
/**
* /
*/
rail_node_t node;
rail_node_t *node;
/**
*
*/
struct bus_query *next_node;
};
typedef struct bus_query bus_query_t;
/**
*
* @param query
*
*/
extern bus_query_t *queries;
/**
*
* @param type
* @param node /
*/
void CreateQuery(bus_query_t query, int type, rail_node_t node);
bus_query_t *CreateQuery(int type, rail_node_t *node);
/**
*
* @param query
* @param target_query
*/
void DeleteQuery(bus_query_t query, bus_query_t target_query);
void DeleteQuery(bus_query_t *target_query);
/**
*
* @param queries
* @param head
*/
void FreeQueries(bus_query_t queries);
void FreeQueries(bus_query_t *head);
#endif //AUTO_PILOT_BUS_QUERY_H

View File

@ -35,6 +35,11 @@ typedef struct rail_node rail_node_t;
*/
extern rail_node_t *rails;
/**
*
*/
extern int bus_time;
/**
*
* @param head
@ -55,8 +60,10 @@ rail_node_t *CreateRails(int length, int node_num);
*
* @param railNode
*/
void FreeRails(rail_node_t railNode);
int add(int a, int b);
void FreeRails(rail_node_t *head);
/**
*
*/
void AddTime();
#endif //AUTO_PILOT_BUS_RAIL_H

View File

@ -1 +1,3 @@
#include "bus.h"
#include "bus.h"
bus_t *the_bus;

View File

@ -3,5 +3,70 @@
//
#include "query.h"
bus_query_t *queries = NULL;
bus_query_t *CreateQuery(int type, rail_node_t *node)
{
bus_query_t *p = (bus_query_t *)malloc(sizeof (bus_query_t));
p->node = node;
p->type = type;
p->time = bus_time;
p->next_node = NULL;
if(queries == NULL)
{
queries = p;
}
else
{
// 寻找链表的末节点
bus_query_t *last_node = queries;
while(last_node->next_node != NULL)
{
last_node = last_node->next_node;
}
last_node->next_node = p;
}
return p;
}
void DeleteQuery(bus_query_t *target)
{
if(target == queries)
{
queries = target->next_node;
}
else
{
bus_query_t *node = queries;
// 找到被删除节点的上一个节点
while(node->next_node != target)
{
node = node->next_node;
}
node->next_node = target->next_node;
}
free(target);
}
void FreeQueries(bus_query_t *head)
{
bus_query_t *p = head;
while (p != NULL)
{
bus_query_t *temp = p;
p = p->next_node;
free(temp);
}
// 将全局的请求列表头指针置为空
queries = NULL;
}

View File

@ -1,11 +1,7 @@
#include "rail.h"
rail_node_t *rails = NULL;
int add(int a, int b)
{
return a+ b;
}
int bus_time = 0;
rail_node_t *CreateRails(int length, int node_num)
{
@ -63,3 +59,23 @@ rail_node_t *FindNode(rail_node_t *head, int id)
return NULL;
}
void FreeRails(rail_node_t *head)
{
rail_node_t *p = head;
while (p != NULL)
{
rail_node_t *temp = p;
p = p->next_node;
free(temp);
}
// 将全局的轨道指针置为空
rails = NULL;
}
void AddTime()
{
bus_time++;
}

View File

@ -41,7 +41,7 @@ TEST(rail, CreateRails)
TEST(rail, FindNode)
{
rail_node_t *head = CreateRails(10, 10);
rail_node_t *p = nullptr;
rail_node_t *p;
p = FindNode(head, 3);
EXPECT_EQ(p->id, 3);
@ -50,6 +50,12 @@ TEST(rail, FindNode)
EXPECT_EQ(p->id, 9);
}
TEST(rail, FreeRails)
{
rail_node_t *head = CreateRails(10, 10);
FreeRails(head);
}