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 org.idey.scala.generator | |
import scala.util.Random | |
/** | |
* Generator Trait for any Random object generator if any types | |
* @tparam T type of any [[scala.Any]] | |
*/ | |
trait Generator[+T] { | |
self => |
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 org.idey.algo.iterator.peek; | |
import java.util.Iterator; | |
/** | |
* Special Iterator which will provide addiotnal method {@link PeekIterator#peek()} | |
* @param <T> return the current object | |
* | |
*/ | |
public interface PeekIterator<T> extends Iterator<T> { |
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 org.idey.algo.util; | |
import java.util.function.Predicate; | |
/** | |
* Assertion Utility class which will Assert statement in case statement is false, | |
* it will throw IllegalArgument Exception. | |
*/ | |
public class AssertJ { |
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
private static <T> int[] computeTemporaryArray(T pattern[]){ | |
int [] lps = new int[pattern.length]; | |
int index =0; | |
for(int i=1; i < pattern.length;){ | |
if(equals(pattern[i],pattern[index])){ | |
lps[i] = index + 1; | |
index++; | |
i++; | |
}else{ | |
if(index != 0){ |
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
public class RateLimiter { | |
private long minTime; | |
//holds time of last action (past or future!) | |
private volatile long lastSchedAction; | |
private volatile boolean forFirstTime; | |
public RateLimiter(float maxRate, long duration, TimeUnit unit) { | |
if(maxRate <= 0.0f) { | |
throw new IllegalArgumentException("Invalid rate"); | |
} | |
if(unit.compareTo(TimeUnit.MILLISECONDS)<0){ |
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
private static <T> boolean isSafe(T[][] array, int rowIndex, int colIndex,Predicate<T> predicate){ | |
final int ROW = array.length; | |
final int COL = array[0].length; | |
return rowIndex>=0 && rowIndex<ROW && colIndex>=0 && colIndex<COL | |
&& predicate.test(array[rowIndex][colIndex]); | |
} | |
public static <T> void floodFill(T[][] array, int rowIndex, int colIndex, T newObject, Predicate<T> predicate){ | |
int rowNbr[] = new int[] {-1, -1, -1, 0, 0, 1, 1, 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
//O(log(N)) complexity | |
public <T extends Comparable<T>> static in findPivote(T[] array){ | |
int low = 0; | |
int hight = array.length - 1; | |
while(array[low].compareTo(array[high])>0){ | |
int mid = low + (high -low)/2; | |
if(array[mid].compareTo(array[high])>0){ | |
low = mid + 1; | |
}else{ | |
high = mid; |
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
public static boolean isPalinDrome(String str){ | |
if(str==null || str.length()==0){ | |
throw new IllegalArgumentException("Invalid words"); | |
}else{ | |
str = str.trim(); | |
char[] array = str.toCharArray(); | |
Set<Character> sets = new HashSet<>(); | |
for(char ch:array){ | |
boolean add = sets.add(ch); | |
if(!add){ |
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
import java.io.Closeable; | |
import java.util.Iterator; | |
/** | |
* Iterator which used some resource needs to be closed after execution | |
* <em>Any concrete {@link ClosableResourceIterator} class either must be initialized with | |
* try with resource or should call {@link ClosableResourceIterator#close()} after complele | |
* execution.</em> | |
* @see Iterator | |
* @see Closeable |
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
//Class Represent NArrayTreeNode | |
public class NArrayTreeNode<E> { | |
private E data; | |
private List<NArrayTreeNode<E>> childs = new ArrayList<>(); | |
public NArrayTreeNode(E data) { | |
this.data = data; | |
} | |
public NArrayTreeNode<E> addChild(NArrayTreeNode<E> child){ |