//TODO: clear s public Associated_structure_node <C_Data> assoc_binary_search(float i) { Associated_structure_node <C_Data> s = new Associated_structure_node <C_Data>(i); int index = assoc_array.BinarySearch(s); if (index < 0) { index = ~index; } return(assoc_array[index]); }
public void report_structure(Associated_structure_node <C_Data> assoc_v, List <C_Data> result2, float y_2) { int index = assoc_v.index; while (index != assoc_array.Count && assoc_array[index].data.get_coordinate(1) <= y_2) { result2.Add(assoc_array[index].data); index++; } }
public void put_frac_casc(int node, Associated_structure_node <C_Data> frac_node, bool left) { if (left) { assoc_array[node].leftstructure = frac_node; //assoc_array[node].leftstructure_index = index; } else { assoc_array[node].rightstructure = frac_node; //assoc_array[node].rightstructure_index = index; } }
public int CompareTo(Associated_structure_node <C_Data> other) { return(this.data.get_coordinate(1).CompareTo(other.data.get_coordinate(1))); }
// performs a range query in the last tree public void range_query(C_Data from, C_Data to, int d, List <C_Data> result) { float x_1 = from.get_coordinate(d); float x_2 = to.get_coordinate(d); float y_1 = from.get_coordinate(d - 1); float y_2 = to.get_coordinate(d - 1); int split = find_split_node(x_1, x_2); var assoc_split = main_tree[split].substructure.assoc_binary_search(y_1); if (assoc_split.index != main_tree[split].substructure.get_end()) { //the answer of binary search is inside the index Associated_structure_node <C_Data> assoc_v = assoc_split; if (is_leaf(split)) { if (x_1 <= main_tree[split].data && main_tree[split].data <= x_2) { main_tree[split].substructure.report_structure(assoc_v, result, y_2); } } else { //left path int v = left_child(split); assoc_v = assoc_split; if (assoc_v.leftstructure != null) { assoc_v = assoc_v.leftstructure; } while (!is_leaf(v)) { if (x_1 <= main_tree[v].data) { if (assoc_v.rightstructure != null) { main_tree[right_child(v)].substructure. report_structure(assoc_v.rightstructure, result, y_2); } v = left_child(v); if (assoc_v.leftstructure != null) { assoc_v = assoc_v.leftstructure; } } else { v = right_child(v); if (assoc_v.rightstructure != null) { assoc_v = assoc_v.rightstructure; } } } if (x_1 <= main_tree[v].data && main_tree[v].data <= x_2) { main_tree[v].substructure.report_structure(assoc_v, result, y_2); } //right path v = right_child(split); assoc_v = assoc_split; if (assoc_v.rightstructure != null) { assoc_v = assoc_v.rightstructure; } while (!is_leaf(v)) { if (main_tree[v].data <= x_2) { if (assoc_v.leftstructure != null) { main_tree[left_child(v)].substructure. report_structure(assoc_v.leftstructure, result, y_2); } v = right_child(v); if (assoc_v.rightstructure != null) { assoc_v = assoc_v.rightstructure; } } else { v = left_child(v); if (assoc_v.leftstructure != null) { assoc_v = assoc_v.leftstructure; } } } if (x_1 <= main_tree[v].data && main_tree[v].data <= x_2) { main_tree[v].substructure.report_structure(assoc_v, result, y_2); } }//else } else { System.Console.WriteLine("error: binary search out of borders"); } }//range_query