Skip to content

Commit

Permalink
Modified hashmap
Browse files Browse the repository at this point in the history
  • Loading branch information
fredericlemoine committed Dec 15, 2019
1 parent 8421de6 commit ab308fe
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 13 deletions.
12 changes: 6 additions & 6 deletions hashmap/hashmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ func (k *PairKey) HashEquals(h2 Hasher) bool {
}

// Does not depend on the order
func (k *PairKey) HashCode() int64 {
var hashCode int64 = 1
func (k *PairKey) HashCode() uint64 {
var hashCode uint64 = 1
if k.i1 < k.i2 {
hashCode = 31*hashCode + int64(k.i1)
hashCode = 31*hashCode + int64(k.i2)
hashCode = 31*hashCode + uint64(k.i1)
hashCode = 31*hashCode + uint64(k.i2)
} else {
hashCode = 31*hashCode + int64(k.i2)
hashCode = 31*hashCode + int64(k.i1)
hashCode = 31*hashCode + uint64(k.i2)
hashCode = 31*hashCode + uint64(k.i1)
}
return hashCode
}
Expand Down
1 change: 0 additions & 1 deletion test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,6 @@ ${GOTREE} compare trees -i <(${GOTREE} generate yuletree --seed 10) -c <(${GOTRE
diff -q -b expected result
rm -f expected result


# gotree compare edges
echo "->gotree compare edges"
cat > expected <<EOF
Expand Down
2 changes: 1 addition & 1 deletion tests/clone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestCloneTree(t *testing.T) {
// Comparing edges
edges := tr.Edges()
edges2 := clone.Edges()
index := tree.NewEdgeIndex(int64(len(edges)*2), 0.75)
index := tree.NewEdgeIndex(uint64(len(edges)*2), 0.75)
for i, e := range edges {
index.PutEdgeValue(e, i, e.Length())
}
Expand Down
2 changes: 2 additions & 0 deletions tests/consensus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func TestMajorityConsensus(t *testing.T) {
if err != nil {
t.Error(err)
}
expected_majority.ReinitIndexes()
edgeindex2 := tree.NewEdgeIndex(128, .75)
for _, e := range expected_majority.Edges() {
edgeindex2.PutEdgeValue(e, 1, e.Length())
Expand Down Expand Up @@ -102,6 +103,7 @@ func TestStrictConsensus(t *testing.T) {
if err != nil {
t.Error(err)
}
expected_strict.ReinitIndexes()
edgeindex2 := tree.NewEdgeIndex(128, .75)
for _, e := range expected_strict.Edges() {
edgeindex2.PutEdgeValue(e, 1, e.Length())
Expand Down
3 changes: 2 additions & 1 deletion tests/edgeindex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestEdgeIndex(t *testing.T) {
}
edges := tr.Edges()
edgeindex := tree.NewEdgeIndex(128, .75)

tr.ReinitIndexes()
for i := 1; i <= 10000; i++ {
for _, e := range edges {
edgeindex.AddEdgeCount(e)
Expand Down Expand Up @@ -52,6 +52,7 @@ func TestEdgeIndex2(t *testing.T) {
nbtrees := 1
numLoops := 10
for tr := range trees {
tr.Tree.ReinitIndexes()
edges := tr.Tree.Edges()
for i := 1; i <= numLoops; i++ {
for _, e := range edges {
Expand Down
2 changes: 1 addition & 1 deletion tests/reroot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func TestRootOutgroup(t *testing.T) {
t.Error(err)
}
edges := tr.Edges()
index := tree.NewEdgeIndex(int64(len(edges)*2), 0.75)
index := tree.NewEdgeIndex(uint64(len(edges)*2), 0.75)
for i, e := range edges {
index.PutEdgeValue(e, i, e.Length())
}
Expand Down
11 changes: 8 additions & 3 deletions tests/tree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ func TestCollapseDepth(t *testing.T) {
if err != nil {
t.Error(err)
}
tr.ReinitIndexes()
if err = tr.CollapseTopoDepth(2, 3); err != nil {
t.Error(err)
}
Expand Down Expand Up @@ -165,14 +166,18 @@ func TestMerge(t *testing.T) {
t.Error(err3)
}

tr.ReinitIndexes()
tr2.ReinitIndexes()
tr3.ReinitIndexes()

compchan := make(chan tree.Trees)
err4 := tr.Merge(tr2)
if err4 != nil {
t.Error(err4)
}

stats, err := tree.Compare(tr, compchan, false, true, 1)
compchan <- tree.Trees{tr3, 0, nil}
compchan <- tree.Trees{Tree: tr3, Id: 0, Err: nil}
st := <-stats
if st.Err != nil {
t.Error(st.Err)
Expand Down Expand Up @@ -340,7 +345,7 @@ func TestRotateRandom(t *testing.T) {
t.Error(err)
}
edges := tr.Edges()
index := tree.NewEdgeIndex(int64(len(edges)*2), 0.75)
index := tree.NewEdgeIndex(uint64(len(edges)*2), 0.75)
for i, e := range edges {
index.PutEdgeValue(e, i, e.Length())
}
Expand Down Expand Up @@ -371,7 +376,7 @@ func TestRotateSort(t *testing.T) {
t.Error(err)
}
edges := tr.Edges()
index := tree.NewEdgeIndex(int64(len(edges)*2), 0.75)
index := tree.NewEdgeIndex(uint64(len(edges)*2), 0.75)
for i, e := range edges {
index.PutEdgeValue(e, i, e.Length())
}
Expand Down

0 comments on commit ab308fe

Please sign in to comment.