How to quickly operate more than 3 million lengths of go map?

//[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.

May.23,2021

if you don't consider using a better algorithm, it's easier to read key into an in-memory array, then traverse to find all the strings in bit 4 that contain 4, and then find value, in map.


splits the array and accesses it concurrently.
< del > add: if the generated array is in a certain order (I see the order in your example), then you can learn from the idea of binary search to locate and reduce unnecessary queries. < / del > forget it


you can think in the direction of "optimizing the data structure first" and then "finding".

in real scenarios, 300w items of data can be considered to be introduced into the database

  • Can golang map value be a function?

    ConditionCheck: = map [string] interface {} { "_checkIP": func test {} {} } I can t write this correctly. Please tell me how to define functions in value. Thank you . ...

    Dec.21,2021
Menu