This file contains 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 StringKeyTest { | |
private static final SecureRandom SECURE_RANDOM = new SecureRandom(); | |
private static final StringGenerator GENERATOR = () -> new BigInteger(130, SECURE_RANDOM).toString(32); | |
public static void main(String[] args) { | |
List<Key> keys = new ArrayList<>(); | |
Map<String, String> withString = new HashMap<>(); |
This file contains 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
With Warm up String: 78933098 | |
With Warm up Object: 24321005 | |
With Warm up Builder: 71801287 | |
With Warm up String: 63005060 | |
With Warm up Object: 11406968 | |
With Warm up Builder: 62253727 | |
With Warm up String: 61489515 | |
With Warm up Object: 12505735 | |
With Warm up Builder: 60929296 | |
With Warm up String: 62588585 |
This file contains 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.math.BigInteger; | |
import java.security.SecureRandom; | |
import java.util.ArrayList; | |
import java.util.HashMap; | |
import java.util.List; | |
import java.util.Map; | |
/** | |
* @author me | |
*/ |
This file contains 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 org.junit.Test; | |
import sun.reflect.ReflectionFactory; | |
import java.lang.reflect.Constructor; | |
import java.lang.reflect.InvocationTargetException; | |
/** | |
* @author me | |
*/ |
This file contains 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 Node { | |
/*data to be save*/ | |
def data | |
/*child nodes of this node*/ | |
def children = [:] | |
/*any key finshied in this node? (end of a word)*/ | |
def flag = false | |
} | |
class Trie { |
This file contains 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 Node { | |
/*data to be save*/ | |
def data | |
/*child nodes of this node*/ | |
def children = [:] | |
} | |
class Trie { | |
/*root node with empty data*/ | |
def root = new Node(data:'') |
This file contains 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
def introSort(list) { | |
// calculate the depth limit. | |
def depth = 2 * (int)(Math.log10(list.size()) / Math.log10(2)) | |
return introLoop(list, depth) | |
} | |
def introLoop(list, depth) { | |
if (list.size() <= 1) { | |
return list | |
} |
This file contains 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
def log2First(v) { | |
def r = 0 | |
while ((v >>= 1) != 0) r++ | |
return r | |
} | |
def log2Second(v) { | |
def buffer = java.nio.ByteBuffer.allocate(8) | |
double d = buffer.putInt(0x43300000).putInt(v).getDouble(0) - 4503599627370496.0 | |
return (buffer.putDouble(0, d).getInt(0) >> 20) - 0x3FF |
This file contains 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 PriorityQueue { | |
/*a list to contains the queue elments in a binary heap format*/ | |
def list = [] | |
/*Add new item to the queue*/ | |
def add(item) { | |
list.add(item) | |
/*After adding new item, we need to re-validate the heap*/ | |
siftUp(list, 0, list.size() - 1) |
This file contains 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
def quickSort(list) { | |
/*Make sure there are at least 2 elements in the list*/ | |
if (list == null || list.size() < 2) { | |
return list | |
} | |
/*break the list to three different groups | |
group 1: with elements less than pivot | |
group 2: with elements equal to pivot |