NODE_DATA sflist_remove_head(SF_LIST* s)
{
NODE_DATA ndata = nullptr;
- SF_QNODE* q;
+ SF_LNODE* q;
if ( s && s->head )
{
q = s->head;
NODE_DATA sflist_remove_tail(SF_LIST* s)
{
NODE_DATA ndata = nullptr;
- SF_QNODE* q;
+ SF_LNODE* q;
if (s && s->tail)
{
q = s->tail;
return (NODE_DATA)ndata;
}
-void sflist_remove_node(SF_LIST* s, SF_LNODE* n)
-{
- SF_LNODE* cur;
-
- if ( n == s->head )
- {
- s->head = s->head->next;
- s->count--;
-
- if (!s->head)
- s->tail = nullptr;
- else
- s->head->prev = nullptr;
-
- snort_free(n);
- return;
- }
- else if ( n == s->tail )
- {
- s->tail = s->tail->prev;
- s->count--;
-
- if (!s->tail )
- s->head = nullptr;
- else
- s->tail->next = nullptr;
-
- snort_free(n);
- return;
- }
-
- for (cur = s->head;
- cur!= nullptr;
- cur = cur->next )
- {
- if ( n == cur )
- {
- /* unlink a middle node */
- n->next->prev = n->prev;
- n->prev->next = n->next;
- s->count--;
- snort_free(n);
- return;
- }
- }
-}
-
int sflist_count(SF_LIST* s)
{
if (!s)
}
-// ----- queue methods -----
-
-using namespace snort;
-
-SF_QUEUE* sfqueue_new()
-{
- return (SF_QUEUE*)sflist_new();
-}
-
-void sfqueue_add(SF_QUEUE* s, NODE_DATA ndata)
-{
- sflist_add_tail(s, ndata);
-}
-
-
-NODE_DATA sfqueue_remove(SF_QUEUE* s)
-{
- return (NODE_DATA)sflist_remove_head(s);
-}
-
-int sfqueue_count(SF_QUEUE* s)
-{
- if (!s)
- return 0;
- return s->count;
-}
-
-void sfqueue_free_all(SF_QUEUE* s,void (* nfree)(void*) )
-{
- sflist_free_all(s, nfree);
-}
#include "main/snort_types.h"
-// Simple LIST, STACK, QUEUE DICTIONARY (LIST BASED) interface
-// All of these functions are based on lists.
-// Use STL containers instead of these if possible.
+// Simple LIST interface
+// Switch to STL containers ASAP
+// FIXIT-M deprecated, we are going to delete this
-// FIXIT-L if we're going to keep sflsq around (instead of using STL data
-// structures) it would make sense to template the interfaces instead of
-// using a void* for data
-
-// FIXIT-M but we are going to delete sflsq and use STL instead
-
-// Note that NODE_DATA can be redefined with the typedef below
typedef void* NODE_DATA;
-// Simple list, stack, or queue NODE
typedef struct sf_lnode
{
struct sf_lnode* next;
struct sf_lnode* prev;
NODE_DATA ndata;
}
-SF_QNODE,SF_SNODE,SF_LNODE;
-
-// Integer Stack - uses an array from the subroutines stack
-struct SF_ISTACK
-{
- unsigned* stack;
- unsigned nstack;
- unsigned n;
-};
-
-// Pointer Stack - uses an array from the subroutines stack
-struct SF_PSTACK
-{
- void** stack;
- unsigned nstack;
- unsigned n;
-};
+SF_LNODE;
-// Simple Structure for Queue's, stacks, lists
struct sf_list
{
SF_LNODE* head, * tail;
unsigned count;
};
-typedef sf_list SF_QUEUE;
typedef sf_list SF_LIST;
// -----------------------------------------------------------------------------
// Linked List Interface
// -----------------------------------------------------------------------------
+
namespace snort
{
SO_PUBLIC SF_LIST* sflist_new();
SO_PUBLIC void sflist_add_before(SF_LIST*, SF_LNODE*, NODE_DATA);
SO_PUBLIC NODE_DATA sflist_remove_head(SF_LIST*);
SO_PUBLIC NODE_DATA sflist_remove_tail(SF_LIST*);
-SO_PUBLIC void sflist_remove_node(SF_LIST*, SF_LNODE*);
SO_PUBLIC int sflist_count(SF_LIST*);
SO_PUBLIC NODE_DATA sflist_first(SF_LIST*, SF_LNODE**);
SO_PUBLIC NODE_DATA sflist_next(SF_LNODE**);
SO_PUBLIC void sflist_static_free_all(SF_LIST*, void (* nfree)(void*));
}
-// -----------------------------------------------------------------------------
-// Queue Interface ( FIFO - First in, First out )
-// -----------------------------------------------------------------------------
-SF_QUEUE* sfqueue_new();
-void sfqueue_add(SF_QUEUE*, NODE_DATA);
-NODE_DATA sfqueue_remove(SF_QUEUE*);
-int sfqueue_count(SF_QUEUE*);
-void sfqueue_free_all(SF_QUEUE*, void (* free)(void*) );
-
#endif