0

这是我的对象的定义:

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;
    }
}

以下是我使用 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();     

当我运行它时,我看到以下内容:

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

它会在第 34 项突然无限期地继续运行(尽管我希望它会继续添加第 1000 项)。当我删除 myMap.put(....) 时,它会一直持续到 1000;所以 put 函数有一些问题。我怀疑我有问题(或在对象类型的定义中缺少属性)。

有人知道我对 MapDB 的使用有什么问题吗?

4

1 回答 1

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.

于 2014-10-01T07:32:58.033 回答