-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<module type="JAVA_MODULE" version="4"> | ||
<component name="NewModuleRootManager" inherit-compiler-output="true"> | ||
<exclude-output /> | ||
<content url="file://$MODULE_DIR$"> | ||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> | ||
</content> | ||
<orderEntry type="inheritedJdk" /> | ||
<orderEntry type="sourceFolder" forTests="false" /> | ||
<orderEntry type="library" name="com.carrotsearch:hppc:0.6.1" level="project" /> | ||
<orderEntry type="library" name="com.google.guava:guava:18.0" level="project" /> | ||
</component> | ||
</module> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
package amu.saeed.marmof; | ||
|
||
import java.math.BigInteger; | ||
import java.util.Arrays; | ||
|
||
/** | ||
* Created by Saeed on 3/7/14. | ||
*/ | ||
public class BoolArray implements Comparable<BoolArray> { | ||
private boolean[] array; | ||
|
||
public BoolArray(boolean[] array) { | ||
this.array = array.clone(); | ||
} | ||
|
||
private BoolArray() { | ||
} | ||
|
||
public static BoolArray buildFrom(boolean[] array) { | ||
BoolArray result = new BoolArray(); | ||
result.array = array; | ||
return result; | ||
} | ||
|
||
public static boolean[] longToBoolArray(long a, int size) { | ||
boolean[] arr = new boolean[size]; | ||
for (int i = 0; i < size; i++) | ||
if ((a & (1L << i)) != 0) | ||
arr[i] = true; | ||
return arr; | ||
} | ||
|
||
public static long boolArrayToLong(boolean[] arr) { | ||
if (arr.length > 64) | ||
throw new IllegalStateException("Array size is larger than 64: " + arr.length); | ||
|
||
long result = 0; | ||
for (int i = 0; i < arr.length; i++) | ||
if (arr[i]) | ||
result |= (1L << i); | ||
|
||
return result; | ||
} | ||
|
||
public boolean[] getArray() { | ||
return array; | ||
} | ||
|
||
public int size() { | ||
return getArray().length; | ||
} | ||
|
||
public BigInteger getAsBigInt() { | ||
BigInteger result = BigInteger.ZERO; | ||
for (int i = 0; i < getArray().length; i++) | ||
if (getArray()[i]) | ||
result = result.setBit(i); | ||
return result; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
char[] signature = new char[getArray().length]; | ||
for (int i = 0; i < getArray().length; i++) | ||
if (getArray()[i]) | ||
signature[i] = '1'; | ||
else | ||
signature[i] = '0'; | ||
return new String(signature); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object aThat) { | ||
if (this == aThat) return true; | ||
if (aThat == null) return false; | ||
if (!(aThat instanceof BoolArray)) return false; | ||
BoolArray that = (BoolArray) aThat; | ||
return Arrays.equals(getArray(), that.getArray()); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
if (getArray() == null) | ||
return 0; | ||
int result = 1; | ||
for (int i = 0; i < getArray().length; i++) | ||
result = 31 * result + (getArray()[i] ? 1231 : 1237); | ||
return result; | ||
} | ||
|
||
@Override | ||
public int compareTo(BoolArray o) { | ||
if (getArray().length < o.getArray().length) | ||
return -1; | ||
if (getArray().length > o.getArray().length) | ||
return 1; | ||
|
||
for (int i = 0; i < getArray().length; i++) { | ||
if (getArray()[i] == o.getArray()[i]) | ||
continue; | ||
if (getArray()[i] == true) | ||
return 1; | ||
else | ||
return -1; | ||
} | ||
return 0; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package amu.saeed.marmof; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* Created by Saeed on 4/17/14. | ||
*/ | ||
final public class FreqMap { | ||
public HashMap<BoolArray, Count> map = new HashMap<BoolArray, Count>(); | ||
|
||
public void add(BoolArray arr, int occurrences) { | ||
Count freq = map.get(arr); | ||
if (freq == null) | ||
map.put(arr, new Count(occurrences)); | ||
else | ||
freq.getAndAdd(occurrences); | ||
} | ||
|
||
public void add(BoolArray arr, long occurrences) { | ||
Count freq = map.get(arr); | ||
if (freq == null) | ||
map.put(arr, new Count(occurrences)); | ||
else | ||
freq.getAndAdd(occurrences); | ||
} | ||
|
||
public int size() { | ||
return map.size(); | ||
} | ||
|
||
public long totalFreq() { | ||
long sum = 0; | ||
for (Map.Entry<BoolArray, Count> e : map.entrySet()) | ||
sum += e.getValue().get(); | ||
return sum; | ||
} | ||
|
||
public void clear() { | ||
map.clear(); | ||
} | ||
|
||
final public class Count { | ||
long value; | ||
|
||
Count(int value) { | ||
this.value = value; | ||
} | ||
|
||
Count(long value) { | ||
this.value = value; | ||
} | ||
|
||
public long get() { | ||
return value; | ||
} | ||
|
||
public long getAndAdd(int delta) { | ||
long result = value; | ||
value = result + delta; | ||
return result; | ||
} | ||
|
||
public long getAndAdd(long delta) { | ||
long result = value; | ||
value = result + delta; | ||
return result; | ||
} | ||
|
||
|
||
@Override | ||
public int hashCode() { | ||
return (int) (value ^ (value >>> 32)); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
return obj instanceof Count && ((Count) obj).value == value; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return Long.toString(value); | ||
} | ||
|
||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package amu.saeed.marmof; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
/** | ||
* Created by saeed on 5/7/15. | ||
*/ | ||
public interface Graph { | ||
boolean areNeighbor(int v, int w); | ||
|
||
public int[] getNeighbors(int v); | ||
|
||
public void printInfo(); | ||
|
||
public int vertexCount(); | ||
|
||
public int edgeCount(); | ||
|
||
public Set<Integer> getVertices(); | ||
|
||
public List<Edge> getEdges(); | ||
|
||
public int getDegree(int vertex); | ||
|
||
public SubGraphStructure getSubGraph(int[] vertex_set); | ||
|
||
public long getSubGraphAsLong(int[] vertex_set); | ||
|
||
public boolean hasEdge(int v, int w); | ||
|
||
public void printToFile(String path) throws IOException; | ||
|
||
public final static class Edge { | ||
int src; | ||
int dest; | ||
|
||
public Edge(int src, int dest) { | ||
this.src = src; | ||
this.dest = dest; | ||
} | ||
} | ||
} |