##// END OF EJS Templates
rust-nodemap: a method for full invalidation...
Georges Racinet -
r44874:d5189943 default
parent child Browse files
Show More
@@ -575,11 +575,25 b' impl NodeTree {'
575 575 Ok(())
576 576 }
577 577
578 /// Make the whole `NodeTree` logically empty, without touching the
579 /// immutable part.
580 pub fn invalidate_all(&mut self) {
581 self.root = Block::new();
582 self.growable = Vec::new();
583 self.masked_inner_blocks = self.readonly.len();
584 }
585
578 586 /// Return the number of blocks in the readonly part that are currently
579 587 /// masked in the mutable part.
580 588 ///
581 589 /// The `NodeTree` structure has no efficient way to know how many blocks
582 590 /// are already unreachable in the readonly part.
591 ///
592 /// After a call to `invalidate_all()`, the returned number can be actually
593 /// bigger than the whole readonly part, a conventional way to mean that
594 /// all the readonly blocks have been masked. This is what is really
595 /// useful to the caller and does not require to know how many were
596 /// actually unreachable to begin with.
583 597 pub fn masked_readonly_blocks(&self) -> usize {
584 598 if let Some(readonly_root) = self.readonly.last() {
585 599 if readonly_root == &self.root {
@@ -1060,6 +1074,27 b' mod tests {'
1060 1074 }
1061 1075
1062 1076 #[test]
1077 fn test_invalidate_all() -> Result<(), NodeMapError> {
1078 let mut idx = TestNtIndex::new();
1079 idx.insert(0, "1234")?;
1080 idx.insert(1, "1235")?;
1081 idx.insert(2, "131")?;
1082 idx.insert(3, "cafe")?;
1083 let mut idx = idx.commit();
1084
1085 idx.nt.invalidate_all();
1086
1087 assert_eq!(idx.find_hex("1234")?, None);
1088 assert_eq!(idx.find_hex("1235")?, None);
1089 assert_eq!(idx.find_hex("131")?, None);
1090 assert_eq!(idx.find_hex("cafe")?, None);
1091 // all the readonly blocks have been masked, this is the
1092 // conventional expected response
1093 assert_eq!(idx.nt.masked_readonly_blocks(), idx.nt.readonly.len() + 1);
1094 Ok(())
1095 }
1096
1097 #[test]
1063 1098 fn test_into_added_empty() {
1064 1099 assert!(sample_nodetree().into_readonly_and_added().1.is_empty());
1065 1100 assert!(sample_nodetree()
General Comments 0
You need to be logged in to leave comments. Login now