From bb930a7d32d4c26d6c43e219583efeca211392e9 Mon Sep 17 00:00:00 2001
From: frederik stehli <frederik.stehli@udo.edu>
Date: Tue, 10 Jul 2018 18:18:11 +0200
Subject: [PATCH] [min_max] finished bwd search ... hopefully

---
 src/datastructures/min_max.rs | 34 ++++++++++++++++++++++++++++++----
 1 file changed, 30 insertions(+), 4 deletions(-)

diff --git a/src/datastructures/min_max.rs b/src/datastructures/min_max.rs
index 0cba460..d09f53e 100644
--- a/src/datastructures/min_max.rs
+++ b/src/datastructures/min_max.rs
@@ -305,6 +305,7 @@ impl MinMax {
             let mut look_for = diff + index_excess - current_excess;
             let mut bottom_up = true;
             let mut top_down = false;
+            let mut block_search = false;
 
             while bottom_up && current_node > 0 {
                 if current_node % 2 == 0 {
@@ -332,15 +333,41 @@ impl MinMax {
                     && self.heap[current_node as usize * 2 + 1].min_excess <= look_for
                 {
                     current_node = current_node * 2 + 1;
+                } else {
+                    //todo konnte nicht gefunden werden!!
                 }
 
                 if current_node < self.heap.len() as u64 / 2 {
                     top_down = false;
+                    block_search = true;
                 }
             }
-        }
 
-        Ok(1)
+            if block_search {
+                block_no = current_node - (self.heap.len() / 2) as u64;
+                begin_of_block = block_no * self.block_size;
+                end_of_block = begin_of_block + self.block_size - 1;
+                position = end_of_block;
+                while !found && position >= end_of_block {
+                    if self.bits[position + 1] {
+                        look_for -= 1;
+                    } else {
+                        look_for += 1;
+                    }
+                    if look_for == 0 {
+                        found = true;
+                    } else {
+                        position -= 1
+                    }
+                }
+            }
+        }
+        if found {
+            Ok(position)
+        } else {
+            //todo konnte nicht gefunden werden!!
+            Ok(1)
+        }
     }
 
     pub fn find_close(&self, index: u64) -> Result<u64, NodeError> {
@@ -509,12 +536,11 @@ mod tests {
     }
 
     #[test]
-    #[ignore]
     fn test_bwd_search() {
         let bits =
             bit_vec![true, true, true, false, true, false, false, true, true, false, false, false];
         let min_max = MinMax::new(bits, 4);
-        assert_eq!(min_max.bwd_search(0, 0).unwrap(), 11);
+        assert_eq!(min_max.bwd_search(7, 1).unwrap(), 4);
     }
 
     #[test]
-- 
GitLab