1616
1717#define MAXIMUM (a ,b ) (((a)>(b)) ? (a) : (b))
1818
19+ typedef struct completion_trie_viz_params_t
20+ {
21+ uint16_t FrameNumber ;
22+ uint32_t HighlightedNodeIdx ;
23+ } completion_trie_viz_params_t ;
24+
1925static inline void InitializeCIdentifierCharacters (completion_trie_root_t * root ) {
2026 static const char cIdentifierChars [] =
2127 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_" ;
@@ -388,7 +394,12 @@ LinsertNode: {}
388394 * @param rootPrefix The prefix of the root node.
389395 * @param f The file to which the DOT code will be written.
390396 */
391- void CompletionTrie_Print (completion_trie_root_t * root , uint32_t nodeIdx , const char * rootPrefix , FILE * f ) {
397+ void CompletionTrie_Print (completion_trie_root_t * root ,
398+ uint32_t nodeIdx ,
399+ const char * rootPrefix ,
400+ FILE * f ,
401+ const completion_trie_viz_params_t * params
402+ ) {
392403 // Retrieve a pointer to the nodes array for easier access
393404 completion_trie_node_t const * nodes = root -> Nodes ;
394405 uint32_t childIdx ;
@@ -406,6 +417,12 @@ void CompletionTrie_Print(completion_trie_root_t* root, uint32_t nodeIdx, const
406417 childIdx , nodes [childIdx ].Prefix4 );
407418 }
408419
420+ // Output highlight if we have params
421+ if (params && params -> HighlightedNodeIdx == nodeIdx )
422+ {
423+ fprintf (f , "{ %d: %.4s [color=red style=filled fillcolor=lightpink] }\n" ,
424+ nodeIdx , rootPrefix );
425+ }
409426 // Output DOT code to ensure that child nodes appear in the same rank
410427 fprintf (f , "{ rank = same; " );
411428 for (childIdx = childIdxBegin ; childIdx < childIdxEnd ; childIdx ++ )
@@ -421,21 +438,34 @@ void CompletionTrie_Print(completion_trie_root_t* root, uint32_t nodeIdx, const
421438 if (nodes [childIdx ].ChildCount )
422439 {
423440 // Recursively traverse child nodes with ChildCount
424- CompletionTrie_Print (root , childIdx , nodes [childIdx ].Prefix4 , f );
441+ CompletionTrie_Print (root , childIdx , nodes [childIdx ].Prefix4 , f , params );
425442 }
426443 }
427444}
428445
446+ completion_trie_node_t * CompletionTrie_SplitNode (completion_trie_root_t * root ,
447+ completion_trie_node_t * nodeToSplit ,
448+ int splitAt )
449+ {
450+ return 0 ;
451+ }
452+
429453void CompletionTrie_Add (completion_trie_root_t * root , const char * word , uint32_t length )
430454{
431455 uint32_t remaining_length = length ;
432456 completion_trie_node_t * parentNode =
433457 CompletionTrie_FindLongestMatchingPrefix (root , word , & remaining_length );
434458
459+
435460 if (remaining_length )
436461 {
437462 int posWord = length - remaining_length ;
438463 parentNode = CompletionTrie_AddChild (root , parentNode , word + posWord , remaining_length );
464+ if (parentNode -> ChildCount != 0 )
465+ {
466+ // here we potentially need a split to determine if we need a split
467+ // if we do need it we need to compute where to split the parentNode
468+ }
439469 }
440470 // insert terminal node
441471 CompletionTrie_AddChild (root , parentNode , "" , 0 );
@@ -526,9 +556,10 @@ void CompletionTrie_PrintRanges(completion_trie_root_t* self)
526556}
527557#endif
528558
529- void CompletionTrie_PrintTrie (completion_trie_root_t * self , uint32_t n )
559+ void CompletionTrie_PrintTrie (completion_trie_root_t * self , const completion_trie_viz_params_t params )
530560{
531561 char fname [32 ] = "g.dot" ;
562+ int n = params .FrameNumber ;
532563 if (n != 0 )
533564 {
534565 snprintf (fname , sizeof (fname ), "g%u.dot" , n );
@@ -538,17 +569,18 @@ void CompletionTrie_PrintTrie(completion_trie_root_t* self, uint32_t n)
538569 fprintf (f , "digraph G {\n" );
539570 fprintf (f , " node [shape=record headport=n]\n" );
540571
541- CompletionTrie_Print (self , 0 , "" , f );
572+ CompletionTrie_Print (self , 0 , "" , f , & params );
542573
543574 fprintf (f , "}\n" );
544575 fclose (f );
545576 RESTORE_STACK ();
546577}
547578
548- void CompletionTrie_PrintStats (completion_trie_root_t * self , uint32_t n )
579+ void CompletionTrie_PrintStats (completion_trie_root_t * self , uint16_t n )
549580{
550581
551- CompletionTrie_PrintTrie (self , n );
582+ completion_trie_viz_params_t params = {.FrameNumber = n };
583+ CompletionTrie_PrintTrie (self , params );
552584
553585 printf ("UsedNodes: %u\n" , self -> TotalNodes );
554586 printf ("AllocatedNodes: %u\n" , self -> NodesCount );
0 commit comments