77//! enabling precise identification of changed nodes without full reprocessing.
88
99use std:: collections:: HashMap ;
10- use std:: hash:: { Hash , Hasher } ;
1110use std:: path:: Path ;
1211use std:: time:: SystemTime ;
1312
@@ -208,17 +207,10 @@ impl ChangeDetector {
208207 self
209208 }
210209
211- /// Compute hash of content (simple u64 hash).
212- fn hash_content ( content : & str ) -> u64 {
213- let mut hasher = std:: collections:: hash_map:: DefaultHasher :: new ( ) ;
214- content. hash ( & mut hasher) ;
215- hasher. finish ( )
216- }
217-
218- /// Check if a file needs reindexing based on mtime.
219- pub fn needs_reindex_by_mtime ( & self , doc_id : & str , path : & Path ) -> bool {
210+ /// Check if a file needs recompilation based on mtime.
211+ pub fn needs_recompile_by_mtime ( & self , doc_id : & str , path : & Path ) -> bool {
220212 let Some ( recorded_mtime) = self . mtimes . get ( doc_id) else {
221- return true ; // Never indexed
213+ return true ; // Never compiled
222214 } ;
223215
224216 let Ok ( metadata) = std:: fs:: metadata ( path) else {
@@ -232,8 +224,8 @@ impl ChangeDetector {
232224 current_mtime > * recorded_mtime
233225 }
234226
235- /// Check if content needs reindexing based on fingerprint.
236- pub fn needs_reindex_by_hash ( & self , doc_id : & str , content : & str ) -> bool {
227+ /// Check if content needs recompilation based on fingerprint.
228+ pub fn needs_recompile_by_hash ( & self , doc_id : & str , content : & str ) -> bool {
237229 let current_fp = Fingerprint :: from_str ( content) ;
238230
239231 match self . content_fps . get ( doc_id) {
@@ -242,23 +234,23 @@ impl ChangeDetector {
242234 }
243235 }
244236
245- /// Check if document needs reindexing based on fingerprint.
246- pub fn needs_reindex_by_fingerprint ( & self , doc_id : & str , new_fp : & Fingerprint ) -> bool {
237+ /// Check if document needs recompilation based on fingerprint.
238+ pub fn needs_recompile_by_fingerprint ( & self , doc_id : & str , new_fp : & Fingerprint ) -> bool {
247239 match self . content_fps . get ( doc_id) {
248240 Some ( recorded_fp) => recorded_fp != new_fp,
249241 None => true ,
250242 }
251243 }
252244
253245 /// Check if processing version has changed.
254- pub fn needs_reindex_by_version ( & self , doc_id : & str ) -> bool {
246+ pub fn needs_recompile_by_version ( & self , doc_id : & str ) -> bool {
255247 match self . processing_versions . get ( doc_id) {
256248 Some ( recorded_version) => * recorded_version < self . current_processing_version ,
257249 None => true ,
258250 }
259251 }
260252
261- /// Record document state after indexing .
253+ /// Record document state after compiling .
262254 pub fn record ( & mut self , doc_id : & str , content : & str , path : Option < & Path > ) {
263255 self . record_with_tree ( doc_id, content, None , path) ;
264256 }
@@ -415,7 +407,7 @@ impl ChangeDetector {
415407 let mut needs_reprocess = Vec :: new ( ) ;
416408
417409 // If processing version changed, all nodes need reprocessing
418- if self . needs_reindex_by_version ( doc_id) {
410+ if self . needs_recompile_by_version ( doc_id) {
419411 return Some ( new_fps. keys ( ) . cloned ( ) . collect ( ) ) ;
420412 }
421413
@@ -501,20 +493,6 @@ pub fn compute_tree_fingerprint(tree: &DocumentTree) -> Fingerprint {
501493 root_fp. subtree
502494}
503495
504- /// Compute content fingerprint for a single node.
505- fn compute_node_content_fp ( tree : & DocumentTree , node_id : NodeId ) -> Fingerprint {
506- let node = match tree. get ( node_id) {
507- Some ( n) => n,
508- None => return Fingerprint :: zero ( ) ,
509- } ;
510-
511- Fingerprinter :: new ( )
512- . with_str ( & node. title )
513- . with_str ( & node. content )
514- . with_option_str ( node. node_id . as_deref ( ) )
515- . into_fingerprint ( )
516- }
517-
518496/// Compute fingerprint for a node and its subtree.
519497fn compute_node_fingerprint ( tree : & DocumentTree , node_id : NodeId ) -> NodeFingerprint {
520498 let node = match tree. get ( node_id) {
@@ -578,20 +556,20 @@ mod tests {
578556 }
579557
580558 #[ test]
581- fn test_needs_reindex_by_hash ( ) {
559+ fn test_needs_recompile_by_hash ( ) {
582560 let mut detector = ChangeDetector :: new ( ) ;
583561
584- // First time: always needs reindex
585- assert ! ( detector. needs_reindex_by_hash ( "doc1" , "content" ) ) ;
562+ // First time: always needs recompilation
563+ assert ! ( detector. needs_recompile_by_hash ( "doc1" , "content" ) ) ;
586564
587565 // Record the content
588566 detector. record ( "doc1" , "content" , None ) ;
589567
590- // Same content: no reindex needed
591- assert ! ( !detector. needs_reindex_by_hash ( "doc1" , "content" ) ) ;
568+ // Same content: no recompilation needed
569+ assert ! ( !detector. needs_recompile_by_hash ( "doc1" , "content" ) ) ;
592570
593- // Different content: needs reindex
594- assert ! ( detector. needs_reindex_by_hash ( "doc1" , "new content" ) ) ;
571+ // Different content: needs recompilation
572+ assert ! ( detector. needs_recompile_by_hash ( "doc1" , "new content" ) ) ;
595573 }
596574
597575 #[ test]
@@ -614,12 +592,12 @@ mod tests {
614592 let mut detector = ChangeDetector :: new ( ) . with_processing_version ( 2 ) ;
615593 detector. record ( "doc1" , "content" , None ) ;
616594
617- // Version matches, no reindex needed
618- assert ! ( !detector. needs_reindex_by_version ( "doc1" ) ) ;
595+ // Version matches, no recompilation needed
596+ assert ! ( !detector. needs_recompile_by_version ( "doc1" ) ) ;
619597
620598 // Create new detector with higher version
621599 let detector2 = ChangeDetector :: new ( ) . with_processing_version ( 3 ) ;
622- assert ! ( detector2. needs_reindex_by_version ( "doc1" ) ) ;
600+ assert ! ( detector2. needs_recompile_by_version ( "doc1" ) ) ;
623601 }
624602
625603 #[ test]
0 commit comments