Skip to content

Instantly share code, notes, and snippets.

View mhshams's full-sized avatar

Mohammad Sarbandi mhshams

  • Berlin, Germany
View GitHub Profile
/**
* A Set is a data structure that contains multiple (zero or more) elements.
* - The elements in the Set are unique. (no duplication)
* - The elements in the Set are not kept in given order. (unordered)
*/
class MySet {
/**
* This property shows the number of elements that are currently available in the Set.
*/
var size: Int = 0
package io.dahgan
/**
* Queue is a data structure that stores some elements and these elements can be received in FIFO order.
* That means the first element that is inserted to queue would be the first one that can be removed.
*
* Our queue has a limited capacity and can NOT store element more than its capacity.
*
* Note to developer:
* - define an array of integers to keep the queue elements.
package io.dahgan
/**
* Stack is a data structure that stores some elements and these elements can be received in LIFO order.
* That means the last element that is pushed to stack would be the first one that can be poped.
*
* Our stack has a limited capacity and can not store element more than its capacity.
*
* Note to developer:
* - define an array of integers to keep the stack elements.
@mhshams
mhshams / Binary.kt
Last active January 22, 2016 09:45
/**
* A function that takes TWO arrays of Integer, compares them and then returns:
* - 1, if the first array is greater than second one
* - -1, if the second array is greater tan first one
* - 0, if both arrays are the same.
*
* How to Compare?
* Starting from index 0, compare the elements of both array in the same positions until you find one is bigger than the other.
*
* Examples:
@mhshams
mhshams / gist:6136923
Created August 2, 2013 01:45
final results
/opt/jdk1.8.0/bin/java -Didea.launcher.port=7533 -Didea.launcher.bin.path=/opt/idea-IU-129.161/bin -Dfile.encoding=UTF-8 -classpath /opt/jdk1.8.0/jre/lib/rt.jar:/opt/jdk1.8.0/jre/lib/javaws.jar:/opt/jdk1.8.0/jre/lib/charsets.jar:/opt/jdk1.8.0/jre/lib/jfr.jar:/opt/jdk1.8.0/jre/lib/jsse.jar:/opt/jdk1.8.0/jre/lib/jce.jar:/opt/jdk1.8.0/jre/lib/resources.jar:/opt/jdk1.8.0/jre/lib/management-agent.jar:/opt/jdk1.8.0/jre/lib/plugin.jar:/opt/jdk1.8.0/jre/lib/deploy.jar:/opt/jdk1.8.0/jre/lib/ext/sunec.jar:/opt/jdk1.8.0/jre/lib/ext/sunpkcs11.jar:/opt/jdk1.8.0/jre/lib/ext/dnsns.jar:/opt/jdk1.8.0/jre/lib/ext/cldrdata.jar:/opt/jdk1.8.0/jre/lib/ext/sunjce_provider.jar:/opt/jdk1.8.0/jre/lib/ext/zipfs.jar:/opt/jdk1.8.0/jre/lib/ext/localedata.jar:/home/me/code/string-intern/out/production/string-intern:/opt/idea-IU-129.161/lib/idea_rt.jar com.intellij.rt.execution.application.AppMain StringKeyTest
With Warm up String: 82373148
With Warm up Object: 30957921
With Warm up Builder: 72123213
With Warm up String: 61386367
With W
@mhshams
mhshams / StringKeyTest.java
Created August 2, 2013 01:44
final version
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
*/
@mhshams
mhshams / StringKeyTest.java
Created August 1, 2013 17:52
performance test, completed :)
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<>();
@mhshams
mhshams / gist:6133552
Created August 1, 2013 17:40
the results
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
@mhshams
mhshams / StringKeyTest.java
Created August 1, 2013 17:39
a performance test
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
*/
@mhshams
mhshams / ReflectionConstructorTest.java
Created January 17, 2013 16:55
Object instanciation with reflection API
import org.junit.Test;
import sun.reflect.ReflectionFactory;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
/**
* @author me
*/