diff --git a/util/bitStore/BitStoreTool.go b/util/bitStore/BitStoreTool.go index 238673f..6d20af5 100644 --- a/util/bitStore/BitStoreTool.go +++ b/util/bitStore/BitStoreTool.go @@ -12,7 +12,8 @@ package bitStore import "fmt" const ( - bit = 32 + bit = 32 + realBit = 31 ) type BitStore struct { @@ -72,12 +73,12 @@ func (bitStore *BitStore) checkGearRight(gear int) { //获取当前档位对应的数组长度(这边的length是从1开始的.) func (bitStore *BitStore) getGearListLength(gear int) int { - return (gear + bit) / bit + return ((gear - 1) + (bit - 1)) / (bit - 1) } //获取档位所在的二进制位置 func (bitStore *BitStore) getGearPosition(gear, length int) int { - return (gear - bit*(length-1)) - 1 + return gear - (bit-1)*(length-1) - 1 } func (bitStore *BitStore) getSizeOrInit() int { @@ -90,8 +91,8 @@ func (bitStore *BitStore) getSizeOrInit() int { func (bitStore *BitStore) fullListDeal(listSize int, length int) map[int]bool { resultMap := make(map[int]bool, 0) for i := 0; i < length; i++ { - for j := 0; j < bit && bitStore.MaxGear > i*bit+j; j++ { - resultMap[i*bit+j+1] = (bitStore.GearPickList[i] & (1 << uint(j))) > 0 + for j := 0; j < bit-1 && bitStore.MaxGear > i*(bit-1)+j; j++ { + resultMap[i*(bit-1)+j+1] = (bitStore.GearPickList[i] & (1 << uint(j))) > 0 } } return resultMap @@ -100,13 +101,13 @@ func (bitStore *BitStore) fullListDeal(listSize int, length int) map[int]bool { func (bitStore *BitStore) shortListDeal(listSize, length int) map[int]bool { resultMap := make(map[int]bool, 0) for i := 0; i < listSize; i++ { - for j := 0; j < bit; j++ { - resultMap[i*bit+j+1] = (bitStore.GearPickList[i] & (1 << uint(j))) > 0 + for j := 0; j < (bit - 1); j++ { + resultMap[i*(bit-1)+j+1] = (bitStore.GearPickList[i] & (1 << uint(j))) > 0 } } for i := listSize; i < length; i++ { - for j := 0; j < bit && bitStore.MaxGear > i*bit+j; j++ { - resultMap[i*bit+j+1] = false + for j := 0; j < (bit-1) && bitStore.MaxGear > i*(bit-1)+j; j++ { + resultMap[i*(bit-1)+j+1] = false } } return resultMap diff --git a/util/bitStore/BitStoreTool_test.go b/util/bitStore/BitStoreTool_test.go index 153ad3e..5075976 100644 --- a/util/bitStore/BitStoreTool_test.go +++ b/util/bitStore/BitStoreTool_test.go @@ -47,25 +47,35 @@ func TestOneThousand(t *testing.T) { newStoreMap(bitStore) //初始化的校验 fmt.Println() - bitStore.ReceiveByGear(3) - fmt.Println(fmt.Sprintf("这个时候领取结果 3应该返回true,结果是:%v", bitStore.IsGearReceive(3))) + bitStore.ReceiveByGear(1) + fmt.Println(fmt.Sprintf("%b", bitStore.GearPickList[0])) + fmt.Println(fmt.Sprintf("这个时候领取结果 1应该返回true,结果是:%v", bitStore.IsGearReceive(3))) bitStore.ReceiveByGear(8) + fmt.Println(fmt.Sprintf("%b", bitStore.GearPickList[0])) fmt.Println(fmt.Sprintf("这个时候领取结果 8应该返回true,结果是:%v", bitStore.IsGearReceive(8))) bitStore.ReceiveByGear(16) + fmt.Println(fmt.Sprintf("%b", bitStore.GearPickList[0])) fmt.Println(fmt.Sprintf("这个时候领取结果 16应该返回true,结果是:%v", bitStore.IsGearReceive(16))) bitStore.ReceiveByGear(18) + fmt.Println(fmt.Sprintf("%b", bitStore.GearPickList[0])) fmt.Println(fmt.Sprintf("这个时候领取结果 18应该返回true,结果是:%v", bitStore.IsGearReceive(18))) bitStore.ReceiveByGear(27) + fmt.Println(fmt.Sprintf("%b", bitStore.GearPickList[0])) fmt.Println(fmt.Sprintf("这个时候领取结果 27应该返回true,结果是:%v", bitStore.IsGearReceive(27))) bitStore.ReceiveByGear(32) + fmt.Println(fmt.Sprintf("%b", bitStore.GearPickList[1])) fmt.Println(fmt.Sprintf("这个时候领取结果 32应该返回true,结果是:%v", bitStore.IsGearReceive(32))) bitStore.ReceiveByGear(33) + fmt.Println(fmt.Sprintf("%b", bitStore.GearPickList[1])) fmt.Println(fmt.Sprintf("这个时候领取结果 33应该返回true,结果是:%v", bitStore.IsGearReceive(33))) bitStore.ReceiveByGear(53) + fmt.Println(fmt.Sprintf("%b", bitStore.GearPickList[1])) fmt.Println(fmt.Sprintf("这个时候领取结果 53应该返回true,结果是:%v", bitStore.IsGearReceive(53))) bitStore.ReceiveByGear(44) + fmt.Println(fmt.Sprintf("%b", bitStore.GearPickList[1])) fmt.Println(fmt.Sprintf("这个时候领取结果 44应该返回true,结果是:%v", bitStore.IsGearReceive(44))) bitStore.ReceiveByGear(48) + fmt.Println(fmt.Sprintf("%b", bitStore.GearPickList[1])) fmt.Println(fmt.Sprintf("判断当前数组是否动态增长,当前数组长度为:%d", len(bitStore.GearPickList)))