This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.the_mgi.util; | |
| import java.util.List; | |
| import java.util.function.Supplier; | |
| import static java.util.Objects.nonNull; | |
| import static java.util.Objects.requireNonNull; | |
| public class Catchable<T> { | |
| private final Supplier<T> supplier; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| FROM node:14.17 | |
| RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \ | |
| && echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list \ | |
| && apt update \ | |
| && apt -y install yarn | |
| CMD ["bash"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?xml version="1.0" encoding="UTF-8"?> | |
| <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
| <modelVersion>4.0.0</modelVersion> | |
| <parent> | |
| <groupId>org.springframework.boot</groupId> | |
| <artifactId>spring-boot-starter-parent</artifactId> | |
| <version>2.5.5</version> | |
| <relativePath/> <!-- lookup parent from repository --> | |
| </parent> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function InterpolationSearchRecursive(array: number[], key: number, startIndex: number, lastIndex: number): number { | |
| const position = | |
| Math.floor(startIndex + ( | |
| (lastIndex - startIndex) / | |
| (array[lastIndex] - array[startIndex]) * | |
| (key - array[startIndex]))); | |
| // 1st condition, to make sure we are not out of bounds of array | |
| // 2nd and 3rd condition to make sure that the key would be present in indexes [startIndex, lastIndex] | |
| if (startIndex <= lastIndex && key >= array[startIndex] && key <= array[lastIndex]) { | |
| if (array[position] === key) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function InterpolationSearchIterative(array: number[], key: number): number { | |
| let startIndex = 0; | |
| let lastIndex = array.length - 1; | |
| // 1st condition, to make sure we are not out of bounds of array | |
| // 2nd and 3rd condition to make sure that the key would be present in indexes [startIndex, lastIndex] | |
| while (startIndex <= lastIndex && key >= array[startIndex] && key <= array[lastIndex]) { | |
| const position = | |
| Math.floor(startIndex + ( | |
| (lastIndex - startIndex) / | |
| (array[lastIndex] - array[startIndex]) * |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function JumpSearchRecursive(array: number[], key: number): number { | |
| const jumpSize = Math.floor(Math.sqrt(array.length)); | |
| let val = jumpSize; | |
| const getHighLowRanges = () => { | |
| if ((array[val] > key) || (val >= array.length)) { | |
| return; | |
| } else { | |
| val = val + jumpSize; | |
| getHighLowRanges(); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function JumpSearchIterative(array: number[], key: number): number { | |
| const jumpSize = Math.floor(Math.sqrt(array.length)); | |
| let val = jumpSize; | |
| while (val <= array.length) { | |
| if ((array[val] > key) || (val >= array.length)) { | |
| break; | |
| } else { | |
| val = val + jumpSize; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function BinarySearchRecursive(array: number[], key, startIndex: number, lastIndex: number): number { | |
| const mid = Math.floor((startIndex + lastIndex) / 2); | |
| if (!(startIndex <= lastIndex)) { | |
| return -1; | |
| } else if (key === array[mid]) { | |
| return mid; | |
| } else if (key < array[mid]) { | |
| BinarySearchRecursive(array, key, startIndex, mid - 1); | |
| } else { | |
| BinarySearchRecursive(array, key, mid + 1, lastIndex); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function BinarySearchIterative(array: number[], key: number): number { | |
| let [startIndex, lastIndex] = [0, array.length]; | |
| let mid = Math.floor((startIndex + lastIndex) / 2); | |
| while (startIndex <= lastIndex) { | |
| if (key === array[mid]) { | |
| return mid; | |
| } else if (key < array[mid]) { | |
| lastIndex = mid - 1; | |
| } else { | |
| startIndex = mid + 1; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function LinearSearchRecursive(array: number[], key: number, index: number = 0): number { | |
| if (index >= array.length) { | |
| return -1; // in case if key is not present in the given array | |
| } else if (array[index] === key) { | |
| return index; | |
| } | |
| LinearSearchRecursive(array, key, index + 1); | |
| } |
NewerOlder