Skip to content

Commit

Permalink
HevList: Init.
Browse files Browse the repository at this point in the history
  • Loading branch information
heiher committed May 19, 2021
1 parent efe3fba commit 1cf3a91
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/misc/hev-list.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
============================================================================
Name : hev-list.c
Authors : Heiher <[email protected]>
Copyright : Copyright (c) 2019 everyone.
Description : Double-linked List
============================================================================
*/

#include <stddef.h>

#include "hev-list.h"

void
hev_list_add_tail (HevList *self, HevListNode *new_)
{
new_->prev = self->tail;
new_->next = NULL;

if (self->tail)
self->tail->next = new_;
else
self->head = new_;
self->tail = new_;
}

void
hev_list_del (HevList *self, HevListNode *node)
{
if (node->prev)
node->prev->next = node->next;
else
self->head = node->next;

if (node->next)
node->next->prev = node->prev;
else
self->tail = node->prev;
}
63 changes: 63 additions & 0 deletions src/misc/hev-list.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
============================================================================
Name : hev-list.h
Authors : Heiher <[email protected]>
Copyright : Copyright (c) 2019 everyone.
Description : Double-linked List
============================================================================
*/

#ifndef __HEV_LIST_H__
#define __HEV_LIST_H__

#ifdef __cplusplus
extern "C" {
#endif

typedef struct _HevList HevList;
typedef struct _HevListNode HevListNode;

struct _HevList
{
HevListNode *head;
HevListNode *tail;
};

struct _HevListNode
{
HevListNode *next;
HevListNode *prev;
};

static inline HevListNode *
hev_list_node_prev (HevListNode *node)
{
return node->prev;
}

static inline HevListNode *
hev_list_node_next (HevListNode *node)
{
return node->next;
}

static inline HevListNode *
hev_list_first (HevList *self)
{
return self->head;
}

static inline HevListNode *
hev_list_last (HevList *self)
{
return self->tail;
}

void hev_list_add_tail (HevList *self, HevListNode *new_);
void hev_list_del (HevList *self, HevListNode *node);

#ifdef __cplusplus
}
#endif

#endif /* __HEV_LIST_H__ */

0 comments on commit 1cf3a91

Please sign in to comment.