Skip to content
Snippets Groups Projects
Commit c4e62754 authored by Anjan Chanda's avatar Anjan Chanda
Browse files

remove copy of hlist.h

parent d1d46e91
No related branches found
No related tags found
No related merge requests found
...@@ -20,8 +20,8 @@ ...@@ -20,8 +20,8 @@
#include <sys/time.h> #include <sys/time.h>
#include <libubox/list.h> #include <libubox/list.h>
#include <easy/easy.h>
#include "bufutil.h" #include "bufutil.h"
#include "hlist.h"
/** struct cmdu_header - IEEE-1905 CMDU header */ /** struct cmdu_header - IEEE-1905 CMDU header */
struct cmdu_header { struct cmdu_header {
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
#define CMDU_ACKQ_H #define CMDU_ACKQ_H
#include "hlist.h" #include <easy/easy.h>
#define CMDU_BACKLOG_MAX 128 #define CMDU_BACKLOG_MAX 128
......
...@@ -19,8 +19,9 @@ ...@@ -19,8 +19,9 @@
#include <sys/time.h> #include <sys/time.h>
#include <libubox/list.h> #include <libubox/list.h>
#include <easy/easy.h>
#include "bufutil.h" #include "bufutil.h"
#include "hlist.h"
#include "cmdu.h" #include "cmdu.h"
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
#include <sys/time.h> #include <sys/time.h>
#include <libubox/list.h> #include <libubox/list.h>
#include "hlist.h" #include <easy/easy.h>
......
/*
* hlist.h - stripped down version of hash list implementation using
* singly linked list.
* Doubly linked list is wastage of space for big hash-tables. If cost of
* iterating a hash list is significant, it means the hash function is NOT
* formulated well and should be revisited.
*
* Copyright (C) 2021 IOPSYS Software Solutions AB. All rights reserved.
*
* Author: anjan.chanda@iopsys.eu
*
*/
#ifndef _HLIST_H
#define _HLIST_H
struct hlist_node {
struct hlist_node *next;
};
struct hlist_head {
struct hlist_node *first;
};
#define HLIST_HEAD_INIT(name) { &(name) }
#define HLIST_HEAD(name) struct hlist_head name = HLIST_HEAD_INIT(name)
static inline void INIT_HLIST_HEAD(struct hlist_head *h)
{
h->first = NULL;
}
static inline void INIT_HLIST_NODE(struct hlist_node *n)
{
n->next = NULL;
}
static inline int hlist_empty(const struct hlist_head *h)
{
return !h->first;
}
static inline void __hlist_del(struct hlist_node *prev, struct hlist_node *n)
{
prev->next = n->next;
n->next = NULL;
}
static inline void hlist_del(struct hlist_node *n, struct hlist_head *h)
{
struct hlist_node *p;
if (h->first == n) {
h->first = n->next;
n->next = NULL;
return;
}
for (p = h->first; p; p = p->next) {
if (p->next == n)
__hlist_del(p, n);
}
}
static inline void _hlist_add(struct hlist_node *_new, struct hlist_head *h)
{
_new->next = h->first;
h->first = _new;
}
static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h)
{
_hlist_add(n, h);
}
#define hlist_for_each(pos, head) \
for (pos = (head)->first; pos ; pos = pos->next)
#define hlist_for_each_safe(pos, n, head) \
for (pos = (head)->first; pos && ({ n = pos->next; 1; }); \
pos = n)
#define hlist_entry(ptr, type, member) container_of(ptr, type, member)
#define hlist_entry_safe(ptr, type, member) \
({ typeof(ptr) ____ptr = (ptr); \
____ptr ? hlist_entry(____ptr, type, member) : NULL; \
})
#define hlist_for_each_entry(pos, head, member) \
for (pos = hlist_entry_safe((head)->first, typeof(*(pos)), member); \
pos; \
pos = hlist_entry_safe((pos)->member.next, typeof(*(pos)), member))
#define hlist_for_each_entry_safe(pos, n, head, member) \
for (pos = hlist_entry_safe((head)->first, typeof(*pos), member); \
pos && ({ n = pos->member.next; 1; }); \
pos = hlist_entry_safe(n, typeof(*pos), member))
#endif /* _HLIST_H */
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
#include <easy/easy.h> #include <easy/easy.h>
#include "hlist.h"
#define NEIGH_ENTRIES_MAX 128 #define NEIGH_ENTRIES_MAX 128
#define NEIGH_AGEOUT_DEFAULT 60000 /* msecs */ #define NEIGH_AGEOUT_DEFAULT 60000 /* msecs */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment