From 757fbd50ec30cf4f07995cd687737621ea5eab06 Mon Sep 17 00:00:00 2001 From: wshwsh12 <793703860@qq.com> Date: Wed, 3 Mar 2021 10:32:09 +0800 Subject: [PATCH] move to util/set --- .../set}/set_with_memory_usage.go | 22 ++++++++++--------- .../set}/set_with_memory_usage_test.go | 2 +- 2 files changed, 13 insertions(+), 11 deletions(-) rename {executor/aggfuncs => util/set}/set_with_memory_usage.go (91%) rename {executor/aggfuncs => util/set}/set_with_memory_usage_test.go (99%) diff --git a/executor/aggfuncs/set_with_memory_usage.go b/util/set/set_with_memory_usage.go similarity index 91% rename from executor/aggfuncs/set_with_memory_usage.go rename to util/set/set_with_memory_usage.go index b5687d108418c..9c7039b98acff 100644 --- a/executor/aggfuncs/set_with_memory_usage.go +++ b/util/set/set_with_memory_usage.go @@ -11,11 +11,9 @@ // See the License for the specific language governing permissions and // limitations under the License. -package aggfuncs +package set -import ( - "github.com/pingcap/tidb/util/set" -) +import "unsafe" const ( // DefStringSetBucketMemoryUsage = bucketSize*(1+unsafe.Sizeof(string) + unsafe.Sizeof(struct{}))+2*ptrSize @@ -28,17 +26,21 @@ const ( // Represent as loadFactorNum/loadFactDen, to allow integer math. loadFactorNum = 13 loadFactorDen = 2 + // DefFloat64Size is the size of float64 + DefFloat64Size = int64(unsafe.Sizeof(float64(0))) + // DefInt64Size is the size of int64 + DefInt64Size = int64(unsafe.Sizeof(int64(0))) ) // StringSetWithMemoryUsage is a string set with memory usage. type StringSetWithMemoryUsage struct { - set.StringSet + StringSet bInMap int64 } // NewStringSetWithMemoryUsage builds a string set. func NewStringSetWithMemoryUsage(ss ...string) (setWithMemoryUsage StringSetWithMemoryUsage, memDelta int64) { - set := make(set.StringSet, len(ss)) + set := make(StringSet, len(ss)) setWithMemoryUsage = StringSetWithMemoryUsage{ StringSet: set, bInMap: 0, @@ -62,13 +64,13 @@ func (s *StringSetWithMemoryUsage) Insert(val string) (memDelta int64) { // Float64SetWithMemoryUsage is a float64 set with memory usage. type Float64SetWithMemoryUsage struct { - set.Float64Set + Float64Set bInMap int64 } // NewFloat64SetWithMemoryUsage builds a float64 set. func NewFloat64SetWithMemoryUsage(ss ...float64) (setWithMemoryUsage Float64SetWithMemoryUsage, memDelta int64) { - set := make(set.Float64Set, len(ss)) + set := make(Float64Set, len(ss)) setWithMemoryUsage = Float64SetWithMemoryUsage{ Float64Set: set, bInMap: 0, @@ -92,13 +94,13 @@ func (s *Float64SetWithMemoryUsage) Insert(val float64) (memDelta int64) { // Int64SetWithMemoryUsage is a int set with memory usage. type Int64SetWithMemoryUsage struct { - set.Int64Set + Int64Set bInMap int64 } // NewInt64SetWithMemoryUsage builds a int64 set. func NewInt64SetWithMemoryUsage(ss ...int64) (setWithMemoryUsage Int64SetWithMemoryUsage, memDelta int64) { - set := make(set.Int64Set, len(ss)) + set := make(Int64Set, len(ss)) setWithMemoryUsage = Int64SetWithMemoryUsage{ Int64Set: set, bInMap: 0, diff --git a/executor/aggfuncs/set_with_memory_usage_test.go b/util/set/set_with_memory_usage_test.go similarity index 99% rename from executor/aggfuncs/set_with_memory_usage_test.go rename to util/set/set_with_memory_usage_test.go index fc167be7a5104..ed437f62f4486 100644 --- a/executor/aggfuncs/set_with_memory_usage_test.go +++ b/util/set/set_with_memory_usage_test.go @@ -1,4 +1,4 @@ -package aggfuncs +package set import ( "fmt"