//[1 2 3][123 132 213 231 312 321]
func outOrder(trainsNums []string) []string {
COUNT := len(trainsNums)
//
if COUNT == 0 || COUNT > 10 {
panic("Illegal argument. trainsNums size must between 1 and 9.")
}
//
if COUNT == 1 {
return []string{trainsNums[0]}
}
//
return insert(outOrder(trainsNums[:COUNT-1]), trainsNums[COUNT-1])
}
func insert(res []string, insertNum string) []string {
//slice
result := make([]string, len(res)*(len(res[0])+1))
index := 0
for _, v := range res {
for i := 0; i < len(v); iPP {
//v
result[index] = v[:i] + insertNum + v[i:]
indexPP
}
//v
result[index] = v + insertNum
indexPP
}
return result
}
func main(){
init := []string{
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"0",
}
arr := outOrder(init)
list = make(map[string]int)
for _,v := range arr {
list[v] = 0
}
}
the length of the array generated by the above code is 3.8 million. Suppose I"m looking for all the strings in the fourth bit of key that contain 4.
key is a string of 10-digit non-repeating strings
currently using the memory engine in the database, it still doesn"t meet my requirements
CREATE TABLE `mem` (
`k1` tinyint(2) NOT NULL,
`k2` tinyint(2) NOT NULL,
`k3` tinyint(2) NOT NULL,
`k4` tinyint(2) NOT NULL,
`k5` tinyint(2) NOT NULL,
`k6` tinyint(2) NOT NULL,
`k7` tinyint(2) NOT NULL,
`k8` tinyint(2) NOT NULL,
`k9` tinyint(2) NOT NULL,
`k10` tinyint(2) NOT NULL,
`t1` tinyint(1) DEFAULT NULL,
`t2` tinyint(1) DEFAULT NULL,
`t3` tinyint(1) DEFAULT NULL,
`t4` tinyint(1) DEFAULT NULL,
`t5` tinyint(1) DEFAULT NULL,
`he` tinyint(2) DEFAULT NULL,
`bonus` float DEFAULT NULL,
PRIMARY KEY (`k1`,`k2`,`k3`,`k4`,`k5`,`k6`,`k7`,`k8`,`k9`,`k10`),
KEY `k1` (`k1`) USING HASH,
KEY `k2` (`k2`) USING HASH,
KEY `k3` (`k3`) USING HASH,
KEY `k4` (`k4`) USING HASH,
KEY `k5` (`k5`) USING HASH,
KEY `k6` (`k6`) USING HASH,
KEY `k7` (`k7`) USING HASH,
KEY `k8` (`k8`) USING HASH,
KEY `k9` (`k9`) USING HASH,
KEY `k10` (`k10`) USING HASH,
KEY `t1` (`t1`) USING HASH,
KEY `t2` (`t2`) USING HASH,
KEY `t3` (`t3`) USING HASH,
KEY `t4` (`t4`) USING HASH,
KEY `t5` (`t5`) USING HASH,
KEY `he` (`he`) USING BTREE
) ENGINE=MEMORY DEFAULT CHARSET=utf8;
demand:
update the numbers of 10 bonus fields of 0-9 digits in K2 field, respectively, + 1 update, respectively. It takes 0.5 seconds for each update, and it takes too long to update multiple fields.