28 FTC_MruNode_Prepend( FTC_MruNode *plist,
31 FTC_MruNode first = *plist;
36 FTC_MruNode last = first->prev;
41 FTC_MruNode cnode = first;
48 fprintf( stderr,
"FTC_MruNode_Prepend: invalid action\n" );
53 }
while ( cnode != first );
72 FTC_MruNode_Up( FTC_MruNode *plist,
75 FTC_MruNode first = *plist;
82 FTC_MruNode prev, next, last;
87 FTC_MruNode cnode = first;
94 }
while ( cnode != first );
96 fprintf( stderr,
"FTC_MruNode_Up: invalid action\n" );
121 FTC_MruNode_Remove( FTC_MruNode *plist,
124 FTC_MruNode first = *plist;
125 FTC_MruNode prev, next;
132 FTC_MruNode cnode = first;
141 }
while ( cnode != first );
143 fprintf( stderr,
"FTC_MruNode_Remove: invalid action\n" );
157 FT_ASSERT( first == node );
158 FT_ASSERT( prev == node );
162 else if ( node == first )
168 FTC_MruList_Init( FTC_MruList list,
169 FTC_MruListClass clazz,
175 list->max_nodes = max_nodes;
177 list->clazz = *clazz;
179 list->memory = memory;
184 FTC_MruList_Reset( FTC_MruList list )
186 while ( list->nodes )
187 FTC_MruList_Remove( list, list->nodes );
189 FT_ASSERT( list->num_nodes == 0 );
194 FTC_MruList_Done( FTC_MruList list )
196 FTC_MruList_Reset( list );
201 FT_LOCAL_DEF( FTC_MruNode )
202 FTC_MruList_Find( FTC_MruList list,
205 FTC_MruNode_CompareFunc compare = list->clazz.node_compare;
206 FTC_MruNode first, node;
217 if ( compare( node, key ) )
220 FTC_MruNode_Up( &list->nodes, node );
227 }
while ( node != first);
234 FT_LOCAL_DEF( FT_Error )
235 FTC_MruList_New( FTC_MruList list,
240 FTC_MruNode node = NULL;
241 FTC_MruNode prev = NULL;
242 FT_Memory memory = list->memory;
246 if ( FT_ALLOC( node, list->clazz.node_size ) )
249 error = list->clazz.node_init( node, key, list->data );
257 else if ( list->max_nodes > 0 && list->num_nodes >= list->max_nodes )
258 prev = list->nodes->prev;
260 FTC_MruNode_Prepend( &list->nodes, node );
266 FTC_MruNode_Remove( &list->nodes, prev );
270 if ( list->clazz.node_done )
271 list->clazz.node_done( prev, list->data );
282 FT_LOCAL_DEF( FT_Error )
283 FTC_MruList_Lookup( FTC_MruList list,
290 node = FTC_MruList_Find( list, key );
292 return FTC_MruList_New( list, key, anode );
300 FTC_MruList_Remove( FTC_MruList list,
303 FT_Memory memory = list->memory;
306 FTC_MruNode_Remove( &list->nodes, node );
309 if ( list->clazz.node_done )
310 list->clazz.node_done( node, list->data );
317 FTC_MruList_RemoveSelection( FTC_MruList list,
318 FTC_MruNode_CompareFunc selection,
321 FTC_MruNode first = list->nodes;
322 FTC_MruNode prev, node;
325 if ( !first || !selection )
334 if ( selection( node, key ) )
335 FTC_MruList_Remove( list, node );
337 }
while ( node != first );