Welcome to mirror list, hosted at ThFree Co, Russian Federation.

VertexSignature.java « hg4 « statmt « org « attempt1 « hypergraph-prototype - github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 211706a25a31ddc3be4c42e63d4b0c0529843d54 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package org.statmt.hg4;

import java.util.HashMap;

public class VertexSignature extends HashMap<String,Comparable> implements Comparable<VertexSignature> {

	private static final long serialVersionUID = 13434L;

	@Override
	public int hashCode() {
		int hc = 0;
		for (String x : this.keySet()) {
			hc *= 37;
			hc += x.hashCode();
		}
		for (Object o : this.values()) {
			hc *= 37;
			hc += o.hashCode();
		}
		return hc;
	}
	
	@Override
	public boolean equals(Object o) {
		VertexSignature v = (VertexSignature)o;
		int cs = v.size();
		for (String x : this.keySet()) {
			Object ot = this.get(x);
			if (!ot.equals(v.get(x)))
				return false;
			cs--;
		}
		return cs == 0;
	}

	public int compareTo(VertexSignature o) {
		VertexSignature v = (VertexSignature)o;
		int cs = v.size();
		for (String x : this.keySet()) {
			Comparable<Object> ot = this.get(x);
			if (ot.compareTo(v.get(x)) != 0)
				return ot.compareTo(v.get(x));
			cs--;
		}
		return cs;
	}
}