Tag:Slice

  • Slice and array in golang and their differences

    Time:2020-10-22

    There are two kinds of data structures in golang: array and slice. Slice is an implementation based on array. Slice is a dynamically variable length data structure. In essence, it is a reference to array word sequence and provides lightweight access to array. So today we will give you a detailed introduction to slice and […]

  • Using slice + index map instead of map to improve performance in golang

    Time:2020-7-9

    cause In our multiple online game projects, many modules and services store a large amount of (CACHE) data in memory to get the fastest access speed in order to improve the response speed. Usually, for convenience, go’s own map is used as the storage container. When there are more than several hundred thousand key values, […]

  • In depth understanding of basic type sorting and slice sorting of golang

    Time:2020-5-10

    Preface In fact, there are some differences between gorang’s sorting ideas and C and C + +. By default, C sorts arrays, C + + sorts a sequence, and go is broader. Objects to be sorted can be any object, although in many cases it is a slice (sharding, similar to an array), or an […]

  • An example analysis of the usage of JS array method slice()

    Time:2020-3-20

    The example of this paper describes the usage of slice () in JS array method. To share with you for your reference, as follows: Slice () method Slice (), which creates a new array based on one or more of the current arrays. You can accept one or two parameters, the start and end positions […]

  • Explain the transfer of map type and slice type in go language

    Time:2020-2-21

    Map type Let’s look at the example M1: func main() { m := make(map[int]int) mdMap(m) fmt.Println(m) } func mdMap(m map[int]int) { m[1] = 100 m[2] = 200 } The result is map[2:200 1:100] We will modify M2 as follows: func main() { var m map[int]int mdMap(m) fmt.Println(m) } func mdMap(m map[int]int) { m = make(map[int]int) […]

  • Several solutions of string reverse order implemented by golang

    Time:2020-2-5

    Preface This article mainly introduces the related content about the realization of string inversion in golang, and shares it for your reference and study. I won’t say much about it below. Let’s have a look at the detailed introduction: String inversion is as follows: Hello World –> dlroW olleH Solution 1: length := len(str) array […]

  • Explain the transfer of map type and slice type in go

    Time:2020-1-23

    On the passing of map type and slice type in go Map type Let’s look at the example M1: func main() { m := make(map[int]int) mdMap(m) fmt.Println(m) } func mdMap(m map[int]int) { m[1] = 100 m[2] = 200 } The result is map[2:200 1:100] We will modify M2 as follows: func main() { var m […]

  • On the principle of golang slice

    Time:2020-1-18

    Slice introduction The length of an array cannot be modified again after it has been defined; an array is a value type and each pass will produce a copy. Obviously, this data structure can not fully meet the real needs of developers. When we initially define an array, we don’t know how large it needs […]

  • Addition, deletion and insertion of slices in golang slice operation

    Time:2020-1-17

    This paper introduces the addition, deletion and insertion of slices in the operation of golang slice, and shares the details as follows: 1、 General operation 1. Declare variable, go is automatically initialized to nil, length: 0, address: 0, nil func main(){ var ss []string; fmt.Printf(“length:%v \taddr:%p \tisnil:%v”,len(ss),ss, ss==nil) } — Running… length:0 addr:0x0 isnil:true Success: […]

  • Collection: encapsulate map and slice to improve the development efficiency of golang

    Time:2019-11-3

    The array and map of golang lack the support of many system APIs like PHP, which makes it necessary to write an API for such operations as getting all the keys in the map or disrupting the array. At this time, collection came into being. Collection is a data structure that can be easily transformed […]

  • Go Basic Slice Tutorial

    Time:2019-10-14

    Go Language Slice The Go language slice is an abstraction of arrays. The length of Go array can not be changed, such a set is not suitable in specific scenarios. Go provides a flexible and powerful built-in type slice (“dynamic array”), which is not fixed in length compared with the array, can add elements, and […]

  • Some “pits” encountered when slice is passed as a parameter in Go language

    Time:2019-10-6

    Preface I believe that seeing this topic may be considered a commonplace topic. It has always been possible to understand a variety of situations by grasping a “value transfer”, but recently encountered a deeper “small hole” to share with you. First of all, let’s start with the simplest one. Look at the following code: func […]