mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-08-28 10:54:59 +00:00
Remove duplicate instances of test utilities from pilosa.ctl. Now subpackages such as pilosa.ctl may import test utilities.
40 lines
963 B
Go
40 lines
963 B
Go
package test
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/pilosa/pilosa"
|
|
)
|
|
|
|
// NewCluster returns a cluster with n nodes and uses a mod-based hasher.
|
|
func NewCluster(n int) *pilosa.Cluster {
|
|
c := pilosa.NewCluster()
|
|
c.ReplicaN = 1
|
|
c.Hasher = NewModHasher()
|
|
|
|
for i := 0; i < n; i++ {
|
|
c.Nodes = append(c.Nodes, &pilosa.Node{
|
|
Host: fmt.Sprintf("host%d", i),
|
|
})
|
|
}
|
|
|
|
return c
|
|
}
|
|
|
|
// ModHasher represents a simple, mod-based hashing.
|
|
type ModHasher struct{}
|
|
|
|
// NewModHasher returns a new instance of ModHasher with n buckets.
|
|
func NewModHasher() *ModHasher { return &ModHasher{} }
|
|
|
|
func (*ModHasher) Hash(key uint64, n int) int { return int(key) % n }
|
|
|
|
// ConstHasher represents hash that always returns the same index.
|
|
type ConstHasher struct {
|
|
i int
|
|
}
|
|
|
|
// NewConstHasher returns a new instance of ConstHasher that always returns i.
|
|
func NewConstHasher(i int) *ConstHasher { return &ConstHasher{i: i} }
|
|
|
|
func (h *ConstHasher) Hash(key uint64, n int) int { return h.i }
|