SphinxBase 5prealpha
glist.h File Reference

Generic linked-lists maintenance. More...

#include <stdlib.h>
#include <sphinxbase/sphinxbase_export.h>
#include <sphinxbase/prim_type.h>

Go to the source code of this file.

Data Structures

struct  gnode_s
 A node in a generic list. More...
 

Macros

#define gnode_ptr(g)   ((g)->data.ptr)
 Head of a list of gnodes.
 
#define gnode_int32(g)   ((g)->data.i)
 
#define gnode_uint32(g)   ((g)->data.ui)
 
#define gnode_float32(g)   ((float32)(g)->data.fl)
 
#define gnode_float64(g)   ((g)->data.fl)
 
#define gnode_next(g)   ((g)->next)
 

Typedefs

typedef struct gnode_s gnode_t
 A node in a generic list.
 
typedef gnode_tglist_t
 

Functions

SPHINXBASE_EXPORT glist_t glist_add_ptr (glist_t g, void *ptr)
 Create and prepend a new list node, with the given user-defined data, at the HEAD of the given generic list.
 
SPHINXBASE_EXPORT glist_t glist_add_int32 (glist_t g, int32 val)
 Create and prepend a new list node containing an integer.
 
SPHINXBASE_EXPORT glist_t glist_add_uint32 (glist_t g, uint32 val)
 Create and prepend a new list node containing an unsigned integer.
 
SPHINXBASE_EXPORT glist_t glist_add_float32 (glist_t g, float32 val)
 Create and prepend a new list node containing a single-precision float.
 
SPHINXBASE_EXPORT glist_t glist_add_float64 (glist_t g, float64 val)
 Create and prepend a new list node containing a double-precision float.
 
SPHINXBASE_EXPORT gnode_tglist_insert_ptr (gnode_t *gn, void *ptr)
 Create and insert a new list node, with the given user-defined data, after the given generic node gn.
 
SPHINXBASE_EXPORT gnode_tglist_insert_int32 (gnode_t *gn, int32 val)
 Create and insert a new list node containing an integer.
 
SPHINXBASE_EXPORT gnode_tglist_insert_uint32 (gnode_t *gn, uint32 val)
 Create and insert a new list node containing an unsigned integer.
 
SPHINXBASE_EXPORT gnode_tglist_insert_float32 (gnode_t *gn, float32 val)
 Create and insert a new list node containing a single-precision float.
 
SPHINXBASE_EXPORT gnode_tglist_insert_float64 (gnode_t *gn, float64 val)
 Create and insert a new list node containing a double-precision float.
 
SPHINXBASE_EXPORT glist_t glist_reverse (glist_t g)
 Reverse the order of the given glist.
 
SPHINXBASE_EXPORT int32 glist_count (glist_t g)
 Count the number of element in a given link list.
 
SPHINXBASE_EXPORT void glist_free (glist_t g)
 Free the given generic list; user-defined data contained within is not automatically freed.
 
SPHINXBASE_EXPORT gnode_tgnode_free (gnode_t *gn, gnode_t *pred)
 Free the given node, gn, of a glist, pred being its predecessor in the list.
 
SPHINXBASE_EXPORT gnode_tglist_tail (glist_t g)
 Return the last node in the given list.
 

Detailed Description

Generic linked-lists maintenance.

Only insert at the head of the list. A convenient little linked-list package, but a double-edged sword: the user must keep track of the data type within the linked list elements. When it was first written, there was no selective deletions except to destroy the entire list. This is modified in later version.

(C++ would be good for this, but that's a double-edged sword as well.)

Definition in file glist.h.

Macro Definition Documentation

◆ gnode_float32

#define gnode_float32 ( g)    ((float32)(g)->data.fl)

Definition at line 112 of file glist.h.

◆ gnode_float64

#define gnode_float64 ( g)    ((g)->data.fl)

Definition at line 113 of file glist.h.

◆ gnode_int32

#define gnode_int32 ( g)    ((g)->data.i)

Definition at line 110 of file glist.h.

◆ gnode_next

#define gnode_next ( g)    ((g)->next)

Definition at line 114 of file glist.h.

◆ gnode_ptr

#define gnode_ptr ( g)    ((g)->data.ptr)

Head of a list of gnodes.

Access macros, for convenience

Definition at line 109 of file glist.h.

Referenced by cmd_ln_free_r(), jsgf_grammar_free(), listelem_alloc_free(), listelem_get_item(), listelem_stats(), ngram_model_read_classdef(), ngram_model_set_read(), and parse_subvecs().

◆ gnode_uint32

#define gnode_uint32 ( g)    ((g)->data.ui)

Definition at line 111 of file glist.h.

Typedef Documentation

◆ glist_t

typedef gnode_t* glist_t

Definition at line 104 of file glist.h.

Function Documentation

◆ glist_add_float32()

SPHINXBASE_EXPORT glist_t glist_add_float32 ( glist_t g,
float32 val )

Create and prepend a new list node containing a single-precision float.

Parameters
ga link list
vala float32 vlaue

Definition at line 110 of file glist.c.

References ckd_calloc, glist_add_float32(), and gnode_s::next.

Referenced by glist_add_float32(), and ngram_model_add_class().

◆ glist_add_float64()

SPHINXBASE_EXPORT glist_t glist_add_float64 ( glist_t g,
float64 val )

Create and prepend a new list node containing a double-precision float.

Parameters
ga link list
vala float64 vlaue

Definition at line 122 of file glist.c.

References ckd_calloc, glist_add_float64(), and gnode_s::next.

Referenced by glist_add_float64().

◆ glist_add_int32()

SPHINXBASE_EXPORT glist_t glist_add_int32 ( glist_t g,
int32 val )

Create and prepend a new list node containing an integer.

Parameters
ga link list
valan integer value

Definition at line 86 of file glist.c.

References ckd_calloc, glist_add_int32(), and gnode_s::next.

Referenced by glist_add_int32(), and parse_subvecs().

◆ glist_add_ptr()

SPHINXBASE_EXPORT glist_t glist_add_ptr ( glist_t g,
void * ptr )

Create and prepend a new list node, with the given user-defined data, at the HEAD of the given generic list.

Return the new list thus formed. g may be NULL to indicate an initially empty list.

Parameters
ga link list
ptra pointer

Definition at line 74 of file glist.c.

References ckd_calloc, glist_add_ptr(), and gnode_s::next.

Referenced by glist_add_ptr(), hash_table_tolist(), ngram_model_set_read(), and parse_subvecs().

◆ glist_add_uint32()

SPHINXBASE_EXPORT glist_t glist_add_uint32 ( glist_t g,
uint32 val )

Create and prepend a new list node containing an unsigned integer.

Parameters
ga link list
valan unsigned integer value

Definition at line 98 of file glist.c.

References ckd_calloc, glist_add_uint32(), and gnode_s::next.

Referenced by glist_add_uint32().

◆ glist_count()

SPHINXBASE_EXPORT int32 glist_count ( glist_t g)

Count the number of element in a given link list.

Returns
the number of elements in the given glist_t
Parameters
ginput link list

Definition at line 145 of file glist.c.

References glist_count(), and gnode_s::next.

Referenced by glist_count(), ngram_model_set_read(), and parse_subvecs().

◆ glist_free()

SPHINXBASE_EXPORT void glist_free ( glist_t g)

Free the given generic list; user-defined data contained within is not automatically freed.

The caller must have done that already.

Definition at line 133 of file glist.c.

References ckd_free(), glist_free(), and gnode_s::next.

Referenced by cmd_ln_free_r(), glist_free(), jsgf_grammar_free(), listelem_alloc_free(), ngram_model_add_class(), ngram_model_read_classdef(), ngram_model_set_read(), and parse_subvecs().

◆ glist_insert_float32()

SPHINXBASE_EXPORT gnode_t * glist_insert_float32 ( gnode_t * gn,
float32 val )

Create and insert a new list node containing a single-precision float.

Parameters
gna generic node which a value will be inserted after it
valfloat32 inserted

Definition at line 230 of file glist.c.

References ckd_calloc, glist_insert_float32(), and gnode_s::next.

Referenced by glist_insert_float32().

◆ glist_insert_float64()

SPHINXBASE_EXPORT gnode_t * glist_insert_float64 ( gnode_t * gn,
float64 val )

Create and insert a new list node containing a double-precision float.

Parameters
gna generic node which a value will be inserted after it
valfloat64 inserted

Definition at line 244 of file glist.c.

References ckd_calloc, glist_insert_float64(), and gnode_s::next.

Referenced by glist_insert_float64().

◆ glist_insert_int32()

SPHINXBASE_EXPORT gnode_t * glist_insert_int32 ( gnode_t * gn,
int32 val )

Create and insert a new list node containing an integer.

Parameters
gna generic node which a value will be inserted after it
valint32 inserted

Definition at line 201 of file glist.c.

References ckd_calloc, glist_insert_int32(), and gnode_s::next.

Referenced by glist_insert_int32().

◆ glist_insert_ptr()

SPHINXBASE_EXPORT gnode_t * glist_insert_ptr ( gnode_t * gn,
void * ptr )

Create and insert a new list node, with the given user-defined data, after the given generic node gn.

gn cannot be NULL. Return ptr to the newly created gnode_t.

Parameters
gna generic node which ptr will be inserted after it
ptrpointer inserted

Definition at line 187 of file glist.c.

References ckd_calloc, glist_insert_ptr(), and gnode_s::next.

Referenced by glist_insert_ptr().

◆ glist_insert_uint32()

SPHINXBASE_EXPORT gnode_t * glist_insert_uint32 ( gnode_t * gn,
uint32 val )

Create and insert a new list node containing an unsigned integer.

Parameters
gna generic node which a value will be inserted after it
valuint32 inserted

Definition at line 215 of file glist.c.

References ckd_calloc, glist_insert_uint32(), and gnode_s::next.

Referenced by glist_insert_uint32().

◆ glist_reverse()

SPHINXBASE_EXPORT glist_t glist_reverse ( glist_t g)

Reverse the order of the given glist.

(glist_add() adds to the head; one might ultimately want the reverse of that.) NOTE: The list is reversed "in place"; i.e., no new memory is allocated.

Returns
: The head of the new list.
Parameters
ginput link list

Definition at line 169 of file glist.c.

References glist_reverse(), and gnode_s::next.

Referenced by glist_reverse(), ngram_model_add_class(), and ngram_model_set_read().

◆ glist_tail()

SPHINXBASE_EXPORT gnode_t * glist_tail ( glist_t g)

Return the last node in the given list.

Definition at line 156 of file glist.c.

References glist_tail(), and gnode_s::next.

Referenced by glist_tail().

◆ gnode_free()

SPHINXBASE_EXPORT gnode_t * gnode_free ( gnode_t * gn,
gnode_t * pred )

Free the given node, gn, of a glist, pred being its predecessor in the list.

Return ptr to the next node in the list after the freed node.

Definition at line 257 of file glist.c.

References ckd_free(), gnode_free(), and gnode_s::next.

Referenced by gnode_free().