feat(Go-Tool):新增lomute划分算法效率单测,结果:多次查找,元素多的情况下由末尾开始查找效率更高
This commit is contained in:
@@ -52,6 +52,8 @@
|
|||||||
|
|
||||||
2020/10/28: 新增根据二进制位数来存储奖励领取情况工具类,BitStoreTool、使用说明及其单测
|
2020/10/28: 新增根据二进制位数来存储奖励领取情况工具类,BitStoreTool、使用说明及其单测
|
||||||
|
|
||||||
|
2020/11/9: 新增lomute划分算法效率单测,结果:多次查找,元素多的情况下由末尾开始查找效率更高
|
||||||
|
|
||||||
|
|
||||||
# mod vendor模式加载包
|
# mod vendor模式加载包
|
||||||
通过go mod的方式加载的github上面的包会有报红的问题,但是包本身是可以运行的,这样就是会有一个问题,如果你想要点击去看方法的内容,没办法做到
|
通过go mod的方式加载的github上面的包会有报红的问题,但是包本身是可以运行的,这样就是会有一个问题,如果你想要点击去看方法的内容,没办法做到
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ func (bitStore *BitStore) IsGearReceive(gear int) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
position := bitStore.getGearPosition(gear, length)
|
position := bitStore.getGearPosition(gear, length)
|
||||||
return (bitStore.GearPickList[length-1] & (2 << position)) > 0
|
return (bitStore.GearPickList[length-1] & (1 << position)) > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取对应档位奖励
|
//获取对应档位奖励
|
||||||
@@ -59,7 +59,7 @@ func (bitStore *BitStore) ReceiveByGear(gear int) ([]int, map[int]bool) {
|
|||||||
bitStore.checkIfReceive(gear) //校验是否被领取了
|
bitStore.checkIfReceive(gear) //校验是否被领取了
|
||||||
length := bitStore.dynamicGrowth(gear) //数组进行动态增长
|
length := bitStore.dynamicGrowth(gear) //数组进行动态增长
|
||||||
position := bitStore.getGearPosition(gear, length) //获取档位在数组中的位数位置
|
position := bitStore.getGearPosition(gear, length) //获取档位在数组中的位数位置
|
||||||
bitStore.GearPickList[length-1] = bitStore.GearPickList[length-1] + (2 << uint(position))
|
bitStore.GearPickList[length-1] = bitStore.GearPickList[length-1] + (1 << uint(position))
|
||||||
return bitStore.GearPickList, bitStore.FindAllGearMap()
|
return bitStore.GearPickList, bitStore.FindAllGearMap()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,7 +91,7 @@ func (bitStore *BitStore) fullListDeal(listSize int, length int) map[int]bool {
|
|||||||
resultMap := make(map[int]bool, 0)
|
resultMap := make(map[int]bool, 0)
|
||||||
for i := 0; i < length; i++ {
|
for i := 0; i < length; i++ {
|
||||||
for j := 0; j < bit && bitStore.MaxGear > i*bit+j; j++ {
|
for j := 0; j < bit && bitStore.MaxGear > i*bit+j; j++ {
|
||||||
resultMap[i*bit+j+1] = (bitStore.GearPickList[i] & (2 << uint(j))) > 0
|
resultMap[i*bit+j+1] = (bitStore.GearPickList[i] & (1 << uint(j))) > 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return resultMap
|
return resultMap
|
||||||
@@ -101,7 +101,7 @@ func (bitStore *BitStore) shortListDeal(listSize, length int) map[int]bool {
|
|||||||
resultMap := make(map[int]bool, 0)
|
resultMap := make(map[int]bool, 0)
|
||||||
for i := 0; i < listSize; i++ {
|
for i := 0; i < listSize; i++ {
|
||||||
for j := 0; j < bit; j++ {
|
for j := 0; j < bit; j++ {
|
||||||
resultMap[i*bit+j+1] = (bitStore.GearPickList[i] & (2 << uint(j))) > 0
|
resultMap[i*bit+j+1] = (bitStore.GearPickList[i] & (1 << uint(j))) > 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for i := listSize; i < length; i++ {
|
for i := listSize; i < length; i++ {
|
||||||
|
|||||||
@@ -6,6 +6,11 @@
|
|||||||
|
|
||||||
package search
|
package search
|
||||||
|
|
||||||
|
var (
|
||||||
|
times = 0 //用来计算一次划分进行了多少次的比较操作
|
||||||
|
charge = 0 //实际进行元素交换的次数
|
||||||
|
)
|
||||||
|
|
||||||
//参数说明:
|
//参数说明:
|
||||||
//list :数组
|
//list :数组
|
||||||
//start : 开始比较的数字下标
|
//start : 开始比较的数字下标
|
||||||
@@ -17,19 +22,25 @@ func LomutoPartition(list []int, start int, end int) int {
|
|||||||
for i := start + 1; i <= end; i++ {
|
for i := start + 1; i <= end; i++ {
|
||||||
if list[i] < compareValue {
|
if list[i] < compareValue {
|
||||||
moveSubscript++
|
moveSubscript++
|
||||||
|
charge++
|
||||||
list[moveSubscript], list[i] = list[i], list[moveSubscript]
|
list[moveSubscript], list[i] = list[i], list[moveSubscript]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
charge++
|
||||||
list[moveSubscript], list[start] = list[start], list[moveSubscript] //交换元素
|
list[moveSubscript], list[start] = list[start], list[moveSubscript] //交换元素
|
||||||
return moveSubscript
|
return moveSubscript
|
||||||
}
|
}
|
||||||
|
|
||||||
func LomutoQuiteSelect(list []int, pointPosition int) int {
|
func LomutoQuiteSelect(list []int, pointPosition int) (int, int, int) {
|
||||||
positionCheck(pointPosition, len(list)) //下标校验
|
positionCheck(pointPosition, len(list)) //下标校验
|
||||||
|
times = 0
|
||||||
|
charge = 0
|
||||||
|
|
||||||
nowPosition := LomutoPartition(list, 0, len(list)-1)
|
nowPosition := LomutoPartition(list, 0, len(list)-1)
|
||||||
|
times++
|
||||||
//循环进行lomuto划分处理,知道找到我们需要的那个位置的元素
|
//循环进行lomuto划分处理,知道找到我们需要的那个位置的元素
|
||||||
for nowPosition != pointPosition-1 {
|
for nowPosition != pointPosition-1 {
|
||||||
|
times++
|
||||||
if nowPosition > pointPosition-1 {
|
if nowPosition > pointPosition-1 {
|
||||||
nowPosition = LomutoPartition(list, 0, nowPosition)
|
nowPosition = LomutoPartition(list, 0, nowPosition)
|
||||||
} else {
|
} else {
|
||||||
@@ -37,7 +48,7 @@ func LomutoQuiteSelect(list []int, pointPosition int) int {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return list[nowPosition]
|
return list[nowPosition], times, charge
|
||||||
}
|
}
|
||||||
|
|
||||||
func positionCheck(pointPosition int, len int) {
|
func positionCheck(pointPosition int, len int) {
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user