Skip to content

Commit

Permalink
First commit!
Browse files Browse the repository at this point in the history
  • Loading branch information
shahrivari committed May 7, 2015
0 parents commit ba2aa32
Show file tree
Hide file tree
Showing 24 changed files with 1,503 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions .idea/copyright/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/description.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/libraries/com_carrotsearch_hppc_0_6_1.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/libraries/com_google_guava_guava_18_0.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions .idea/project-template.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added lib/guava-18.0.jar
Binary file not shown.
Binary file added lib/hppc-0.6.1.jar
Binary file not shown.
13 changes: 13 additions & 0 deletions marmof.iml
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>
109 changes: 109 additions & 0 deletions src/amu/saeed/marmof/BoolArray.java
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;
}

}
88 changes: 88 additions & 0 deletions src/amu/saeed/marmof/FreqMap.java
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);
}

}

}
44 changes: 44 additions & 0 deletions src/amu/saeed/marmof/Graph.java
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;
}
}
}
Loading

0 comments on commit ba2aa32

Please sign in to comment.