22 #include FT_INTERNAL_OBJECTS_H
23 #include FT_INTERNAL_DEBUG_H
29 #define FT_COMPONENT trace_cache
32 #define FTC_HASH_MAX_LOAD 2
33 #define FTC_HASH_MIN_LOAD 1
34 #define FTC_HASH_SUB_LOAD ( FTC_HASH_MAX_LOAD - FTC_HASH_MIN_LOAD )
37 #define FTC_HASH_INITIAL_SIZE 8
92 ftc_get_top_node_for_hash(
FTC_Cache cache,
99 idx = (
FT_UInt)( hash & cache->mask );
100 if ( idx < cache->
p )
101 idx = (
FT_UInt)( hash & ( 2 * cache->mask + 1 ) );
102 pnode = cache->buckets +
idx;
119 FT_UFast p = cache->
p;
121 FT_UFast
count = mask + p + 1;
125 if ( cache->
slack < 0 )
141 ( mask + 1 ) * 2, ( mask + 1 ) * 4 ) )
154 if ( node->
hash & ( mask + 1 ) )
157 node->
link = new_list;
164 cache->
buckets[p + mask + 1] = new_list;
170 cache->
mask = 2 * mask + 1;
180 FT_UFast old_index = p +
mask;
195 ( mask + 1 ) * 2, mask + 1 ) )
206 pnode = &(*pnode)->
link;
208 pold = cache->
buckets + old_index;
238 FT_TRACE0((
"ftc_node_hash_unlink: unknown node\n" ));
245 pnode = &(*pnode)->
link;
248 *pnode = node0->
link;
273 #ifdef FT_CONFIG_OPTION_OLD_INTERNALS
284 #ifdef FT_DEBUG_ERROR
288 FT_TRACE0((
"ftc_node_destroy: invalid node handle\n" ));
295 #ifdef FT_DEBUG_ERROR
298 FT_TRACE0((
"ftc_node_destroy: invalid node handle\n" ));
317 FT_TRACE0((
"ftc_node_destroy: invalid cache node count (%d)\n",
365 count = cache->
p + cache->
mask + 1;
367 for ( i = 0; i <
count; i++ )
408 cache->memory =
NULL;
466 error = cache->clazz.node_new( &node, query, cache );
502 if ( cache ==
NULL || anode ==
NULL )
503 return FTC_Err_Invalid_Argument;
516 if ( node->
hash == hash &&
517 compare( node, query, cache, &list_changed ) )
529 while ( *pnode != node )
531 if ( *pnode ==
NULL )
533 FT_ERROR((
"FTC_Cache_Lookup: oops!!! node missing\n" ));
537 pnode = &((*pnode)->link);
542 if ( node != *bucket )
545 node->
link = *bucket;
555 ftc_node_mru_up( node, manager );
577 count = cache->p + cache->mask + 1;
578 for ( i = 0; i <
count; i++ )
593 if ( cache->clazz.node_remove_faceid( node, face_id,
594 cache, &list_changed ) )
614 manager->
cur_weight -= cache->clazz.node_weight( node, cache );
617 cache->clazz.node_free( node, cache );
static void ftc_node_hash_link(FTC_Node node, FTC_Cache cache)
#define FTC_CACHE_TRYLOOP_END(list_changed)
GLvoid **typedef void(GLAPIENTRY *PFNGLGETVERTEXATTRIBDVPROC)(GLuint
FTC_Manager_Compress(FTC_Manager manager)
typedefFT_BEGIN_HEADER struct FTC_MruNodeRec_ * FTC_MruNode
FTC_MruNode_Remove(FTC_MruNode *plist, FTC_MruNode node)
#define FTC_CACHE_TRYLOOP(cache)
FT_BEGIN_HEADER typedef FT_Pointer FTC_FaceID
ftc_cache_init(FTC_Cache cache)
FT_BEGIN_HEADER typedef unsigned char FT_Bool
#define FT_ERROR(varformat)
FTC_Node_FreeFunc node_free
FTC_Cache_Done(FTC_Cache cache)
#define FTC_HASH_MAX_LOAD
FTC_Cache_NewNode(FTC_Cache cache, FT_PtrDist hash, FT_Pointer query, FTC_Node *anode)
#define FTC_HASH_SUB_LOAD
#define FTC_HASH_INITIAL_SIZE
static void ftc_cache_resize(FTC_Cache cache)
FTC_Node_WeightFunc node_weight
#define FT_TRACE0(varformat)
static void ftc_cache_add(FTC_Cache cache, FT_PtrDist hash, FTC_Node node)
FTC_MruNode_Up(FTC_MruNode *plist, FTC_MruNode node)
static void ftc_node_hash_unlink(FTC_Node node0, FTC_Cache cache)
#define FT_RENEW_ARRAY(ptr, curcnt, newcnt)
ftc_node_destroy(FTC_Node node, FTC_Manager manager)
FTC_Cache caches[FTC_MAX_CACHES]
static void ftc_node_mru_link(FTC_Node node, FTC_Manager manager)
typedefFT_BEGIN_HEADER struct FT_MemoryRec_ * FT_Memory
#define FT_NEW_ARRAY(ptr, count)
FTC_Cache_RemoveFaceID(FTC_Cache cache, FTC_FaceID face_id)
GLint GLint GLint GLint GLint GLint GLint GLbitfield mask
#define FTC_NODE__TOP_FOR_HASH(cache, hash)
static void FTC_Cache_Clear(FTC_Cache cache)
FTC_Cache_Init(FTC_Cache cache)
FT_Bool(* FTC_Node_CompareFunc)(FTC_Node node, FT_Pointer key, FTC_Cache cache, FT_Bool *list_changed)
ftc_cache_done(FTC_Cache cache)
static void ftc_node_mru_unlink(FTC_Node node, FTC_Manager manager)
FTC_MruNode_Prepend(FTC_MruNode *plist, FTC_MruNode node)