Skip to content

Commit

Permalink
refactory NewBkdTree parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
yuzhichang committed Jul 25, 2017
1 parent 3f4f9ca commit 7c1b9d5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
6 changes: 3 additions & 3 deletions bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import (

func BenchmarkBkdInsert(b *testing.B) {
t0mCap := 1000
numDims := 2
bytesPerDim := 4
leafCap := 50
intraCap := 4
numDims := 2
bytesPerDim := 4
dir := "/tmp"
prefix := "bkd"
bkd, err := NewBkdTree(t0mCap, numDims, bytesPerDim, leafCap, intraCap, dir, prefix)
bkd, err := NewBkdTree(t0mCap, leafCap, intraCap, numDims, bytesPerDim, dir, prefix)
if err != nil {
b.Fatalf("%+v", err)
}
Expand Down
7 changes: 3 additions & 4 deletions bkdtree.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,9 @@ func (n *KdTreeExtIntraNode) Write(w io.Writer) (err error) {
}

//NewBkdTree creates a BKDTree. This is used for construct a BkdTree from scratch. Existing files, if any, will be removed.
func NewBkdTree(t0mCap, numDims, bytesPerDim, leafCap, intraCap int, dir, prefix string) (bkd *BkdTree, err error) {
if t0mCap <= 0 || numDims <= 0 ||
(bytesPerDim != 1 && bytesPerDim != 2 && bytesPerDim != 4 && bytesPerDim != 8) ||
leafCap <= 0 || leafCap >= int(^uint16(0)) || intraCap <= 2 || intraCap >= int(^uint16(0)) {
func NewBkdTree(t0mCap, leafCap, intraCap, numDims, bytesPerDim int, dir, prefix string) (bkd *BkdTree, err error) {
if t0mCap <= 0 || leafCap <= 0 || leafCap >= int(^uint16(0)) || intraCap <= 2 ||
numDims <= 0 || (bytesPerDim != 1 && bytesPerDim != 2 && bytesPerDim != 4 && bytesPerDim != 8) {
err = errors.Errorf("invalid parameter")
return
}
Expand Down
12 changes: 6 additions & 6 deletions bkdtree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ func TestBkdInsert(t *testing.T) {
t0mCap := 1000
treesCap := 5
bkdCap := t0mCap<<uint(treesCap) - 1
numDims := 2
bytesPerDim := 4
leafCap := 50
intraCap := 4
numDims := 2
bytesPerDim := 4
dir := "/tmp"
prefix := "bkd"
bkd, err := NewBkdTree(t0mCap, numDims, bytesPerDim, leafCap, intraCap, dir, prefix)
bkd, err := NewBkdTree(t0mCap, leafCap, intraCap, numDims, bytesPerDim, dir, prefix)
if err != nil {
t.Fatalf("%+v", err)
}
Expand Down Expand Up @@ -110,13 +110,13 @@ func prepareBkdTree(maxVal uint64) (bkd *BkdTree, points []Point, err error) {
t0mCap := 1000
treesCap := 5
bkdCap := t0mCap<<uint(treesCap) - 1
numDims := 2
bytesPerDim := 4
leafCap := 50
intraCap := 4
numDims := 2
bytesPerDim := 4
dir := "/tmp"
prefix := "bkd"
bkd, err = NewBkdTree(t0mCap, numDims, bytesPerDim, leafCap, intraCap, dir, prefix)
bkd, err = NewBkdTree(t0mCap, leafCap, intraCap, numDims, bytesPerDim, dir, prefix)
if err != nil {
return
}
Expand Down

0 comments on commit 7c1b9d5

Please sign in to comment.