Skip to content

Commit

Permalink
api-change: array: NewSlimArray is renamed to NewU32 to specify the d…
Browse files Browse the repository at this point in the history
…ata type in it
  • Loading branch information
drmingdrmer committed Nov 14, 2020
1 parent d6520d6 commit e8c7488
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion example_slimarray_stat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func ExampleSlimArray_Stat() {

sort.Slice(nums, func(i, j int) bool { return nums[i] < nums[j] })

a := slimarray.NewSlimArray(nums)
a := slimarray.NewU32(nums)

st := a.Stat()
fmt.Printf("\nn=%d rng=[0, %d]:\n\n", n, rng)
Expand Down
2 changes: 1 addition & 1 deletion example_slimarray_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func ExampleSlimArray() {
956, 958, 962, 966, 968, 971, 975, 979, 983, 987, 989, 994, 997, 1000,
}

a := slimarray.NewSlimArray(nums)
a := slimarray.NewU32(nums)

fmt.Println("last elt is:", a.Get(int32(a.Len()-1)))

Expand Down
4 changes: 2 additions & 2 deletions slimarray.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,10 @@ func evalpoly2(poly []float64, x float64) float64 {
return poly[0] + poly[1]*x + poly[2]*x*x
}

// NewSlimArray creates a "SlimArray" array from a slice of uint32.
// NewU32 creates a "SlimArray" array from a slice of uint32.
//
// Since 0.1.1
func NewSlimArray(nums []uint32) *SlimArray {
func NewU32(nums []uint32) *SlimArray {

pa := &SlimArray{
N: int32(len(nums)),
Expand Down
2 changes: 1 addition & 1 deletion slimarray.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion slimarray_bug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func TestSlimArray_bug_start_overflow_2019_06_08(t *testing.T) {

nums := bug70KNums

a := NewSlimArray(nums)
a := NewU32(nums)
for i, n := range nums {
r := a.Get(int32(i))
ta.Equal(n, r, "i=%d", i)
Expand Down
26 changes: 13 additions & 13 deletions slimarray_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func TestSlimArray_New(t *testing.T) {

for _, nums := range cases {

a := NewSlimArray(nums)
a := NewU32(nums)
testGet(ta, a, nums)

// Stat() should work
Expand All @@ -108,7 +108,7 @@ func TestNewSlimArray_eltWidthSmall(t *testing.T) {
nums[i] = uint32(15 * i)
}

a := NewSlimArray(nums)
a := NewU32(nums)
fmt.Println(a.Stat())
ta.True(a.Stat()["bits/elt"] <= 4)

Expand All @@ -118,7 +118,7 @@ func TestNewSlimArray_default(t *testing.T) {

ta := require.New(t)

a := NewSlimArray(testNums)
a := NewU32(testNums)
ta.Equal(int32(len(testNums)), a.N)

fmt.Println(a.Stat())
Expand All @@ -137,7 +137,7 @@ func TestNewSlimArray_big(t *testing.T) {
step := int32(64)
ns := testutil.RandU32Slice(0, n, step)

a := NewSlimArray(ns)
a := NewU32(ns)
st := a.Stat()
fmt.Println(st)

Expand All @@ -157,7 +157,7 @@ func TestNewSlimArray_bigResidual_lowhigh(t *testing.T) {
big, big, big, big,
}

a := NewSlimArray(ns)
a := NewU32(ns)
st := a.Stat()
fmt.Println(st)

Expand All @@ -177,7 +177,7 @@ func TestNewSlimArray_bigResidual_zipzag(t *testing.T) {
0, big, 0, 0,
}

a := NewSlimArray(ns)
a := NewU32(ns)
st := a.Stat()
fmt.Println(st)

Expand All @@ -200,7 +200,7 @@ func TestNewSlimArray_bigResidual_rand(t *testing.T) {
ns = append(ns, s)
}

a := NewSlimArray(ns)
a := NewU32(ns)
st := a.Stat()
fmt.Println(st)

Expand All @@ -221,14 +221,14 @@ func TestNewSlimArray_largenum(t *testing.T) {
}
}

a := NewSlimArray(ns)
a := NewU32(ns)
testGet(ta, a, ns)
}

func TestSlimArray_Get_panic(t *testing.T) {
ta := require.New(t)

a := NewSlimArray(testNums)
a := NewU32(testNums)
ta.Panics(func() {
a.Get(int32(len(testNums) + 64))
})
Expand All @@ -241,7 +241,7 @@ func TestSlimArray_Stat(t *testing.T) {

ta := require.New(t)

a := NewSlimArray(testNums)
a := NewU32(testNums)

st := a.Stat()
want := map[string]int32{
Expand All @@ -261,7 +261,7 @@ func TestSlimArray_Stat(t *testing.T) {
func TestSlimArray_marshalUnmarshal(t *testing.T) {
ta := require.New(t)

a := NewSlimArray(testNums)
a := NewU32(testNums)

bytes, err := proto.Marshal(a)
ta.Nil(err, "want no error but: %+v", err)
Expand Down Expand Up @@ -309,7 +309,7 @@ func BenchmarkSlimArray_Get(b *testing.B) {

s := uint32(0)

a := NewSlimArray(ns)
a := NewU32(ns)
fmt.Println(a.Stat())

b.ResetTimer()
Expand All @@ -332,7 +332,7 @@ func BenchmarkNewSlimArray(b *testing.B) {
b.ResetTimer()
var a *SlimArray
for i := 0; i < b.N; i++ {
a = NewSlimArray(ns)
a = NewU32(ns)
s += a.Get(int32(0))
}

Expand Down

0 comments on commit e8c7488

Please sign in to comment.