Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
cristaloleg committed Oct 2, 2023
1 parent 2edc87a commit 25fc0e4
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 83 deletions.
11 changes: 0 additions & 11 deletions internal/generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,6 @@ func WithLogSizeRange(min, max int) Option {
}
}

// WithSize returns an Option that will add given pooling size to the pool.
func WithSize(n int) Option {
return func(c Config) {
c.AddSize(n)
}
}

func WithSizeMapping(sz func(int) int) Option {
return func(c Config) {
c.SetSizeMapping(sz)
Expand All @@ -121,7 +114,3 @@ func WithSizeMapping(sz func(int) int) Option {
func WithLogSizeMapping() Option {
return WithSizeMapping(pmath.CeilToPowerOfTwo)
}

func WithIdentitySizeMapping() Option {
return WithSizeMapping(pmath.Identity)
}
16 changes: 8 additions & 8 deletions internal/pbufio/pbufio.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ func NewWriterPool(min, max int) *WriterPool {
return &WriterPool{pool.New(min, max)}
}

// CustomWriterPool creates new WriterPool with given options.
func CustomWriterPool(opts ...pool.Option) *WriterPool {
return &WriterPool{pool.Custom(opts...)}
}
// // CustomWriterPool creates new WriterPool with given options.
// func CustomWriterPool(opts ...pool.Option) *WriterPool {
// return &WriterPool{pool.Custom(opts...)}
// }

// Get returns bufio.Writer whose buffer has at least size bytes.
func (wp *WriterPool) Get(w io.Writer, size int) *bufio.Writer {
Expand Down Expand Up @@ -81,10 +81,10 @@ func NewReaderPool(min, max int) *ReaderPool {
return &ReaderPool{pool.New(min, max)}
}

// CustomReaderPool creates new ReaderPool with given options.
func CustomReaderPool(opts ...pool.Option) *ReaderPool {
return &ReaderPool{pool.Custom(opts...)}
}
// // CustomReaderPool creates new ReaderPool with given options.
// func CustomReaderPool(opts ...pool.Option) *ReaderPool {
// return &ReaderPool{pool.Custom(opts...)}
// }

// Get returns bufio.Reader whose buffer has at least size bytes.
func (rp *ReaderPool) Get(r io.Reader, size int) *bufio.Reader {
Expand Down
4 changes: 2 additions & 2 deletions internal/pbytes/pbytes.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ var DefaultPool = New(128, 65536)
// Get returns probably reused slice of bytes with at least capacity of c and
// exactly len of n.
// Get is a wrapper around DefaultPool.Get().
func Get(n, c int) []byte { return DefaultPool.Get(n, c) }
// func Get(n, c int) []byte { return DefaultPool.Get(n, c) }

// GetCap returns probably reused slice of bytes with at least capacity of n.
// GetCap is a wrapper around DefaultPool.GetCap().
func GetCap(c int) []byte { return DefaultPool.GetCap(c) }
// func GetCap(c int) []byte { return DefaultPool.GetCap(c) }

// GetLen returns probably reused slice of bytes with at least capacity of n
// and exactly len of n.
Expand Down
16 changes: 8 additions & 8 deletions internal/pbytes/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ func New(min, max int) *Pool {
return &Pool{pool.New(min, max)}
}

// New creates new Pool with given options.
func Custom(opts ...pool.Option) *Pool {
return &Pool{pool.Custom(opts...)}
}
// // New creates new Pool with given options.
// func Custom(opts ...pool.Option) *Pool {
// return &Pool{pool.Custom(opts...)}
// }

// Get returns probably reused slice of bytes with at least capacity of c and
// exactly len of n.
Expand All @@ -48,10 +48,10 @@ func (p *Pool) Put(bts []byte) {
p.pool.Put(bts, cap(bts))
}

// GetCap returns probably reused slice of bytes with at least capacity of n.
func (p *Pool) GetCap(c int) []byte {
return p.Get(0, c)
}
// // GetCap returns probably reused slice of bytes with at least capacity of n.
// func (p *Pool) GetCap(c int) []byte {
// return p.Get(0, c)
// }

// GetLen returns probably reused slice of bytes with at least capacity of n
// and exactly len of n.
Expand Down
30 changes: 15 additions & 15 deletions internal/pmath/pmath.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ func LogarithmicRange(min, max int, cb func(int)) {
}
}

// IsPowerOfTwo reports whether given integer is a power of two.
func IsPowerOfTwo(n int) bool {
return n&(n-1) == 0
}
// // IsPowerOfTwo reports whether given integer is a power of two.
// func IsPowerOfTwo(n int) bool {
// return n&(n-1) == 0
// }

// Identity is identity.
func Identity(n int) int {
Expand All @@ -42,17 +42,17 @@ func CeilToPowerOfTwo(n int) int {
return n
}

// FloorToPowerOfTwo returns the greatest power of two integer value less than
// or equal to n.
func FloorToPowerOfTwo(n int) int {
if n <= 2 {
return n
}
n = fillBits(n)
n >>= 1
n++
return n
}
// // FloorToPowerOfTwo returns the greatest power of two integer value less than
// // or equal to n.
// func FloorToPowerOfTwo(n int) int {
// if n <= 2 {
// return n
// }
// n = fillBits(n)
// n >>= 1
// n++
// return n
// }

func fillBits(n int) int {
n |= n >> 1
Expand Down
78 changes: 39 additions & 39 deletions internal/pmath/pmath_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,46 +64,46 @@ func TestCeilToPowerOfTwo(t *testing.T) {
}
}

func TestFloorToPowerOfTwo(t *testing.T) {
for _, test := range []struct {
in int
exp int
}{
{0, 0},
{1, 1},
{2, 2},
{3, 2},
{4, 4},
{9, 8},
{maxint, maxintHeadBit},
} {
t.Run(fmt.Sprintf("%d to %d", test.in, test.exp), func(t *testing.T) {
act := FloorToPowerOfTwo(test.in)
if exp := test.exp; act != exp {
t.Errorf("FloorToPowerOfTwo(%d) = %d; want %d", test.in, act, exp)
}
})
}
}
// func TestFloorToPowerOfTwo(t *testing.T) {
// for _, test := range []struct {
// in int
// exp int
// }{
// {0, 0},
// {1, 1},
// {2, 2},
// {3, 2},
// {4, 4},
// {9, 8},
// {maxint, maxintHeadBit},
// } {
// t.Run(fmt.Sprintf("%d to %d", test.in, test.exp), func(t *testing.T) {
// act := FloorToPowerOfTwo(test.in)
// if exp := test.exp; act != exp {
// t.Errorf("FloorToPowerOfTwo(%d) = %d; want %d", test.in, act, exp)
// }
// })
// }
// }

func TestIsPowerOfTwo(t *testing.T) {
for _, test := range []struct {
in int
exp bool
}{
{0, true},
{1, true},
{3, false},
{maxint, false},
{maxintHeadBit, true},
} {
t.Run(fmt.Sprintf("%d->%t", test.in, test.exp), func(t *testing.T) {
if act, exp := IsPowerOfTwo(test.in), test.exp; act != exp {
t.Errorf("IsPowerOfTwo(%d) = %t; want %t", test.in, act, exp)
}
})
}
}
// func TestIsPowerOfTwo(t *testing.T) {
// for _, test := range []struct {
// in int
// exp bool
// }{
// {0, true},
// {1, true},
// {3, false},
// {maxint, false},
// {maxintHeadBit, true},
// } {
// t.Run(fmt.Sprintf("%d->%t", test.in, test.exp), func(t *testing.T) {
// if act, exp := IsPowerOfTwo(test.in), test.exp; act != exp {
// t.Errorf("IsPowerOfTwo(%d) = %t; want %t", test.in, act, exp)
// }
// })
// }
// }

func TestFillBits(t *testing.T) {
for _, test := range []struct {
Expand Down

0 comments on commit 25fc0e4

Please sign in to comment.