0

Here is the definition for my objects:

public class Tuple_comparable implements Serializable, Comparable<Tuple_comparable> {

    public String arg1_surface;
    public String arg1_type; 
    public boolean arg1_type_equals; 
    public String relation; 
    public String arg2_surface; 
    public String arg2_type; 
    public boolean arg2_type_equals; 
    public Long count; 

    @Override 
    public boolean equals(Object o) { 
        if (!(o instanceof Tuple_comparable))
            return false;
        Tuple_comparable oo = (Tuple_comparable)o; 
        if( oo.arg1_type.length() != this.arg1_type.length() )
            return false; 
        if( oo.relation.length() != this.relation.length() )
            return false; 
        if( oo.arg2_type.length() != this.arg2_type.length() )
            return false; 
        if( !oo.arg1_type.equals( this.arg1_type ) )
            return false; 
        if( !oo.arg2_type.equals( this.arg2_type ) )
            return false; 
        if( !oo.relation.equals( this.relation ) )
            return false;           
        return true; 
    }

    @Override
    public int hashCode() { 
        return this.arg1_type.length() + this.relation.length() + this.arg2_type.length(); 
    }

    @Override
    public int compareTo(Tuple_comparable o) {
        return 1;
    }
}

And here is how I used MapDB:

    DB db = DBMaker.newFileDB(new File(folder + "unique_pairs_withDenoms_directed_forward_test_1" + "_mapdb.bin" ))
            //.closeOnJvmShutdown()
            .make();

    // Create a Map:
    Map<Tuple_comparable,long[]> myMap = db.getTreeMap("testmap");

    int i = 0; 

    for( i = 0; i < 100000; i++ ) { 
        // Work with the Map using the normal Map API.
        Tuple_comparable tc = new Tuple_comparable(); 

        tc.arg1_surface = ""+ i; 
        tc.arg1_type = "" +  i; 
        tc.arg1_type_equals = true;  
        tc.relation = "" +  i;  
        tc.arg2_surface = "";
        tc.arg2_type = ""; 
        tc.arg2_type_equals = false; 
        tc.count = (long) 2222222; 

        long[] count = {1,2,3,4,4}; 

        i++; 
        myMap.put(tc, count);
    }
    db.commit(); 
    db.close();     

When I run it, I see the following:

Proccessed = % 0.001
After myMap.size() = 0
Proccessed = % 0.003
After myMap.size() = 1
Proccessed = % 0.005
After myMap.size() = 2
Proccessed = % 0.007
After myMap.size() = 3
Proccessed = % 0.009
After myMap.size() = 4
Proccessed = % 0.011
After myMap.size() = 5
Proccessed = % 0.013
After myMap.size() = 6
Proccessed = % 0.015
After myMap.size() = 7
Proccessed = % 0.017
After myMap.size() = 8
Proccessed = % 0.019
After myMap.size() = 9
Proccessed = % 0.021
After myMap.size() = 10
Proccessed = % 0.023
After myMap.size() = 11
Proccessed = % 0.025
After myMap.size() = 12
Proccessed = % 0.027
After myMap.size() = 13
Proccessed = % 0.029
After myMap.size() = 14
Proccessed = % 0.031
After myMap.size() = 15
Proccessed = % 0.033
After myMap.size() = 16
Proccessed = % 0.035
After myMap.size() = 17
Proccessed = % 0.037
After myMap.size() = 18
Proccessed = % 0.039
After myMap.size() = 19
Proccessed = % 0.041
After myMap.size() = 20
Proccessed = % 0.043
After myMap.size() = 21
Proccessed = % 0.045
After myMap.size() = 22
Proccessed = % 0.047
After myMap.size() = 23
Proccessed = % 0.049
After myMap.size() = 24
Proccessed = % 0.051
After myMap.size() = 25
Proccessed = % 0.053
After myMap.size() = 26
Proccessed = % 0.055
After myMap.size() = 27
Proccessed = % 0.057
After myMap.size() = 28
Proccessed = % 0.059
After myMap.size() = 29
Proccessed = % 0.061
After myMap.size() = 30
Proccessed = % 0.063
After myMap.size() = 31
Proccessed = % 0.065
After myMap.size() = 32
Proccessed = % 0.067
After myMap.size() = 33

And it continues running for unlimited time at the 34th item suddenly (although I expect it to continue adding the 1000th item). When I remove myMap.put(....) it continues until 1000; so there is some wrong going with the put function. I suspect that I have a problem (or missing a property inside the definition of the object type).

Anyone knows what is wrong with my usage of MapDB?

Daniel
  • 5,839
  • 9
  • 46
  • 85

1 Answers1

0

Problem is this:

public int compareTo(Tuple_comparable o) {
    return 1;
}

I am not going to explain it here. For start I would recommend HashMap and generate equals/hashcode by your IDE.

MapDB 1.0 would deadlock, but that is solved in 2.0. So I do not consider it as a problem.

Jan Kotek
  • 1,084
  • 7
  • 4