g4tools  5.4.0
Classes | Macros | Typedefs | Functions
dict File Reference
#include <cstddef>
#include "memalloc"
Include dependency graph for dict:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  DictNode
 
struct  Dict
 

Macros

#define tools_glutess_dict_list
 
#define DictKey   DictListKey
 
#define Dict   DictList
 
#define DictNode   DictListNode
 
#define dictNewDict(frame, leq)   __gl_dictListNewDict(frame,leq)
 
#define dictDeleteDict(dict)   __gl_dictListDeleteDict(dict)
 
#define dictSearch(dict, key)   __gl_dictListSearch(dict,key)
 
#define dictInsert(dict, key)   __gl_dictListInsert(dict,key)
 
#define dictInsertBefore(dict, node, key)   __gl_dictListInsertBefore(dict,node,key)
 
#define dictDelete(dict, node)   __gl_dictListDelete(dict,node)
 
#define dictKey(n)   __gl_dictListKey(n)
 
#define dictSucc(n)   __gl_dictListSucc(n)
 
#define dictPred(n)   __gl_dictListPred(n)
 
#define dictMin(d)   __gl_dictListMin(d)
 
#define dictMax(d)   __gl_dictListMax(d)
 
#define __gl_dictListKey(n)   ((n)->key)
 
#define __gl_dictListSucc(n)   ((n)->next)
 
#define __gl_dictListPred(n)   ((n)->prev)
 
#define __gl_dictListMin(d)   ((d)->head.next)
 
#define __gl_dictListMax(d)   ((d)->head.prev)
 
#define __gl_dictListInsert(d, k)   (dictInsertBefore((d),&(d)->head,(k)))
 

Typedefs

typedef void * DictKey
 
typedef struct Dict Dict
 
typedef struct DictNode DictNode
 

Functions

DictdictNewDict (void *frame, int(*leq)(void *frame, DictKey key1, DictKey key2))
 inlined C code : /////////////////////////////////// More...
 
void dictDeleteDict (Dict *dict)
 
DictNodedictInsertBefore (Dict *dict, DictNode *node, DictKey key)
 
void dictDelete (Dict *, DictNode *node)
 
DictNodedictSearch (Dict *dict, DictKey key)
 

Macro Definition Documentation

◆ __gl_dictListInsert

#define __gl_dictListInsert (   d,
 
)    (dictInsertBefore((d),&(d)->head,(k)))

Definition at line 35 of file dict.

◆ __gl_dictListKey

#define __gl_dictListKey (   n)    ((n)->key)

Definition at line 30 of file dict.

◆ __gl_dictListMax

#define __gl_dictListMax (   d)    ((d)->head.prev)

Definition at line 34 of file dict.

◆ __gl_dictListMin

#define __gl_dictListMin (   d)    ((d)->head.next)

Definition at line 33 of file dict.

◆ __gl_dictListPred

#define __gl_dictListPred (   n)    ((n)->prev)

Definition at line 32 of file dict.

◆ __gl_dictListSucc

#define __gl_dictListSucc (   n)    ((n)->next)

Definition at line 31 of file dict.

◆ Dict

#define Dict   DictList

Definition at line 9 of file dict.

◆ dictDelete

#define dictDelete (   dict,
  node 
)    __gl_dictListDelete(dict,node)

Definition at line 18 of file dict.

◆ dictDeleteDict

#define dictDeleteDict (   dict)    __gl_dictListDeleteDict(dict)

Definition at line 13 of file dict.

◆ dictInsert

#define dictInsert (   dict,
  key 
)    __gl_dictListInsert(dict,key)

Definition at line 16 of file dict.

◆ dictInsertBefore

#define dictInsertBefore (   dict,
  node,
  key 
)    __gl_dictListInsertBefore(dict,node,key)

Definition at line 17 of file dict.

◆ DictKey

#define DictKey   DictListKey

Definition at line 8 of file dict.

◆ dictKey

#define dictKey (   n)    __gl_dictListKey(n)

Definition at line 20 of file dict.

◆ dictMax

#define dictMax (   d)    __gl_dictListMax(d)

Definition at line 24 of file dict.

◆ dictMin

#define dictMin (   d)    __gl_dictListMin(d)

Definition at line 23 of file dict.

◆ dictNewDict

#define dictNewDict (   frame,
  leq 
)    __gl_dictListNewDict(frame,leq)

Definition at line 12 of file dict.

◆ DictNode

#define DictNode   DictListNode

Definition at line 10 of file dict.

◆ dictPred

#define dictPred (   n)    __gl_dictListPred(n)

Definition at line 22 of file dict.

◆ dictSearch

#define dictSearch (   dict,
  key 
)    __gl_dictListSearch(dict,key)

Definition at line 15 of file dict.

◆ dictSucc

#define dictSucc (   n)    __gl_dictListSucc(n)

Definition at line 21 of file dict.

◆ tools_glutess_dict_list

#define tools_glutess_dict_list

Definition at line 4 of file dict.

Typedef Documentation

◆ Dict

typedef struct Dict Dict

Definition at line 26 of file dict.

◆ DictKey

typedef void* DictKey

Definition at line 26 of file dict.

◆ DictNode

typedef struct DictNode DictNode

Definition at line 26 of file dict.

Function Documentation

◆ dictDelete()

void dictDelete ( Dict ,
DictNode node 
)
inline

Definition at line 109 of file dict.

110 {
111  node->next->prev = node->prev;
112  node->prev->next = node->next;
113  memFree( node );
114 }

◆ dictDeleteDict()

void dictDeleteDict ( Dict dict)
inline

Definition at line 75 of file dict.

75  {
76  DictNode *node, *next;
77 
78  for( node = dict->head.next; node != &dict->head; node = next ) {
79  next = node->next;
80  memFree( node );
81  }
82  memFree( dict );
83 }

◆ dictInsertBefore()

DictNode* dictInsertBefore ( Dict dict,
DictNode node,
DictKey  key 
)
inline

Definition at line 90 of file dict.

90  {
91  DictNode *newNode;
92 
93  do {
94  node = node->prev;
95  } while( node->key != NULL && ! (*dict->leq)(dict->frame, node->key, key));
96 
97  newNode = (DictNode *) memAlloc( sizeof( DictNode ));
98  if (newNode == NULL) return NULL;
99 
100  newNode->key = key;
101  newNode->next = node->next;
102  node->next->prev = newNode;
103  newNode->prev = node;
104  node->next = newNode;
105 
106  return newNode;
107 }

◆ dictNewDict()

Dict* dictNewDict ( void *  frame,
int(*)(void *frame, DictKey key1, DictKey key2)  leq 
)
inline

inlined C code : ///////////////////////////////////

Definition at line 57 of file dict.

57  {
58  Dict *dict = (Dict *) memAlloc( sizeof( Dict ));
59  DictNode *head;
60 
61  if (dict == NULL) return NULL;
62 
63  head = &dict->head;
64 
65  head->key = NULL;
66  head->next = head;
67  head->prev = head;
68 
69  dict->frame = frame;
70  dict->leq = leq;
71 
72  return dict;
73 }

◆ dictSearch()

DictNode* dictSearch ( Dict dict,
DictKey  key 
)
inline

Definition at line 116 of file dict.

117 {
118  DictNode *node = &dict->head;
119 
120  do {
121  node = node->next;
122  } while( node->key != NULL && ! (*dict->leq)(dict->frame, key, node->key));
123 
124  return node;
125 }
memFree
#define memFree
Definition: memalloc:42
DictNode::next
DictNode * next
Definition: dict:41
memAlloc
#define memAlloc
Definition: memalloc:40
Dict
Definition: dict:45
DictNode::key
DictKey key
Definition: dict:40
DictNode::prev
DictNode * prev
Definition: dict:42
Dict::head
DictNode head
Definition: dict:46
Dict::leq
int(* leq)(void *frame, DictKey key1, DictKey key2)
Definition: dict:48
DictNode
Definition: dict:39
Dict::frame
void * frame
Definition: dict:47