How to use msB method in wpt

Best JavaScript code snippet using wpt

bitwise-filter-gen.js

Source:bitwise-filter-gen.js Github

copy

Full Screen

1/**2 * All the functions in this file will ONLY be used by the function subgraph.spliceCyclicOtherOptions_Bitwise 3*/4import { gridSideLen } from "../grid"5import { BITS_PER_SECTION, SECTIONS_PER_ROW, msb, clear_bit, } from "./bitwise-help-functions"6const floor = Math.floor7/******************************************************************************************************************************** */8// The folowing functions will be excuted when its more effiecent to compare 2 graphs by rows,, i.e. (gridSideLen is gt or eq to BITS_PER_SECTION)9// This means that to represent 1 row we need multiple sections,, unless (gridSideLen is eq to BITS_PER_SECTION) then its 1:110const get_left_shifted_filter_by_row = (this_path_mask, other_path_mask, section_index) => {11 let curr_section = this_path_mask[section_index - SECTIONS_PER_ROW]12 let other_curr_section = other_path_mask[section_index]13 let filter_mask = curr_section & other_curr_section14 return filter_mask15}16const get_right_shifted_filter_by_row = (this_path_mask, other_path_mask, section_index) => {17 let curr_section = this_path_mask[section_index + SECTIONS_PER_ROW]18 let other_curr_section = other_path_mask[section_index]19 let filter_mask = curr_section & other_curr_section20 return filter_mask21}22const calc_pivots_other_to_this_upper_wall_by_row = (row_index, _this, _other) => {23 //Left shifting the "this .path_mask[0]"24 // 15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00 ** ** ** ** ** ** ** ** <-- _this.subgraph been left-shifted added dummy first n bits in this subgraph 25 // 23 22 21 20 19 18 17 16 15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00 <-- OTHER IS CYCLIC26 let found = false27 let option = null28 let filters_upper_wall_arr = []29 for (let si = 0; si < SECTIONS_PER_ROW; si++) {30 let section_index = si + (row_index * SECTIONS_PER_ROW)31 let filter_upper_wall = get_left_shifted_filter_by_row(_this.path_mask, _other.path_mask, section_index)32 filters_upper_wall_arr.push(filter_upper_wall)33 }34 for (let si = filters_upper_wall_arr.length - 1; si >= 0 && !found; si--) {35 let filter_upper_wall = filters_upper_wall_arr[si];36 let section_index = si + (row_index * SECTIONS_PER_ROW)37 while (filter_upper_wall !== 0 && !found) {38 let msb_index = msb(filter_upper_wall)39 // add "(section_index * BITS_PER_SECTION )" to get the aqtual node value.40 let msb_node_value = msb_index + (section_index * BITS_PER_SECTION)41 let other_x = floor(msb_node_value / gridSideLen)42 let other_x_is_even = (other_x % 2) == 043 let other_root = other_x_is_even ? (msb_node_value - 1) : msb_node_value44 let other_leaf = other_x_is_even ? msb_node_value : (msb_node_value - 1)45 // since root.y is always even when connecteing with upper wall46 let other_root_y_is_even = other_root % 2 == 0 // this is eq to (msb_node_value % gridSideLen) % 2 == 047 let is_other_root_leaf_same_row = floor(other_leaf / gridSideLen) == floor(other_root / gridSideLen)48 if (is_other_root_leaf_same_row && other_root_y_is_even) {49 if (50 ((msb_index > 0) && (filter_upper_wall & (1 << (msb_index - 1))) != 0) || // if msb_index is gt 0, check if the adjecent bit is_set 51 ((msb_index == 0) && (filters_upper_wall_arr[si - 1] & (1 << (BITS_PER_SECTION - 1))) != 0) // if msb_index is eq 0, check if the (most_sig_bit in the next section) is_set,, this is to cover the case where the potential (root and leaf) are adjecent BUT mapped into diff sections52 ) {53 let connect_before_this_node = other_leaf - gridSideLen54 let insert_other_at_index = _this.getNodeLocalIndex(connect_before_this_node)55 let other_new_root_index = _other.getNodeLocalIndex(other_root)56 if (_this.isValidPivotIndex(insert_other_at_index) && _other.isValidPivotIndex(_other.getNodeLocalIndex(other_root))) { //57 option = Object.assign({}, Option)58 option.other_root = other_root59 option.other_leaf = other_leaf60 option.other_new_root_index = other_new_root_index61 option.insert_other_at_index = insert_other_at_index62 found = true63 // console.log(`other_root ${other_root} other_leaf ${other_leaf} connect_before_this_node ${connect_before_this_node} insert_other_at_index ${option.insert_other_at_index}`)64 }65 }66 filter_upper_wall = clear_bit(filter_upper_wall, msb_index)67 } else {68 filter_upper_wall = clear_bit(filter_upper_wall, msb_index)69 }70 }71 }72 return option73}74const calc_pivots_other_to_this_left_T_wall_by_row = (row_index, _this, _other) => {75 //Left shifting the "this .path_T_mask[0]"76 // 57 49 41 33 25 17 09 01 56 48 40 32 24 16 08 00 ** ** ** ** ** ** ** ** <-- _this.subgraph been left-shifted added dummy first n bits in this subgraph 77 // 58 50 42 34 26 18 10 02 57 49 41 33 25 17 09 01 56 48 40 32 24 16 08 00 <-- OTHER IS CYCLIC78 let found = false79 let option = null80 let filters_T_left_wall_arr = []81 for (let si = 0; si < SECTIONS_PER_ROW; si++) {82 let section_index = si + (row_index * SECTIONS_PER_ROW)83 let filter_T_left_wall = get_left_shifted_filter_by_row(_this.path_T_mask, _other.path_T_mask, section_index)84 filters_T_left_wall_arr.push(filter_T_left_wall)85 }86 for (let si = filters_T_left_wall_arr.length - 1; si >= 0 && !found; si--) {87 let filter_T_left_wall = filters_T_left_wall_arr[si];88 let section_index = si + (row_index * SECTIONS_PER_ROW)89 while (filter_T_left_wall !== 0 && !found) {90 /* if the node actaul value is 58, then msb_T_index is 23 */91 let msb_T_index = msb(filter_T_left_wall)92 // add "(section_index * BITS_PER_SECTION )" to get the T node value.93 /* if the node actaul value is 58, then msb_T_value is 23 = 23 + (0 * 24) */94 let msb_T_value = msb_T_index + (section_index * BITS_PER_SECTION)95 /* if the node actaul value is 58, then msb_T_x is 2 msb_T_x can has a range [0,2] iff the NR_OF_SECTIONS is 3*/96 let msb_T_x = floor(msb_T_value / gridSideLen)97 /* if the node actaul value is 58, then msb_T_y is 7 msb_T_y can has a range [0,7]*/98 let msb_T_y = (msb_T_value % gridSideLen)99 /* if the node actaul value is 58, then msb_node_value is 58 */100 let msb_node_value = msb_T_x + (msb_T_y * gridSideLen)101 // Note (other_T_x_is_even =>(23.x = 2)_is_even) is NOT eq to (msb_T_value_is_even => (23)_is_even), and also NOT eq to actaul node value (58)_is_even102 let other_T_x_is_even = (msb_T_x % 2) == 0103 /* if the node actaul value is 58, then other_root is 58 other_leaf is 50*/104 let other_root = other_T_x_is_even ? msb_node_value : (msb_node_value - gridSideLen)105 let other_leaf = other_T_x_is_even ? (msb_node_value - gridSideLen) : msb_node_value106 // since other_root.x is always odd when connecteing with left wall107 // Note (other_root_x_is_even =>(58.x)_is_even) is NOT eq to actaul node value (58)_is_even108 let other_root_x_is_even = (floor(other_root / gridSideLen)) % 2 == 0109 let is_other_root_leaf_same_col = ((other_root) % gridSideLen) == ((other_leaf) % gridSideLen)110 if (is_other_root_leaf_same_col && !other_root_x_is_even) {111 if (112 ((msb_T_index > 0) && (filter_T_left_wall & (1 << (msb_T_index - 1))) != 0) || // if msb_T_index is gt 0, check if the adjecent bit is_set 113 ((msb_T_index == 0) && (filters_T_left_wall_arr[si - 1] & (1 << (BITS_PER_SECTION - 1))) != 0) // if msb_T_index is eq 0, check if the (most_sig_bit in the next section) is_set,, this is to cover the case where the potential (root and leaf) are adjecent BUT mapped into diff sections114 ) {115 let connect_before_this_node = other_leaf - 1116 let other_new_root_index = _other.getNodeLocalIndex(other_root)117 let insert_other_at_index = _this.getNodeLocalIndex(connect_before_this_node)118 if (_this.isValidPivotIndex(insert_other_at_index) && _other.isValidPivotIndex(_other.getNodeLocalIndex(other_root))) { //119 option = Object.assign({}, Option)120 option.other_root = other_root121 option.other_leaf = other_leaf122 option.other_new_root_index = other_new_root_index123 option.insert_other_at_index = insert_other_at_index124 found = true125 }126 }127 filter_T_left_wall = clear_bit(filter_T_left_wall, msb_T_index)128 } else {129 filter_T_left_wall = clear_bit(filter_T_left_wall, msb_T_index)130 }131 }132 }133 return option134}135const calc_pivots_other_to_this_lower_wall_by_row = (row_index, _this, _other) => {136 // Right shifting the "this .path_mask[0]"137 // 15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00 <-- OTHER IS CYCLIC138 // 23 22 21 20 19 18 17 16 15 14 13 12 11 10 09 08 <-- _this.subgraph been right-shifted ignoring first n bits in this subgraph 139 let found = false140 let option = null141 let filters_lower_wall_arr = []142 for (let si = 0; si < SECTIONS_PER_ROW; si++) {143 let section_index = si + (row_index * SECTIONS_PER_ROW)144 let filter_lower_wall = get_right_shifted_filter_by_row(_this.path_mask, _other.path_mask, section_index)145 filters_lower_wall_arr.push(filter_lower_wall)146 }147 for (let si = filters_lower_wall_arr.length - 1; si >= 0 && !found; si--) {148 let filter_lower_wall = filters_lower_wall_arr[si];149 let section_index = si + (row_index * SECTIONS_PER_ROW)150 while (filter_lower_wall !== 0 && !found) {151 let msb_index = msb(filter_lower_wall)152 // add "(section_index * BITS_PER_SECTION )" to get the aqtual node value.153 let msb_node_value = msb_index + (section_index * BITS_PER_SECTION)154 let other_x = floor(msb_node_value / gridSideLen)155 let other_x_is_even = (other_x % 2) == 0156 let other_root = other_x_is_even ? (msb_node_value - 1) : msb_node_value157 let other_leaf = other_x_is_even ? msb_node_value : (msb_node_value - 1)158 // since root.y is always odd when connecteing with lower wall159 let other_root_y_is_even = other_root % 2 == 0 // this is eq to (msb_node_value % gridSideLen) % 2 == 0160 let is_other_root_leaf_same_row = floor(other_leaf / gridSideLen) == floor(other_root / gridSideLen)161 if (is_other_root_leaf_same_row && !other_root_y_is_even) {162 if (163 ((msb_index > 0) && (filter_lower_wall & (1 << (msb_index - 1))) != 0) || // if msb_index is gt 0, check if the adjecent bit is_set 164 ((msb_index == 0) && (filters_lower_wall_arr[si - 1] & (1 << (BITS_PER_SECTION - 1))) != 0) // if msb_index is eq 0, check if the (most_sig_bit in the next section) is_set,, this is to cover the case where the potential (root and leaf) are adjecent BUT mapped into diff sections165 ) {166 let connect_before_this_node = other_leaf + gridSideLen167 let other_new_root_index = _other.getNodeLocalIndex(other_root)168 let insert_other_at_index = _this.getNodeLocalIndex(connect_before_this_node)169 if (_this.isValidPivotIndex(insert_other_at_index) && _other.isValidPivotIndex(_other.getNodeLocalIndex(other_root))) { //170 option = Object.assign({}, Option)171 option.other_root = other_root172 option.other_leaf = other_leaf173 option.other_new_root_index = other_new_root_index174 option.insert_other_at_index = insert_other_at_index175 found = true176 }177 }178 filter_lower_wall = clear_bit(filter_lower_wall, msb_index)179 } else {180 filter_lower_wall = clear_bit(filter_lower_wall, msb_index)181 }182 }183 }184 return option185}186const calc_pivots_other_to_this_rigth_T_wall_by_row = (row_index, _this, _other) => {187 // right shifting the "this .path_T_mask[0]"188 // 57 49 41 33 25 17 09 01 56 48 40 32 24 16 08 00 <-- OTHER IS CYCLIC189 // 58 50 42 34 26 18 10 02 57 49 41 33 25 17 09 01 <-- _this.subgraph been right-shifted added dummy first n bits in this subgraph 190 let found = false191 let option = null192 let filters_T_right_wall_arr = []193 for (let si = 0; si < SECTIONS_PER_ROW; si++) {194 let section_index = si + (row_index * SECTIONS_PER_ROW)195 let filter_T_right_wall = get_right_shifted_filter_by_row(_this.path_T_mask, _other.path_T_mask, section_index)196 filters_T_right_wall_arr.push(filter_T_right_wall)197 }198 for (let si = filters_T_right_wall_arr.length - 1; si >= 0 && !found; si--) {199 let filter_T_right_wall = filters_T_right_wall_arr[si];200 let section_index = si + (row_index * SECTIONS_PER_ROW)201 while (filter_T_right_wall !== 0 && !found) {202 /* if the node actaul value is 58, then msb_T_index is 23 */203 let msb_T_index = msb(filter_T_right_wall)204 // add "(section_index * BITS_PER_SECTION )" to get the Transposed node value.205 /* if the node actaul value is 58, then msb_T_value is 23 = 23 + (0 * 24) */206 let msb_T_value = msb_T_index + (section_index * BITS_PER_SECTION)207 /* if the node actaul value is 58, then msb_T_x is 2 msb_T_x can has a range [0,2] iff the NR_OF_SECTIONS is 3*/208 let msb_T_x = floor(msb_T_value / gridSideLen)209 /* if the node actaul value is 58, then msb_T_y is 7 msb_T_y can has a range [0,7]*/210 let msb_T_y = (msb_T_value % gridSideLen)211 /* if the node actaul value is 58, then msb_node_value is 58 */212 let msb_node_value = msb_T_x + (msb_T_y * gridSideLen)213 // Note (other_T_x_is_even =>(23.x = 2)_is_even) is NOT eq to (msb_T_value_is_even => (23)_is_even), and also NOT eq to actaul node value (58)_is_even214 let other_T_x_is_even = (msb_T_x % 2) == 0215 /* if the node actaul value is 58, then other_root is 58 other_leaf is 50*/216 let other_root = other_T_x_is_even ? msb_node_value : (msb_node_value - gridSideLen)217 let other_leaf = other_T_x_is_even ? (msb_node_value - gridSideLen) : msb_node_value218 // since other_root.x is always even when connecteing with right wall219 // Note (other_root_x_is_even =>(58.x)_is_even) is NOT eq to actaul node value (58)_is_even220 let other_root_x_is_even = (floor(other_root / gridSideLen)) % 2 == 0221 let is_other_root_leaf_same_col = ((other_root) % gridSideLen) == ((other_leaf) % gridSideLen)222 if (is_other_root_leaf_same_col && other_root_x_is_even) {223 if (224 ((msb_T_index > 0) && (filter_T_right_wall & (1 << (msb_T_index - 1))) != 0) || // if msb_T_index is gt 0, check if the adjecent bit is_set 225 ((msb_T_index == 0) && (filters_T_right_wall_arr[si - 1] & (1 << (BITS_PER_SECTION - 1))) != 0) // if msb_T_index is eq 0, check if the (most_sig_bit in the next section) is_set,, this is to cover the case where the potential (root and leaf) are adjecent BUT mapped into diff sections226 ) {227 let connect_before_this_node = other_leaf + 1228 let other_new_root_index = _other.getNodeLocalIndex(other_root)229 let insert_other_at_index = _this.getNodeLocalIndex(connect_before_this_node)230 if (_this.isValidPivotIndex(insert_other_at_index) && _other.isValidPivotIndex(_other.getNodeLocalIndex(other_root))) { //231 option = Object.assign({}, Option)232 option.other_root = other_root233 option.other_leaf = other_leaf234 option.other_new_root_index = other_new_root_index235 option.insert_other_at_index = insert_other_at_index236 found = true237 }238 }239 filter_T_right_wall = clear_bit(filter_T_right_wall, msb_T_index)240 } else {241 filter_T_right_wall = clear_bit(filter_T_right_wall, msb_T_index)242 }243 }244 }245 return option246}247/******************************************************************************************************************************** */248/******************************************************************************************************************************** */249// The folowing functions will be excuted when its more effiecent to compare 2 graphs by section,, i.e. (gridSideLen is lt BITS_PER_SECTION)250// This means that to ONLY one section can represent multiple rows251const get_left_shifted_filter_by_section = (this_path_mask, other_path_mask, section_index) => {252 /**253 * To connenct other_path to the this left wall , the comparing should start from (2nd col in the "other_T_" subgraph) and (fst col of "this_T_" subgraph), 254 * which means the fst n-th bits in the "other.path_T_mask" should be ignored.255 * 256 * This could either be accoumplished via shifting either:257 * - left shifting "this .path_T_mask[i]" by n bits, and copying the last n-bits from "this. path_T_mask[i-1]", where i = [0, BITS_PER_SECTION> and n = gridSideLen. OR,258 * - right shifting "other.path_T_mask[i]" by n bits, and copying the fst n-bits from "other.path_T_mask[i+1]", where i = [0, BITS_PER_SECTION> and n = gridSideLen.259 * 260 * Left shifting the "this .path_T_mask[0]"261 // 57 49 41 33 25 17 09 01 56 48 40 32 24 16 08 00 ** ** ** ** ** ** ** ** <-- this.subgraph been left-shifted added dummy first n bits in this subgraph 262 // 58 50 42 34 26 18 10 02 57 49 41 33 25 17 09 01 56 48 40 32 24 16 08 00 <-- OTHER IS CYCLIC263 */264 /**265 * To connenct other_path to the this upper wall , the comparing should start from (2nd row in the "other" subgraph) and (fst row of "this" subgraph), 266 * which means the fst n-th bits in the "other" subgraph should be ignored.267 * 268 * This could either be accoumplished via shifting either:269 * - left shifting "this .path_mask[i]" by n bits, and copying the last n-bits from "this. path_mask[i-1]", where i = [0, BITS_PER_SECTION> and n = gridSideLen. OR,270 * - right shifting "other.path_mask[i]" by n bits, and copying the fst n-bits from "other.path_mask[i+1]", where i = [0, BITS_PER_SECTION> and n = gridSideLen.271 * 272 * Left shifting the "this .path_mask[0]"273 // 15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00 ** ** ** ** ** ** ** ** <-- this.subgraph been left-shifted added dummy first n bits in this subgraph 274 // 23 22 21 20 19 18 17 16 15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00 <-- OTHER IS CYCLIC275 */276 // console.log(`\n\n\n\n *************section_index ${section_index}*********************`)277 let curr_section = this_path_mask[section_index]278 let prev_section = this_path_mask[section_index - 1]279 let prev_n_bits = prev_section ? (prev_section >>> (BITS_PER_SECTION - gridSideLen)) : 0280 // printBinString(curr_section, "curr_section")281 // printBinString(prev_n_bits, "prev_n_bits")282 let curr_section_shifted = (curr_section & ((1 << (BITS_PER_SECTION - gridSideLen)) - 1)) << gridSideLen283 curr_section_shifted |= prev_n_bits284 // printBinString(curr_section_shifted, "curr_section_shifted")285 let other_curr_section = other_path_mask[section_index]286 // printBinString(other_curr_section, "other_curr_section")287 let filter_mask = curr_section_shifted & other_curr_section288 // printBinString(filter_mask, "filter_mask")289 return filter_mask290}291const get_right_shifted_filter_by_section = (this_path_mask, other_path_mask, section_index) => {292 /**293 * To connenct other_path to the this lower wall, the comparing should start from (2nd row in the "this" subgraph) and (fst row of "other" subgraph), 294 * which means the fst n-th bits in the "this" subgraph should be ignored.295 * 296 * This could either be accoumplished via shifting either:297 * - left shifting "other.path_mask[i]" by n bits, and copying the last n-bits from "other.path_mask[i-1]", where i = [0, BITS_PER_SECTION> and n = gridSideLen. OR,298 * - right shifting "this .path_mask[i]" by n bits, and copying the fst n-bits from "this .path_mask[i+1]", where i = [0, BITS_PER_SECTION> and n = gridSideLen.299 * 300 * Right shifting the "this .path_mask[0]"301 15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00 <-- OTHER IS CYCLIC302 23 22 21 20 19 18 17 16 15 14 13 12 11 10 09 08 <-- this.subgraph been right-shifted ignoring first n bits in this subgraph 303 */304 /**305 * To connenct other_path to the this right wall, the comparing should start from (2nd col in the "other" subgraph) and (fst col of "this" subgraph), 306 * which means the fst n-th bits in the "other.path_T_mask" should be ignored.307 * 308 * This could either be accoumplished via shifting either:309 * - left shifting "other.path_T_mask[i]" by n bits, and copying the last n-bits from "other.path_T_mask[i-1]", where i = [0, BITS_PER_SECTION> and n = gridSideLen. OR,310 * - right shifting "this. path_T_mask[i]" by n bits, and copying the fst n-bits from "this. path_T_mask[i+1]", where i = [0, BITS_PER_SECTION> and n = gridSideLen.311 * 312 * right shifting the "this .path_T_mask[0]"313 57 49 41 33 25 17 09 01 56 48 40 32 24 16 08 00 <-- OTHER IS CYCLIC314 58 50 42 34 26 18 10 02 57 49 41 33 25 17 09 01 <-- this.subgraph been right-shifted added dummy first n bits in this subgraph 315 */316 // console.log(`\n\n\n\n *************section_index ${section_index}*********************`)317 let curr_section = this_path_mask[section_index]318 let next_section = this_path_mask[section_index + 1]319 let next_n_bits = next_section ? (next_section & ((1 << gridSideLen) - 1)) : 0320 // printBinString(curr_section, "curr_section")321 // printBinString(next_n_bits, "next_n_bits")322 let curr_section_shifted = curr_section >>> gridSideLen323 curr_section_shifted |= (next_n_bits << (BITS_PER_SECTION - gridSideLen))324 // printBinString(curr_section_shifted, "curr_section_shifted")325 let other_curr_section = other_path_mask[section_index]326 // printBinString(other_curr_section, "other_curr_section")327 let filter_mask = curr_section_shifted & other_curr_section328 // printBinString(filter_mask, "filter_mask")329 return filter_mask330}331const calc_pivots_other_to_this_upper_wall_by_section = (section_index, _this, _other) => {332 //Left shifting the "this .path_mask[0]"333 // 15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00 ** ** ** ** ** ** ** ** <-- _this.subgraph been left-shifted added dummy first n bits in this subgraph 334 // 23 22 21 20 19 18 17 16 15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00 <-- OTHER IS CYCLIC335 let found = false336 let option = null337 let filter_upper_wall = get_left_shifted_filter_by_section(_this.path_mask, _other.path_mask, section_index)338 while (filter_upper_wall !== 0 && !found) {339 let msb_index = msb(filter_upper_wall)340 // add "(section_index * BITS_PER_SECTION )" to get the aqtual node value.341 let msb_node_value = msb_index + (section_index * BITS_PER_SECTION)342 let other_x = floor(msb_node_value / gridSideLen)343 let other_x_is_even = (other_x % 2) == 0344 let other_root = other_x_is_even ? (msb_node_value - 1) : msb_node_value345 let other_leaf = other_x_is_even ? msb_node_value : (msb_node_value - 1)346 // since root.y is always even when connecteing with upper wall347 let other_root_y_is_even = other_root % 2 == 0 // this is eq to (msb_node_value % gridSideLen) % 2 == 0348 let is_other_root_leaf_same_row = floor(other_leaf / gridSideLen) == floor(other_root / gridSideLen)349 if (is_other_root_leaf_same_row && other_root_y_is_even) {350 if ((msb_index - 1) >= 0 && (filter_upper_wall & (1 << (msb_index - 1))) != 0) { // important: (msb_index - 1) >= 0, since 1<<(-1) is the same as 1<<7 if the mask leng is 8351 let connect_before_this_node = other_leaf - gridSideLen352 let insert_other_at_index = _this.getNodeLocalIndex(connect_before_this_node)353 let other_new_root_index = _other.getNodeLocalIndex(other_root)354 if (_this.isValidPivotIndex(insert_other_at_index) && _other.isValidPivotIndex(_other.getNodeLocalIndex(other_root))) { //355 option = Object.assign({}, Option)356 option.other_root = other_root357 option.other_leaf = other_leaf358 option.other_new_root_index = other_new_root_index359 option.insert_other_at_index = insert_other_at_index360 found = true361 // console.log(`other_root ${other_root} other_leaf ${other_leaf} connect_before_this_node ${connect_before_this_node} insert_other_at_index ${option.insert_other_at_index}`)362 }363 }364 filter_upper_wall = clear_bit(filter_upper_wall, msb_index)365 filter_upper_wall = clear_bit(filter_upper_wall, (msb_index - 1))366 } else {367 filter_upper_wall = clear_bit(filter_upper_wall, msb_index)368 }369 }370 return option371}372const calc_pivots_other_to_this_left_T_wall_by_section = (section_index, _this, _other) => {373 //Left shifting the "this .path_T_mask[0]"374 // 57 49 41 33 25 17 09 01 56 48 40 32 24 16 08 00 ** ** ** ** ** ** ** ** <-- this.subgraph been left-shifted added dummy first n bits in this subgraph 375 // 58 50 42 34 26 18 10 02 57 49 41 33 25 17 09 01 56 48 40 32 24 16 08 00 <-- OTHER IS CYCLIC376 let found = false377 let option = null378 let filter_T_left_wall = get_left_shifted_filter_by_section(_this.path_T_mask, _other.path_T_mask, section_index)379 while (filter_T_left_wall !== 0 && !found) {380 /* if the node actaul value is 58, then msb_T_index is 23 */381 let msb_T_index = msb(filter_T_left_wall)382 // add "(section_index * BITS_PER_SECTION )" to get the T node value.383 /* if the node actaul value is 58, then msb_T_value is 23 = 23 + (0 * 24) */384 let msb_T_value = msb_T_index + (section_index * BITS_PER_SECTION)385 /* if the node actaul value is 58, then msb_T_x is 2 msb_T_x can has a range [0,2] iff the NR_OF_SECTIONS is 3*/386 let msb_T_x = floor(msb_T_value / gridSideLen)387 /* if the node actaul value is 58, then msb_T_y is 7 msb_T_y can has a range [0,7]*/388 let msb_T_y = (msb_T_value % gridSideLen)389 /* if the node actaul value is 58, then msb_node_value is 58 */390 let msb_node_value = msb_T_x + (msb_T_y * gridSideLen)391 // Note (other_T_x_is_even =>(23.x = 2)_is_even) is NOT eq to (msb_T_value_is_even => (23)_is_even), and also NOT eq to actaul node value (58)_is_even392 let other_T_x_is_even = (msb_T_x % 2) == 0393 /* if the node actaul value is 58, then other_root is 58 other_leaf is 50*/394 let other_root = other_T_x_is_even ? msb_node_value : (msb_node_value - gridSideLen)395 let other_leaf = other_T_x_is_even ? (msb_node_value - gridSideLen) : msb_node_value396 // since other_root.x is always odd when connecteing with left wall397 // Note (other_root_x_is_even =>(58.x)_is_even) is NOT eq to actaul node value (58)_is_even398 let other_root_x_is_even = (floor(other_root / gridSideLen)) % 2 == 0399 let is_other_root_leaf_same_col = ((other_root) % gridSideLen) == ((other_leaf) % gridSideLen)400 if (is_other_root_leaf_same_col && !other_root_x_is_even) {401 if ((msb_T_index - 1) >= 0 && (filter_T_left_wall & (1 << (msb_T_index - 1))) != 0) { // important: (msb_T_index - 1) >= 0, since 1<<(-1) is the same as 1<<7 if the mask leng is 8402 let connect_before_this_node = other_leaf - 1403 let other_new_root_index = _other.getNodeLocalIndex(other_root)404 let insert_other_at_index = _this.getNodeLocalIndex(connect_before_this_node)405 if (_this.isValidPivotIndex(insert_other_at_index) && _other.isValidPivotIndex(_other.getNodeLocalIndex(other_root))) { //406 option = Object.assign({}, Option)407 option.other_root = other_root408 option.other_leaf = other_leaf409 option.other_new_root_index = other_new_root_index410 option.insert_other_at_index = insert_other_at_index411 found = true412 }413 }414 filter_T_left_wall = clear_bit(filter_T_left_wall, msb_T_index)415 filter_T_left_wall = clear_bit(filter_T_left_wall, (msb_T_index - 1))416 } else {417 filter_T_left_wall = clear_bit(filter_T_left_wall, msb_T_index)418 // printBinString(filter_T_left_wall)419 }420 }421 return option422}423const calc_pivots_other_to_this_lower_wall_by_section = (section_index, _this, _other) => {424 // Right shifting the "this .path_mask[0]"425 // 15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00 <-- OTHER IS CYCLIC426 // 23 22 21 20 19 18 17 16 15 14 13 12 11 10 09 08 <-- this.subgraph been right-shifted ignoring first n bits in this subgraph 427 let found = false428 let option = null429 let filter_lower_wall = get_right_shifted_filter_by_section(_this.path_mask, _other.path_mask, section_index)430 while (filter_lower_wall !== 0 && !found) {431 let msb_index = msb(filter_lower_wall)432 // add "(section_index * BITS_PER_SECTION )" to get the aqtual node value.433 let msb_node_value = msb_index + (section_index * BITS_PER_SECTION)434 let other_x = floor(msb_node_value / gridSideLen)435 let other_x_is_even = (other_x % 2) == 0436 let other_root = other_x_is_even ? (msb_node_value - 1) : msb_node_value437 let other_leaf = other_x_is_even ? msb_node_value : (msb_node_value - 1)438 // since root.y is always odd when connecteing with lower wall439 let other_root_y_is_even = other_root % 2 == 0 // this is eq to (msb_node_value % gridSideLen) % 2 == 0440 let is_other_root_leaf_same_row = floor(other_leaf / gridSideLen) == floor(other_root / gridSideLen)441 if (is_other_root_leaf_same_row && !other_root_y_is_even) {442 if ((msb_index - 1) >= 0 && (filter_lower_wall & (1 << (msb_index - 1))) != 0) { // important: (msb_index - 1) >= 0, since 1<<(-1) is the same as 1<<7 if the mask leng is 8443 let connect_before_this_node = other_leaf + gridSideLen444 let other_new_root_index = _other.getNodeLocalIndex(other_root)445 let insert_other_at_index = _this.getNodeLocalIndex(connect_before_this_node)446 if (_this.isValidPivotIndex(insert_other_at_index) && _other.isValidPivotIndex(_other.getNodeLocalIndex(other_root))) { //447 option = Object.assign({}, Option)448 option.other_root = other_root449 option.other_leaf = other_leaf450 option.other_new_root_index = other_new_root_index451 option.insert_other_at_index = insert_other_at_index452 found = true453 }454 }455 filter_lower_wall = clear_bit(filter_lower_wall, msb_index)456 filter_lower_wall = clear_bit(filter_lower_wall, (msb_index - 1))457 } else {458 filter_lower_wall = clear_bit(filter_lower_wall, msb_index)459 }460 }461 return option462}463const calc_pivots_other_to_this_rigth_T_wall_by_section = (section_index, _this, _other) => {464 // right shifting the "this .path_T_mask[0]"465 // 57 49 41 33 25 17 09 01 56 48 40 32 24 16 08 00 <-- OTHER IS CYCLIC466 // 58 50 42 34 26 18 10 02 57 49 41 33 25 17 09 01 <-- _this.subgraph been right-shifted added dummy first n bits in this subgraph 467 let found = false468 let option = null469 let filter_T_right_wall = get_right_shifted_filter_by_section(_this.path_T_mask, _other.path_T_mask, section_index)470 while (filter_T_right_wall !== 0 && !found) {471 /* if the node actaul value is 58, then msb_T_index is 23 */472 let msb_T_index = msb(filter_T_right_wall)473 // add "(section_index * BITS_PER_SECTION )" to get the Transposed node value.474 /* if the node actaul value is 58, then msb_T_value is 23 = 23 + (0 * 24) */475 let msb_T_value = msb_T_index + (section_index * BITS_PER_SECTION)476 /* if the node actaul value is 58, then msb_T_x is 2 msb_T_x can has a range [0,2] iff the NR_OF_SECTIONS is 3*/477 let msb_T_x = floor(msb_T_value / gridSideLen)478 /* if the node actaul value is 58, then msb_T_y is 7 msb_T_y can has a range [0,7]*/479 let msb_T_y = (msb_T_value % gridSideLen)480 /* if the node actaul value is 58, then msb_node_value is 58 */481 let msb_node_value = msb_T_x + (msb_T_y * gridSideLen)482 // Note (other_T_x_is_even =>(23.x = 2)_is_even) is NOT eq to (msb_T_value_is_even => (23)_is_even), and also NOT eq to actaul node value (58)_is_even483 let other_T_x_is_even = (msb_T_x % 2) == 0484 /* if the node actaul value is 58, then other_root is 58 other_leaf is 50*/485 let other_root = other_T_x_is_even ? msb_node_value : (msb_node_value - gridSideLen)486 let other_leaf = other_T_x_is_even ? (msb_node_value - gridSideLen) : msb_node_value487 // since other_root.x is always even when connecteing with right wall488 // Note (other_root_x_is_even =>(58.x)_is_even) is NOT eq to actaul node value (58)_is_even489 let other_root_x_is_even = (floor(other_root / gridSideLen)) % 2 == 0490 let is_other_root_leaf_same_col = ((other_root) % gridSideLen) == ((other_leaf) % gridSideLen)491 if (is_other_root_leaf_same_col && other_root_x_is_even) {492 if ((msb_T_index - 1) >= 0 && (filter_T_right_wall & (1 << (msb_T_index - 1))) != 0) { // important: (msb_T_index - 1) >= 0, since 1<<(-1) is the same as 1<<7 if the mask leng is 8493 let connect_before_this_node = other_leaf + 1494 let other_new_root_index = _other.getNodeLocalIndex(other_root)495 let insert_other_at_index = _this.getNodeLocalIndex(connect_before_this_node)496 if (_this.isValidPivotIndex(insert_other_at_index) && _other.isValidPivotIndex(_other.getNodeLocalIndex(other_root))) { //497 option = Object.assign({}, Option)498 option.other_root = other_root499 option.other_leaf = other_leaf500 option.other_new_root_index = other_new_root_index501 option.insert_other_at_index = insert_other_at_index502 found = true503 }504 }505 filter_T_right_wall = clear_bit(filter_T_right_wall, msb_T_index)506 filter_T_right_wall = clear_bit(filter_T_right_wall, (msb_T_index - 1))507 } else {508 filter_T_right_wall = clear_bit(filter_T_right_wall, msb_T_index)509 }510 }511 return option512}513/******************************************************************************************************************************** */514export {515 get_left_shifted_filter_by_row,516 get_right_shifted_filter_by_row,517 calc_pivots_other_to_this_upper_wall_by_row,518 calc_pivots_other_to_this_left_T_wall_by_row,519 calc_pivots_other_to_this_lower_wall_by_row,520 calc_pivots_other_to_this_rigth_T_wall_by_row,521 get_left_shifted_filter_by_section,522 get_right_shifted_filter_by_section,523 calc_pivots_other_to_this_upper_wall_by_section,524 calc_pivots_other_to_this_left_T_wall_by_section,525 calc_pivots_other_to_this_lower_wall_by_section,526 calc_pivots_other_to_this_rigth_T_wall_by_section,...

Full Screen

Full Screen

00-bitwise-test.js

Source:00-bitwise-test.js Github

copy

Full Screen

1import { gameBoardSideLen } from "../../grid"2const log = Math.log3const floor = Math.floor4const ceil = Math.ceil5let sl = 16while (((sl + 1) * gameBoardSideLen) < 30)7 sl += 18// BITS_PER_SECTION must be multiple of gameBoardSideLen and less than or eq 309const BITS_PER_SECTION = sl * gameBoardSideLen10const NR_OF_SECTIONS = ceil((gameBoardSideLen * gameBoardSideLen) / BITS_PER_SECTION)11const setBit = (n, indexToSet) => {12 return n | (1 << indexToSet)13}14const clear_bit = (nr, bit_index) => {15 // set bool = true to set the bit with index bit_index, or false to clear it16 nr ^= (-false ^ nr) & bit_index // this will set the specified bit if we use nr ^= (-true ^ nr) & bit_index17 return nr18}19const printBinString = (n, msg = "") => {20 // n must be between (-2^31) -2147483648 and ((2^31)-1) 214748364721 for (var nFlag = 0, nShifted = n, sMask = ""; nFlag < 32;22 nFlag++, sMask += String(nShifted >>> 31), nShifted <<= 1);23 console.log(`${msg} ${sMask}`)24}25const msb_u32 = (n) => {26 if (n <= 0) return NaN;27 // Remember that: this will return the mostSignificantBit positoin, where the indexing is Zero-based... i.e. msg(5) is 228 const bval = [0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4]29 let base = 0;30 if (n & 0xFFFF0000) { base += 32 / 2; n >>= 32 / 2; }31 if (n & 0x0000FF00) { base += 32 / 4; n >>= 32 / 4; }32 if (n & 0x000000F0) { base += 32 / 8; n >>= 32 / 8; }33 return (base + bval[n]) - 1; // to make the return value Zero-based index34}35const msb_u32_log = (n) => {36 // Remember that: this will return the mostSignificantBit positoin, where the indexing is Zero-based... i.e. msg(5) is 237 if (n <= 0) return NaN;38 return floor(log(n) / log(2));39}40const msb_u32_loop = (n) => {41 // Remember that: this will return the mostSignificantBit positoin, where the indexing is Zero-based... i.e. msg(5) is 242 if (n <= 0) return NaN43 let msb = 044 while (n > 0) {45 n >>>= 1;46 msb++47 }48 return msb - 149}50const largest_pow2_lte_u32_nr = (nr) => {51 // if nr is 1010, then this function will return 100052 if (nr <= 0) return 053 nr |= (nr >>> 1);54 nr |= (nr >>> 2);55 nr |= (nr >>> 4);56 nr |= (nr >>> 8);57 nr |= (nr >>> 16);58 nr++;59 nr >>>= 1;60 return nr61}62// let x = 563// printBinString(~x)64// x = setBit(x, 4)65// printBinString(128)66const is_path_contains_node = (path, node_value) => {67 let { section_indx, nr_of_shifts } = calc_index(node_value);68 console.log(section_indx + " " + nr_of_shifts)69 return (path[section_indx] & (1 << nr_of_shifts)) != 070}71// let arr = [0, 0, 0]72// let { section_indx, nr_of_shifts } = calc_index(80);73// arr[section_indx] |= (1 << nr_of_shifts)74// console.log(is_path_contains_node(arr, 80))75// arr.forEach(mask=> {76// printBinString(mask)})77const reverse_bits_order = (num) => {78 // reverse a given u32 79 // swap odd and even bits80 num = ((num >> 1) & 0x55555555) | ((num & 0x55555555) << 1);81 // swap consecutive pairs82 num = ((num >> 2) & 0x33333333) | ((num & 0x33333333) << 2);83 // swap nibbles ... 84 num = ((num >> 4) & 0x0F0F0F0F) | ((num & 0x0F0F0F0F) << 4);85 // swap bytes86 num = ((num >> 8) & 0x00FF00FF) | ((num & 0x00FF00FF) << 8);87 // swap 2-byte long pairs88 num = (num >> 16) | (num << 16);89 return num90}91const spliceCyclicOtherOptions_bitwise_v1 = () => {92 let g1 = [93 ['11111111'],94 ['11111111'],95 ['11111111'],96 ['11111111'],97 ['11111111'],98 ['11111111'],99 ['11111111'],100 ['11111111'],101 ]102 let other = [103 ['11111111'],104 ['11111111'],105 ['11111111'],106 ['11111111'],107 ['11111111'],108 ['11111111'],109 ['11111111'],110 ['11111111'],111 ]112 const walls = {113 UPPER: 'UPPER',114 LOWER: 'LOWER',115 LEFT: 'LEFT',116 RIGHT: 'RIGHT',117 }118 const option = {119 other_root: null,120 other_leaf: null,121 connect_before_this_node: null,122 }123 let res_options = {124 [walls.UPPER]: [],125 [walls.LOWER]: [],126 [walls.LEFT]: [],127 [walls.RIGHT]: [],128 }129 const upper_wall_calc = (other_row_index, other_x_is_even, found) => {130 let filter_upper_wall = parseInt(g1[other_row_index - 1], 2) & parseInt(other[other_row_index], 2)131 while (filter_upper_wall > 0 && !found) {132 let msb_index = msb_u32(filter_upper_wall)133 // console.log(`msb_index ${msb_index}`)134 let other_root_index = other_x_is_even ? (msb_index - 1) : msb_index135 let other_leaf_index = other_x_is_even ? msb_index : (msb_index - 1)136 // since root.y is always even when connecteing with upper wall137 let other_root_y_is_even = other_root_index % 2 == 0 // this is eq to (other_root_index % gameBoardSideLen) % 2 == 0138 if (other_root_y_is_even) {139 if ((msb_index - 1) >= 0 && (filter_upper_wall & (1 << (msb_index - 1))) != 0) { // important: (msb_index - 1) >= 0, since 1<<(-1) is the same as 1<<7 if the mask leng is 8140 // console.log(`other_root_index ${other_root_index}`)141 // console.log(`other_leaf_index ${other_leaf_index}`)142 let temp = Object.assign({}, option)143 temp.other_root = other_root_index + (other_row_index * gameBoardSideLen)144 temp.other_leaf = other_leaf_index + (other_row_index * gameBoardSideLen)145 temp.connect_before_this_node = (temp.other_leaf - gameBoardSideLen),146 // temp.other_root_y = other_root_index147 // temp.other_leaf_y = other_leaf_index148 res_options[walls.UPPER].push(temp)149 // console.log(`root ${temp.other_root}`)150 // console.log(`leaf ${temp.other_leaf}`)151 }152 filter_upper_wall = clear_bit(filter_upper_wall, 1 << other_root_index, false)153 filter_upper_wall = clear_bit(filter_upper_wall, 1 << other_leaf_index, false)154 } else {155 filter_upper_wall = clear_bit(filter_upper_wall, 1 << msb_index, false)156 // printBinString(filter_upper_wall)157 }158 }159 }160 const left_wall_calc = (other_T_row_index, other_T_x_is_even, found) => {161 let filter_T_left_wall = parseInt(g1[other_T_row_index - 1], 2) & parseInt(other[other_T_row_index], 2)162 while (filter_T_left_wall > 0 && !found) {163 let msb_index = msb_u32(filter_T_left_wall)164 // console.log(`msb_index ${msb_index}`)165 let other_T_root_index = other_T_x_is_even ? msb_index : (msb_index - 1)166 let other_T_leaf_index = other_T_x_is_even ? (msb_index - 1) : msb_index167 let other_T_root_y_is_even = other_T_root_index % 2 == 0 // this is eq to (floor( nodeValue / gameBoardSideLen )) % 2 == 0168 // since other_T_root_y is always odd when connecteing with left wall169 if (!other_T_root_y_is_even) {170 if ((msb_index - 1) >= 0 && (filter_T_left_wall & (1 << (msb_index - 1))) != 0) { // important: (msb_index - 1) >= 0, since 1<<(-1) is the same as 1<<7 if the mask leng is 8171 // console.log(`other_T_root_index ${other_T_root_index}`)172 // console.log(`other_T_leaf_index ${other_T_leaf_index}`)173 let temp = Object.assign({}, option)174 temp.other_root = other_T_row_index + (other_T_root_index * gameBoardSideLen)175 temp.other_leaf = other_T_row_index + (other_T_leaf_index * gameBoardSideLen)176 temp.connect_before_this_node = (temp.other_leaf - 1),177 // temp.other_root_y = other_T_root_index178 // temp.other_leaf_y = other_T_leaf_index179 res_options[walls.LEFT].push(temp)180 // console.log(`root ${temp.other_root}`)181 // console.log(`leaf ${temp.other_leaf}`)182 }183 filter_T_left_wall = clear_bit(filter_T_left_wall, 1 << other_T_root_index, false)184 filter_T_left_wall = clear_bit(filter_T_left_wall, 1 << other_T_leaf_index, false)185 } else {186 filter_T_left_wall = clear_bit(filter_T_left_wall, 1 << msb_index, false)187 // printBinString(filter_T_left_wall)188 }189 }190 }191 const lower_wall_calc = (other_row_index, other_x_is_even, found) => {192 let filter_lower_wall = parseInt(g1[other_row_index + 1], 2) & parseInt(other[other_row_index], 2)193 while (filter_lower_wall > 0 && !found) {194 let msb_index = msb_u32(filter_lower_wall)195 // console.log(`msb_index ${msb_index}`)196 let other_root_index = other_x_is_even ? (msb_index - 1) : msb_index197 let other_leaf_index = other_x_is_even ? msb_index : (msb_index - 1)198 let other_root_y_is_even = other_root_index % 2 == 0 // this is eq to (other_root_index % gameBoardSideLen) % 2 == 0199 // since root.y is always odd when connecteing with lower wall200 if (!other_root_y_is_even) {201 if ((msb_index - 1) >= 0 && (filter_lower_wall & (1 << (msb_index - 1))) != 0) { // important: (msb_index - 1) >= 0, since 1<<(-1) is the same as 1<<7 if the mask leng is 8202 // console.log(`other_root_index ${other_root_index}`)203 // console.log(`other_leaf_index ${other_leaf_index}`)204 let temp = Object.assign({}, option)205 temp.other_root = other_root_index + (other_row_index * gameBoardSideLen)206 temp.other_leaf = other_leaf_index + (other_row_index * gameBoardSideLen)207 temp.connect_before_this_node = (temp.other_leaf + gameBoardSideLen),208 // temp.other_root_y = other_root_index209 // temp.other_leaf_y = other_leaf_index210 res_options[walls.LOWER].push(temp)211 // console.log(`root ${temp.other_root}`)212 // console.log(`leaf ${temp.other_leaf}`)213 }214 filter_lower_wall = clear_bit(filter_lower_wall, 1 << other_root_index, false)215 filter_lower_wall = clear_bit(filter_lower_wall, 1 << other_leaf_index, false)216 } else {217 filter_lower_wall = clear_bit(filter_lower_wall, 1 << msb_index, false)218 // printBinString(filter_lower_wall)219 }220 }221 return found222 }223 const rigth_wall_calc = (other_T_row_index, other_T_x_is_even, found) => {224 let filter_T_rigth_wall = parseInt(g1[other_T_row_index + 1], 2) & parseInt(other[other_T_row_index], 2)225 while (filter_T_rigth_wall > 0 && !found) {226 let msb_index = msb_u32(filter_T_rigth_wall)227 // console.log(`msb_index ${msb_index}`)228 let other_T_root_index = other_T_x_is_even ? msb_index : (msb_index - 1)229 let other_T_leaf_index = other_T_x_is_even ? (msb_index - 1) : msb_index230 let other_T_root_y_is_even = other_T_root_index % 2 == 0 // this is eq to (floor( nodeValue / gameBoardSideLen )) % 2 == 0231 // since other_T_root_y is always even when connecteing with right wall232 if (other_T_root_y_is_even) {233 if ((msb_index - 1) >= 0 && (filter_T_rigth_wall & (1 << (msb_index - 1))) != 0) { // important: (msb_index - 1) >= 0, since 1<<(-1) is the same as 1<<7 if the mask leng is 8234 // console.log(`other_T_root_index ${other_T_root_index}`)235 // console.log(`other_T_leaf_index ${other_T_leaf_index}`)236 let temp = Object.assign({}, option)237 temp.other_root = other_T_row_index + (other_T_root_index * gameBoardSideLen)238 temp.other_leaf = other_T_row_index + (other_T_leaf_index * gameBoardSideLen)239 temp.connect_before_this_node = (temp.other_leaf - 1),240 // temp.other_root_y = other_T_root_index241 // temp.other_leaf_y = other_T_leaf_index242 res_options[walls.RIGHT].push(temp)243 // console.log(`root ${temp.other_root}`)244 // console.log(`leaf ${temp.other_leaf}`)245 }246 filter_T_rigth_wall = clear_bit(filter_T_rigth_wall, 1 << other_T_root_index, false)247 filter_T_rigth_wall = clear_bit(filter_T_rigth_wall, 1 << other_T_leaf_index, false)248 } else {249 filter_T_rigth_wall = clear_bit(filter_T_rigth_wall, 1 << msb_index, false)250 // printBinString(filter_T_rigth_wall)251 }252 }253 }254 let found = false255 for (let i = 1; i < (other.length - 1); i++) { // && !found256 let other_x_is_even = (i) % 2 == 0257 found = upper_wall_calc(i, other_x_is_even, found)258 found = left_wall_calc(i, other_x_is_even, found)259 found = lower_wall_calc(i, other_x_is_even, found)260 found = rigth_wall_calc(i, other_x_is_even, found)261 }262 console.log('walls.UPPER')263 res_options[walls.UPPER].forEach(op => console.log(op))264 console.log(`\n`)265 console.log('walls.LOWER')266 res_options[walls.LOWER].forEach(op => console.log(op))267 console.log(`\n`)268 console.log('walls.LEFT')269 res_options[walls.LEFT].forEach(op => console.log(op))270 console.log(`\n`)271 console.log('walls.RIGHT')272 res_options[walls.RIGHT].forEach(op => console.log(op))273}274const spliceCyclicOtherOptions_bitwise_v2 = () => {275 const calc_index = (node_value) => {276 // of the 64 bits of js number, we can only use 32 bits due to js number implementation, and that int is signed (Binary signed 2's complement).277 // If total nr of nodes is 8X8 = 64 nodes we need array with 2 int which have 32X2=64 bits,,278 // this is how the mask look like if we have max_usable_bits = 24 and totalNrOfCells = 64:279 // section_indx=0 section_indx=1280 // 23|..|05|04|03|02|01|00 46|...|27|26|25|24281 // to set bit (bit_to_set) = 50:282 // * section_indx = 50 / 24 = 2283 // * nr_of_shifts = 50 % 24 = 2284 // * a[section_indx] |= (1 << nr_of_shifts) ==> a[2] |= (1 << 2)285 let section_indx = floor(node_value / BITS_PER_SECTION);286 let nr_of_shifts = node_value % BITS_PER_SECTION;287 return { section_indx, nr_of_shifts }288 }289 const calc_T_index = (node_value) => {290 // of the 64 bits of js number, we can only use 32 bits due to js number implementation, and that int is signed (Binary signed 2's complement).291 // If total nr of nodes is 8X8 = 64 nodes we need array with 2 int which have 32X2=64 bits,,292 // this is how the TRANSPOSED mask look like if we have max_usable_bits = 24 and totalNrOfCells = 64:293 // section_indx=0 section_indx=1294 // 56|..|40|32|24|16|08|00 57|...|25|17|09|01295 // to set bit (bit_to_set) = 5:296 // * section_indx = floor( (5 % 8)/3 ) = 1297 // * nr_of_shifts = ( (5 % 8) * 8 + floor(5 / 8) ) % 24 = 16298 // * a[section_indx] |= (1 << nr_of_shifts) ==> a[1] |= (1 << 16)299 let section_indx = floor(((node_value % gameBoardSideLen) * gameBoardSideLen) / BITS_PER_SECTION)300 let x_T = (node_value % gameBoardSideLen)301 let y_T = floor(node_value / gameBoardSideLen)302 let nr_of_shifts = ((x_T * gameBoardSideLen) + y_T) % BITS_PER_SECTION;303 return { section_indx, nr_of_shifts }304 }305 // remember to set gameBoardSideLen = 12306 let other_path144 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143,]307 // remember to set gameBoardSideLen = 10308 let other_path100 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99,]309 // remember to set gameBoardSideLen = 8310 let other_path64 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,]311 // remember to set gameBoardSideLen = 6312 let other_path36 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,]313 let other_path = other_path36314 let other_mask = Array(NR_OF_SECTIONS).fill(0)315 other_path.forEach(node => {316 let { section_indx, nr_of_shifts } = calc_index(node);317 other_mask[section_indx] |= (1 << nr_of_shifts)318 })319 let other_T_mask = Array(NR_OF_SECTIONS).fill(0)320 other_path.forEach(node => {321 let { section_indx, nr_of_shifts } = calc_T_index(node);322 other_T_mask[section_indx] |= (1 << nr_of_shifts)323 })324 // remember to set gameBoardSideLen = 12325 let path144 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143,]326 // remember to set gameBoardSideLen = 10327 let path100 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99,]328 // remember to set gameBoardSideLen = 8329 let path64 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,]330 // remember to set gameBoardSideLen = 6331 let path36 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,]332 let path = path36333 let this_mask = Array(NR_OF_SECTIONS).fill(0)334 path.forEach(node => {335 let { section_indx, nr_of_shifts } = calc_index(node);336 this_mask[section_indx] |= (1 << nr_of_shifts)337 })338 let this_T_mask = Array(NR_OF_SECTIONS).fill(0)339 path.forEach(node => {340 let { section_indx, nr_of_shifts } = calc_T_index(node);341 this_T_mask[section_indx] |= (1 << nr_of_shifts)342 })343 const walls = {344 UPPER: 'UPPER',345 LOWER: 'LOWER',346 LEFT: 'LEFT',347 RIGHT: 'RIGHT',348 }349 const option = {350 other_root: null,351 other_leaf: null,352 connect_before_this_node: null,353 }354 let res_options = {355 [walls.UPPER]: [],356 [walls.LOWER]: [],357 [walls.LEFT]: [],358 [walls.RIGHT]: [],359 }360 const upper_wall_calc = (section_index, found) => {361 let this_section = this_mask[section_index]362 let this_next_section = this_mask[section_index + 1]363 let other_section = other_mask[section_index]364 // printBinString(this_section , "this_section")365 // printBinString(other_section , "other_section")366 // To connenct to the upper wall, the comparing starts between (2nd row in the "this" graph) and (fst row of "other" graph), which means the fst n-th bits in the "this" graph will be ignored367 // i.e. the fst n-th bits in this "section" the "this" graph will be ignored, where n is eq "gameBoardSideLen"368 let this_mask_shifted = this_section >>> gameBoardSideLen369 // the n-th fst bits in the next section will be also ignored at the next excution, the same as the fst n-th bits in this section has been ignored370 // that's why we have to copy these fst n-th bits in the next section to be as the last n-th bits at this section.371 let next_n_bits = this_next_section ? (this_next_section & ((1 << gameBoardSideLen) - 1)) : 0372 // copy the fst n bits in the next section to the last n bits in this section, where n is eq "gameBoardSideLen"373 this_mask_shifted |= (next_n_bits << (BITS_PER_SECTION - gameBoardSideLen))374 let filter_upper_wall = other_section & this_mask_shifted375 // printBinString(filter_upper_wall)376 while (filter_upper_wall > 0 && !found) {377 let msb_index = msb_u32(filter_upper_wall)378 // add "(section_index * BITS_PER_SECTION )" to get the aqtual node value.379 let msb_node_value = msb_index + (section_index * BITS_PER_SECTION)380 let other_x = floor(msb_node_value / gameBoardSideLen)381 let other_x_is_even = (other_x % 2) == 0382 let other_root = other_x_is_even ? (msb_node_value - 1) : msb_node_value383 let other_leaf = other_x_is_even ? msb_node_value : (msb_node_value - 1)384 // since root.y is always even when connecteing with upper wall385 let other_root_y_is_even = other_root % 2 == 0 // this is eq to (msb_node_value % gameBoardSideLen) % 2 == 0386 let is_other_root_leaf_same_row = floor(other_leaf / gameBoardSideLen) == floor(other_root / gameBoardSideLen)387 // console.log(`msb_node_value ${msb_node_value}`)388 if (is_other_root_leaf_same_row && other_root_y_is_even && (other_x >= 1 && other_x <= (gameBoardSideLen - 1))) {389 if ((msb_index - 1) >= 0 && (filter_upper_wall & (1 << (msb_index - 1))) != 0) { // important: (msb_index - 1) >= 0, since 1<<(-1) is the same as 1<<7 if the mask leng is 8390 // console.log(`other_root ${other_root}`)391 // console.log(`other_leaf ${other_leaf}`)392 let temp = Object.assign({}, option)393 temp.other_root = other_root394 temp.other_leaf = other_leaf395 temp.connect_before_this_node = (temp.other_leaf - gameBoardSideLen)396 res_options[walls.UPPER].push(temp)397 }398 filter_upper_wall = clear_bit(filter_upper_wall, 1 << msb_index)399 filter_upper_wall = clear_bit(filter_upper_wall, 1 << (msb_index - 1))400 // printBinString(filter_upper_wall)401 } else {402 filter_upper_wall = clear_bit(filter_upper_wall, 1 << msb_index)403 // printBinString(filter_upper_wall)404 }405 }406 }407 const left_Transposed_wall_calc = (section_index, found) => {408 let this_T_section = this_T_mask[section_index]409 let this_T_next_section = this_T_mask[section_index + 1]410 let other_T_section = other_T_mask[section_index]411 // READ the comments inside "upper_wall_calc" since this is almost the same idea, but mask is transposed.412 let this_T_mask_shifted = this_T_section >>> gameBoardSideLen413 let next_T_n_bits = this_T_next_section ? (this_T_next_section & ((1 << gameBoardSideLen) - 1)) : 0414 this_T_mask_shifted |= (next_T_n_bits << (BITS_PER_SECTION - gameBoardSideLen))415 let filter_T_left_wall = other_T_section & this_T_mask_shifted416 while (filter_T_left_wall > 0 && !found) {417 /* if the node actaul value is 58, then msb_T_index is 23 */418 let msb_T_index = msb_u32(filter_T_left_wall)419 // add "(section_index * BITS_PER_SECTION )" to get the T node value.420 /* if the node actaul value is 58, then msb_T_value is 23 = 23 + (0 * 24) */421 let msb_T_value = msb_T_index + (section_index * BITS_PER_SECTION)422 /* if the node actaul value is 58, then msb_T_x is 2 msb_T_x can has a range [0,2] iff the NR_OF_SECTIONS is 3*/423 let msb_T_x = floor(msb_T_value / gameBoardSideLen)424 /* if the node actaul value is 58, then msb_T_y is 7 msb_T_y can has a range [0,7]*/425 let msb_T_y = (msb_T_value % gameBoardSideLen)426 /* if the node actaul value is 58, then msb_node_value is 58 */427 let msb_node_value = msb_T_x + (msb_T_y * gameBoardSideLen)428 // Note (other_T_x_is_even =>(23.x = 2)_is_even) is NOT eq to (msb_T_value_is_even => (23)_is_even), and also NOT eq to actaul node value (58)_is_even429 let other_T_x_is_even = (msb_T_x % 2) == 0430 /* if the node actaul value is 58, then other_root is 58 other_root is 50*/431 let other_root = other_T_x_is_even ? msb_node_value : (msb_node_value - gameBoardSideLen)432 let other_leaf = other_T_x_is_even ? (msb_node_value - gameBoardSideLen) : msb_node_value433 // since other_root.x is always odd when connecteing with left wall434 // Note (other_root_x_is_even =>(58.x)_is_even) is NOT eq to actaul node value (58)_is_even435 let other_root_x_is_even = (floor(other_root / gameBoardSideLen)) % 2 == 0436 let is_other_root_leaf_same_col = ((other_root) % gameBoardSideLen) == ((other_leaf) % gameBoardSideLen)437 if (is_other_root_leaf_same_col && !other_root_x_is_even && (msb_T_x >= 1 && msb_T_x <= (gameBoardSideLen - 1))) {438 if ((msb_T_index - 1) >= 0 && (filter_T_left_wall & (1 << (msb_T_index - 1))) != 0) { // important: (msb_T_index - 1) >= 0, since 1<<(-1) is the same as 1<<7 if the mask leng is 8439 // console.log(`other_root ${other_root}`)440 // console.log(`other_leaf ${other_leaf}`)441 let temp = Object.assign({}, option)442 temp.other_root = other_root443 temp.other_leaf = other_leaf444 temp.connect_before_this_node = (temp.other_leaf - 1)445 res_options[walls.LEFT].push(temp)446 }447 filter_T_left_wall = clear_bit(filter_T_left_wall, 1 << msb_T_index)448 filter_T_left_wall = clear_bit(filter_T_left_wall, 1 << (msb_T_index - 1))449 // printBinString(filter_T_left_wall)450 } else {451 filter_T_left_wall = clear_bit(filter_T_left_wall, 1 << msb_T_index)452 // printBinString(filter_T_left_wall)453 }454 }455 return found456 }457 const lower_wall_calc = (section_index, found) => {458 let this_section = this_mask[section_index]459 let this_next_section = this_mask[section_index + 1]460 let other_section = other_mask[section_index]461 // printBinString(other_mask[section_index], "other_mask["+section_index+"]")462 // printBinString(other_mask[section_index + 1], "other_mask["+(section_index+1)+"]")463 // To connenct to the lower wall, the comparing starts between (2nd row in the "this" graph) and (fst row of "other" graph), which means the fst n-th bits in the "this" graph will be ignored464 // i.e. the fst n-th bits in this "section" the "this" graph will be ignored, where n is eq "gameBoardSideLen"465 let this_mask_shifted = this_section >>> gameBoardSideLen466 // the n-th fst bits in the next section will be also ignored at the next excution, the same as the fst n-th bits in this section has been ignored467 // that's why we have to copy these fst n-th bits in the next section to be as the last n-th bits at this section.468 let next_n_bits = this_next_section ? (this_next_section & ((1 << gameBoardSideLen) - 1)) : 0469 // copy the fst n bits in the next section to the last n bits in this section, where n is eq "gameBoardSideLen"470 this_mask_shifted |= (next_n_bits << (BITS_PER_SECTION - gameBoardSideLen))471 let filter_lower_wall = other_section & this_mask_shifted472 // printBinString(filter_lower_wall)473 while (filter_lower_wall > 0 && !found) {474 let msb_index = msb_u32(filter_lower_wall)475 // add "(section_index * BITS_PER_SECTION )" to get the aqtual node value.476 let msb_node_value = msb_index + (section_index * BITS_PER_SECTION)477 let other_x = floor(msb_node_value / gameBoardSideLen)478 let other_x_is_even = (other_x % 2) == 0479 let other_root = other_x_is_even ? (msb_node_value - 1) : msb_node_value480 let other_leaf = other_x_is_even ? msb_node_value : (msb_node_value - 1)481 // since root.y is always odd when connecteing with lower wall482 let other_root_y_is_even = other_root % 2 == 0 // this is eq to (msb_node_value % gameBoardSideLen) % 2 == 0483 let is_other_root_leaf_same_row = floor(other_leaf / gameBoardSideLen) == floor(other_root / gameBoardSideLen)484 // console.log(`msb_node_value ${msb_node_value}`)485 if (is_other_root_leaf_same_row && !other_root_y_is_even && (other_x >= 1 && other_x <= (gameBoardSideLen - 1))) {486 if ((msb_index - 1) >= 0 && (filter_lower_wall & (1 << (msb_index - 1))) != 0) { // important: (msb_index - 1) >= 0, since 1<<(-1) is the same as 1<<7 if the mask leng is 8487 // console.log(`other_root ${other_root}`)488 // console.log(`other_leaf ${other_leaf}`)489 let temp = Object.assign({}, option)490 temp.other_root = other_root491 temp.other_leaf = other_leaf492 temp.connect_before_this_node = (temp.other_leaf + gameBoardSideLen),493 res_options[walls.LOWER].push(temp)494 }495 filter_lower_wall = clear_bit(filter_lower_wall, 1 << msb_index)496 filter_lower_wall = clear_bit(filter_lower_wall, 1 << (msb_index - 1))497 // printBinString(filter_lower_wall)498 } else {499 filter_lower_wall = clear_bit(filter_lower_wall, 1 << msb_index)500 // printBinString(filter_lower_wall)501 }502 }503 return found504 }505 const rigth_Transposed_wall_calc = (section_index, found) => {506 // READ the comments inside "left_Transposed_wall_calc" since this is almost the same idea 507 let this_T_section = this_T_mask[section_index]508 let this_T_next_section = this_T_mask[section_index + 1]509 let other_T_section = other_T_mask[section_index]510 let this_T_mask_shifted = this_T_section >>> gameBoardSideLen511 let next_T_n_bits = this_T_next_section ? (this_T_next_section & ((1 << gameBoardSideLen) - 1)) : 0512 this_T_mask_shifted |= (next_T_n_bits << (BITS_PER_SECTION - gameBoardSideLen))513 let filter_T_right_wall = other_T_section & this_T_mask_shifted514 while (filter_T_right_wall > 0 && !found) {515 /* if the node actaul value is 58, then msb_T_index is 23 */516 let msb_T_index = msb_u32(filter_T_right_wall)517 // add "(section_index * BITS_PER_SECTION )" to get the Transposed node value.518 /* if the node actaul value is 58, then msb_T_value is 23 = 23 + (0 * 24) */519 let msb_T_value = msb_T_index + (section_index * BITS_PER_SECTION)520 /* if the node actaul value is 58, then msb_T_x is 2 msb_T_x can has a range [0,2] iff the NR_OF_SECTIONS is 3*/521 let msb_T_x = floor(msb_T_value / gameBoardSideLen)522 /* if the node actaul value is 58, then msb_T_y is 7 msb_T_y can has a range [0,7]*/523 let msb_T_y = (msb_T_value % gameBoardSideLen)524 /* if the node actaul value is 58, then msb_node_value is 58 */525 let msb_node_value = msb_T_x + (msb_T_y * gameBoardSideLen)526 // Note (other_T_x_is_even =>(23.x = 2)_is_even) is NOT eq to (msb_T_value_is_even => (23)_is_even), and also NOT eq to actaul node value (58)_is_even527 let other_T_x_is_even = (msb_T_x % 2) == 0528 /* if the node actaul value is 58, then other_root is 58 other_root is 50*/529 let other_root = other_T_x_is_even ? msb_node_value : (msb_node_value - gameBoardSideLen)530 let other_leaf = other_T_x_is_even ? (msb_node_value - gameBoardSideLen) : msb_node_value531 // since other_root.x is always even when connecteing with right wall532 // Note (other_root_x_is_even =>(58.x)_is_even) is NOT eq to actaul node value (58)_is_even533 let other_root_x_is_even = (floor(other_root / gameBoardSideLen)) % 2 == 0534 let is_other_root_leaf_same_col = ((other_root) % gameBoardSideLen) == ((other_leaf) % gameBoardSideLen)535 if (is_other_root_leaf_same_col && other_root_x_is_even && (msb_T_x >= 1 && msb_T_x <= (gameBoardSideLen - 1))) {536 if ((msb_T_index - 1) >= 0 && (filter_T_right_wall & (1 << (msb_T_index - 1))) != 0) { // important: (msb_T_index - 1) >= 0, since 1<<(-1) is the same as 1<<7 if the mask leng is 8537 // console.log(`other_root ${other_root}`)538 // console.log(`other_leaf ${other_leaf}`)539 let temp = Object.assign({}, option)540 temp.other_root = other_root541 temp.other_leaf = other_leaf542 temp.connect_before_this_node = (temp.other_leaf - 1)543 res_options[walls.RIGHT].push(temp)544 }545 filter_T_right_wall = clear_bit(filter_T_right_wall, 1 << msb_T_index)546 filter_T_right_wall = clear_bit(filter_T_right_wall, 1 << (msb_T_index - 1))547 // printBinString(filter_T_right_wall)548 } else {549 filter_T_right_wall = clear_bit(filter_T_right_wall, 1 << msb_T_index)550 // printBinString(filter_T_right_wall)551 }552 }553 return found554 }555 let found = false556 for (let i = 0; i < (other_mask.length); i++) { // && !found557 found = upper_wall_calc(i, found)558 found = left_Transposed_wall_calc(i, found)559 found = lower_wall_calc(i, found)560 found = rigth_Transposed_wall_calc(i, found)561 }562 console.log('walls.UPPER')563 console.log(res_options[walls.UPPER].length)564 res_options[walls.UPPER].forEach(op => console.log(op))565 console.log(`\n`)566 console.log('walls.LOWER')567 console.log(res_options[walls.LOWER].length)568 res_options[walls.LOWER].forEach(op => console.log(op))569 console.log(`\n`)570 console.log(res_options[walls.LEFT].length)571 console.log('walls.LEFT')572 res_options[walls.LEFT].forEach(op => console.log(op))573 console.log(`\n`)574 console.log('walls.RIGHT')575 console.log(res_options[walls.RIGHT].length)576 res_options[walls.RIGHT].forEach(op => console.log(op))577}...

Full Screen

Full Screen

mastodon.js

Source:mastodon.js Github

copy

Full Screen

1"use strict";2const COOKIE_NAME = 'instance-address'3const URL_REGEX = /^(https?:\/\/)?([\da-z.-]+)\.([a-z.]{2,6})([\/\w .-]*)*\/?$/4function msbShareButtonAction(name, target) {5 let msbInstanceAddress = ''6 msbInstanceAddress = msbGetCookie('instance-address')7 if (msbInstanceAddress.length > 0) {8 window.open(`${msbInstanceAddress}/share?text=${name}%20${target}`, `__blank`)9 }10 else {11 if (msbConfig && msbConfig.openModal && msbConfig.addressFieldSelector) {12 13 if (document.querySelector(msbConfig.buttonModalSelector)) {14 let bms = document.querySelector(msbConfig.buttonModalSelector)15 bms.data = { target, name }16 bms.addEventListener('click', () => msbOnShare(), false) 17 }18 msbConfig.openModal(name, target)19 }20 }21}22function msbOnShare(_name, _target) {23 if (msbConfig && msbConfig.addressFieldSelector && msbConfig.buttonModalSelector) {24 let name = !!_name ? _name : document.querySelector(msbConfig.buttonModalSelector).data.name25 let target = !!_target ? _target : document.querySelector(msbConfig.buttonModalSelector).data.target26 let msbInstanceAddress = document.querySelector(`${msbConfig.addressFieldSelector}`).value27 if (msbInstanceAddress.match(URL_REGEX)) {28 if (msbConfig.memorizeFieldId) {29 let msbMemorizeIsChecked = document.querySelector(`#${msbConfig.memorizeFieldId}`).checked30 if (msbConfig.memorizeFieldId && !msbGetCookie(COOKIE_NAME).length > 0 && msbMemorizeIsChecked) {31 msbSetCookie(COOKIE_NAME, msbInstanceAddress, 7);32 }33 }34 window.open(`${msbInstanceAddress}/share?text=${name}%20${target}`, `__blank`)35 if (msbConfig && msbConfig.openModal && msbConfig.closeModal) {36 msbConfig.closeModal()37 }38 }39 }40}41function msbGetCookie(cname) {42 var name = cname + "=";43 var ca = document.cookie.split(';');44 for(var i = 0; i < ca.length; i++) {45 var c = ca[i];46 while (c.charAt(0) == ' ') {47 c = c.substring(1);48 }49 if (c.indexOf(name) == 0) {50 return c.substring(name.length, c.length);51 }52 }53 return "";54}55function msbSetCookie(name, value, days) {56 let d = new Date()57 d.setTime(d.getTime() + days*86400000)58 let expires = 'expires=' + d.toUTCString()59 document.cookie = `${name}=${value}; ${expires}; path=/`60}61(function() {62 let msbButtons = document.querySelectorAll('.mastodon-share-button')63 for(let i = 0; i < msbButtons.length; i++) {64 (function(j) {65 let msbTarget = msbButtons[j].dataset.target66 let msbName = msbButtons[j].dataset.name67 let msbButtonStyle = msbButtons[j].dataset.buttonstyle68 let msbText = msbButtons[j].dataset.text69 // Replace hashtab by html code70 msbName = msbName.replace(/#/g, '%23')71 /**72 * Create buttons73 */74 let button = document.createElement('button')75 let buttonText = null76 /**77 * Add text button... or not78 */79 if (msbConfig && (msbConfig.buttonDisplayText || msbConfig.buttonDisplayText === undefined)) {80 buttonText = !!msbText ? document.createTextNode(msbText) : document.createTextNode(msbI18n())81 }82 else {83 buttonText = document.createTextNode('')84 }85 86 if (msbButtonStyle) {87 button.setAttribute('class', msbButtonStyle)88 }89 90 button.appendChild(buttonText)91 msbButtons[j].appendChild(button)92 93 /**94 * Add icon to the button if buttonIconHtml is setted95 */96 if (msbConfig && msbConfig.buttonIconHtml) {97 button.innerHTML = `${msbConfig.buttonIconHtml} ${button.innerHTML}`98 }99 /**100 * Set the listener in each button101 */102 button.addEventListener('click', () => { msbShareButtonAction(msbName, msbTarget) }, true)103 })(i)104 }105})()106function msbI18n() {107 let language = navigator.language || navigator.userLanguage108 let publish = {109 'ar': 'بوّق',110 'bg': 'Раздумай',111 'cs': 'Tootnout',112 'de': 'Tröt',113 'eo': 'Hué',114 'es': 'Tootear',115 'eu': 'Tut',116 'fa': 'بوق',117 'fi': 'Tuuttaa',118 'fr': 'Pouet',119 'gl': 'ללחוש',120 'he': 'ללחוש',121 'hu': 'Tülk',122 'hy': 'Թթել',123 'io': 'Siflar',124 'ja': 'トゥート',125 'ko': '툿',126 'no': 'Tut',127 'oc': 'Tut',128 'pl': 'Wyślij',129 'pt-BR': 'Publicar',130 'pt': 'Publicar',131 'ru': 'Трубить',132 'sr-Latn': 'Tutni',133 'sr': 'Тутни',134 'uk': 'Дмухнути',135 'zh-CN': '嘟嘟',136 'zh-HK': '發文',137 'zh-TW': '貼掉',138 'default': 'Toot'139 }140 let text = null141 try {142 text = publish[language]143 }144 catch (error) {145 text = publish.default146 }147 return text...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3var options = {4};5wpt.runTest(url, options, function(err, data) {6 if (err) {7 console.log(err);8 } else {9 console.log(data);10 }11});12var wpt = require('webpagetest');13var wpt = new WebPageTest('www.webpagetest.org');14var options = {15};16wpt.runTest(url, options, function(err, data) {17 if (err) {18 console.log(err);19 } else {20 console.log(data);21 }22});23var wpt = require('webpagetest');24var wpt = new WebPageTest('www.webpagetest.org');25var options = {26};27wpt.runTest(url, options, function(err, data) {28 if (err) {29 console.log(err);30 } else {31 console.log(data);32 }33});34var wpt = require('webpagetest');35var wpt = new WebPageTest('www.webpagetest.org');36var options = {37};38wpt.runTest(url, options, function(err, data) {39 if (err) {40 console.log(err);41 } else {42 console.log(data);43 }44});45var wpt = require('webpagetest');

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2wpt.msB(function (err, data) {3 if (err) {4 console.log(err);5 } else {6 console.log(data);7 }8});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt-api');2wpt.msB(1000, function(err, result) {3 if (err) {4 console.log('error: ' + err);5 } else {6 console.log('result: ' + result);7 }8});9var wpt = require('wpt-api');10wpt.msB(1000, function(err, result) {11 if (err) {12 console.log('error: ' + err);13 } else {14 console.log('result: ' + result);15 }16});17var wpt = require('wpt-api');18wpt.msB(1000, function(err, result) {19 if (err) {20 console.log('error: ' + err);21 } else {22 console.log('result: ' + result);23 }24});25var wpt = require('wpt-api');26wpt.msB(1000, function(err, result) {27 if (err) {28 console.log('error: ' + err);29 } else {30 console.log('result: ' + result);31 }32});33var wpt = require('wpt-api');34wpt.msB(1000, function(err, result) {35 if (err) {36 console.log('error: ' + err);37 } else {38 console.log('result: ' + result);39 }40});41var wpt = require('wpt-api');42wpt.msB(1000, function(err, result) {43 if (err) {44 console.log('error: ' + err);45 } else {46 console.log('result: ' + result);47 }48});49var wpt = require('wpt-api');50wpt.msB(1000, function(err, result) {51 if (err) {52 console.log('error: ' + err);53 } else {

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var msB = wptools.msB;3var msB = new msB('Albert Einstein');4msB.get(function(err, result) {5 console.log(result);6});7var wptools = require('wptools');8var msB = wptools.msB;9var msB = new msB('Albert Einstein');10msB.get(function(err, result) {11 console.log(result);12});13var wptools = require('wptools');14var msB = wptools.msB;15var msB = new msB('Albert Einstein');16msB.get(function(err, result) {17 console.log(result);18});19var wptools = require('wptools');20var msB = wptools.msB;21var msB = new msB('Albert Einstein');22msB.get(function(err, result) {23 console.log(result);24});25var wptools = require('wptools');26var msB = wptools.msB;27var msB = new msB('Albert Einstein');28msB.get(function(err, result) {29 console.log(result);30});31var wptools = require('wptools');32var msB = wptools.msB;33var msB = new msB('Albert Einstein');34msB.get(function(err, result) {35 console.log(result);36});37var wptools = require('wptools');38var msB = wptools.msB;39var msB = new msB('Albert Einstein');40msB.get(function(err, result) {41 console.log(result);42});43var wptools = require('wptools');44var msB = wptools.msB;45var msB = new msB('Albert Einstein');

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful