GIRAPH-1215

closes #97
diff --git a/giraph-core/src/main/java/org/apache/giraph/types/heaps/FixedCapacityIntByteMinHeap.java b/giraph-core/src/main/java/org/apache/giraph/types/heaps/FixedCapacityIntByteMinHeap.java
index d3dd1e0..a71472a 100644
--- a/giraph-core/src/main/java/org/apache/giraph/types/heaps/FixedCapacityIntByteMinHeap.java
+++ b/giraph-core/src/main/java/org/apache/giraph/types/heaps/FixedCapacityIntByteMinHeap.java
@@ -81,7 +81,8 @@
    * @param value Value
    */
   public void add(int key, byte value) {
-    if (size == capacity && compare(keys[0], values[0], key, value) >= 0) {
+    if (capacity == 0 ||
+        (size == capacity && compare(keys[0], values[0], key, value) >= 0)) {
       // If the heap is full and smallest element in it is not smaller
       // than value, do nothing
       return;
diff --git a/giraph-core/src/main/java/org/apache/giraph/types/heaps/FixedCapacityIntDoubleMinHeap.java b/giraph-core/src/main/java/org/apache/giraph/types/heaps/FixedCapacityIntDoubleMinHeap.java
index aef4509..85debf8 100644
--- a/giraph-core/src/main/java/org/apache/giraph/types/heaps/FixedCapacityIntDoubleMinHeap.java
+++ b/giraph-core/src/main/java/org/apache/giraph/types/heaps/FixedCapacityIntDoubleMinHeap.java
@@ -81,7 +81,8 @@
    * @param value Value
    */
   public void add(int key, double value) {
-    if (size == capacity && compare(keys[0], values[0], key, value) >= 0) {
+    if (capacity == 0 ||
+        (size == capacity && compare(keys[0], values[0], key, value) >= 0)) {
       // If the heap is full and smallest element in it is not smaller
       // than value, do nothing
       return;
diff --git a/giraph-core/src/main/java/org/apache/giraph/types/heaps/FixedCapacityIntFloatMinHeap.java b/giraph-core/src/main/java/org/apache/giraph/types/heaps/FixedCapacityIntFloatMinHeap.java
index a9c2f37..4f88844 100644
--- a/giraph-core/src/main/java/org/apache/giraph/types/heaps/FixedCapacityIntFloatMinHeap.java
+++ b/giraph-core/src/main/java/org/apache/giraph/types/heaps/FixedCapacityIntFloatMinHeap.java
@@ -81,7 +81,8 @@
    * @param value Value
    */
   public void add(int key, float value) {
-    if (size == capacity && compare(keys[0], values[0], key, value) >= 0) {
+    if (capacity == 0 ||
+        (size == capacity && compare(keys[0], values[0], key, value) >= 0)) {
       // If the heap is full and smallest element in it is not smaller
       // than value, do nothing
       return;
diff --git a/giraph-core/src/main/java/org/apache/giraph/types/heaps/FixedCapacityIntIntMinHeap.java b/giraph-core/src/main/java/org/apache/giraph/types/heaps/FixedCapacityIntIntMinHeap.java
index 3cb15e1..4f76739 100644
--- a/giraph-core/src/main/java/org/apache/giraph/types/heaps/FixedCapacityIntIntMinHeap.java
+++ b/giraph-core/src/main/java/org/apache/giraph/types/heaps/FixedCapacityIntIntMinHeap.java
@@ -81,7 +81,8 @@
    * @param value Value
    */
   public void add(int key, int value) {
-    if (size == capacity && compare(keys[0], values[0], key, value) >= 0) {
+    if (capacity == 0 ||
+        (size == capacity && compare(keys[0], values[0], key, value) >= 0)) {
       // If the heap is full and smallest element in it is not smaller
       // than value, do nothing
       return;
diff --git a/giraph-core/src/main/java/org/apache/giraph/types/heaps/FixedCapacityIntLongMinHeap.java b/giraph-core/src/main/java/org/apache/giraph/types/heaps/FixedCapacityIntLongMinHeap.java
index 3c8c1f6..ae64070 100644
--- a/giraph-core/src/main/java/org/apache/giraph/types/heaps/FixedCapacityIntLongMinHeap.java
+++ b/giraph-core/src/main/java/org/apache/giraph/types/heaps/FixedCapacityIntLongMinHeap.java
@@ -81,7 +81,8 @@
    * @param value Value
    */
   public void add(int key, long value) {
-    if (size == capacity && compare(keys[0], values[0], key, value) >= 0) {
+    if (capacity == 0 ||
+        (size == capacity && compare(keys[0], values[0], key, value) >= 0)) {
       // If the heap is full and smallest element in it is not smaller
       // than value, do nothing
       return;
diff --git a/giraph-core/src/main/java/org/apache/giraph/types/heaps/FixedCapacityLongByteMinHeap.java b/giraph-core/src/main/java/org/apache/giraph/types/heaps/FixedCapacityLongByteMinHeap.java
index 65fadf4..9859b4d 100644
--- a/giraph-core/src/main/java/org/apache/giraph/types/heaps/FixedCapacityLongByteMinHeap.java
+++ b/giraph-core/src/main/java/org/apache/giraph/types/heaps/FixedCapacityLongByteMinHeap.java
@@ -81,7 +81,8 @@
    * @param value Value
    */
   public void add(long key, byte value) {
-    if (size == capacity && compare(keys[0], values[0], key, value) >= 0) {
+    if (capacity == 0 ||
+        (size == capacity && compare(keys[0], values[0], key, value) >= 0)) {
       // If the heap is full and smallest element in it is not smaller
       // than value, do nothing
       return;
diff --git a/giraph-core/src/main/java/org/apache/giraph/types/heaps/FixedCapacityLongDoubleMinHeap.java b/giraph-core/src/main/java/org/apache/giraph/types/heaps/FixedCapacityLongDoubleMinHeap.java
index 4350655..f572ac5 100644
--- a/giraph-core/src/main/java/org/apache/giraph/types/heaps/FixedCapacityLongDoubleMinHeap.java
+++ b/giraph-core/src/main/java/org/apache/giraph/types/heaps/FixedCapacityLongDoubleMinHeap.java
@@ -81,7 +81,8 @@
    * @param value Value
    */
   public void add(long key, double value) {
-    if (size == capacity && compare(keys[0], values[0], key, value) >= 0) {
+    if (capacity == 0 ||
+        (size == capacity && compare(keys[0], values[0], key, value) >= 0)) {
       // If the heap is full and smallest element in it is not smaller
       // than value, do nothing
       return;
diff --git a/giraph-core/src/main/java/org/apache/giraph/types/heaps/FixedCapacityLongFloatMinHeap.java b/giraph-core/src/main/java/org/apache/giraph/types/heaps/FixedCapacityLongFloatMinHeap.java
index 1d79015..5fc0d6b 100644
--- a/giraph-core/src/main/java/org/apache/giraph/types/heaps/FixedCapacityLongFloatMinHeap.java
+++ b/giraph-core/src/main/java/org/apache/giraph/types/heaps/FixedCapacityLongFloatMinHeap.java
@@ -81,7 +81,8 @@
    * @param value Value
    */
   public void add(long key, float value) {
-    if (size == capacity && compare(keys[0], values[0], key, value) >= 0) {
+    if (capacity == 0 ||
+        (size == capacity && compare(keys[0], values[0], key, value) >= 0)) {
       // If the heap is full and smallest element in it is not smaller
       // than value, do nothing
       return;
diff --git a/giraph-core/src/main/java/org/apache/giraph/types/heaps/FixedCapacityLongIntMinHeap.java b/giraph-core/src/main/java/org/apache/giraph/types/heaps/FixedCapacityLongIntMinHeap.java
index 67b4154..6eb65a2 100644
--- a/giraph-core/src/main/java/org/apache/giraph/types/heaps/FixedCapacityLongIntMinHeap.java
+++ b/giraph-core/src/main/java/org/apache/giraph/types/heaps/FixedCapacityLongIntMinHeap.java
@@ -81,7 +81,8 @@
    * @param value Value
    */
   public void add(long key, int value) {
-    if (size == capacity && compare(keys[0], values[0], key, value) >= 0) {
+    if (capacity == 0 ||
+        (size == capacity && compare(keys[0], values[0], key, value) >= 0)) {
       // If the heap is full and smallest element in it is not smaller
       // than value, do nothing
       return;
diff --git a/giraph-core/src/main/java/org/apache/giraph/types/heaps/FixedCapacityLongLongMinHeap.java b/giraph-core/src/main/java/org/apache/giraph/types/heaps/FixedCapacityLongLongMinHeap.java
index b318d17..b94dda5 100644
--- a/giraph-core/src/main/java/org/apache/giraph/types/heaps/FixedCapacityLongLongMinHeap.java
+++ b/giraph-core/src/main/java/org/apache/giraph/types/heaps/FixedCapacityLongLongMinHeap.java
@@ -81,7 +81,8 @@
    * @param value Value
    */
   public void add(long key, long value) {
-    if (size == capacity && compare(keys[0], values[0], key, value) >= 0) {
+    if (capacity == 0 ||
+        (size == capacity && compare(keys[0], values[0], key, value) >= 0)) {
       // If the heap is full and smallest element in it is not smaller
       // than value, do nothing
       return;
diff --git a/giraph-core/templates/FixedCapacityType2TypeMinHeap.java b/giraph-core/templates/FixedCapacityType2TypeMinHeap.java
index 5dc37bc..70ad2a2 100644
--- a/giraph-core/templates/FixedCapacityType2TypeMinHeap.java
+++ b/giraph-core/templates/FixedCapacityType2TypeMinHeap.java
@@ -81,7 +81,8 @@
    * @param value Value
    */
   public void add(${type1.lower} key, ${type2.lower} value) {
-    if (size == capacity && compare(keys[0], values[0], key, value) >= 0) {
+    if (capacity == 0 ||
+        (size == capacity && compare(keys[0], values[0], key, value) >= 0)) {
       // If the heap is full and smallest element in it is not smaller
       // than value, do nothing
       return;