> For the complete documentation index, see [llms.txt](https://xogk39.gitbook.io/htaeha/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://xogk39.gitbook.io/htaeha/go_lang/useful-data-structure.md).

# Useful data structure

## Set

Go lang에는 set이 없지만 비슷하게 만들어 사용할 수 있다.&#x20;

```go
func setAdd(s map[int]bool, v int) map[int]bool {
	s[v] = true
	return s
}

func main() {
	s := make(map[int]bool)
	s = setAdd(s, 1)
	s = setAdd(s, 2)
	s = setAdd(s, 3)
	s = setAdd(s, 2)
	fmt.Println(s)
	delete(s, 3)
	fmt.Println(s)
}
```

```go
map[1:true 2:true 3:true]
map[1:true 2:true]
```

## Slice of map

```go
// 길이 3짜리 slice 안에 map[int]bool 이 존재.
m := make([]map[int]bool, 3, 3)
// map을 초기화해줘야 사용할 수 있다. 
for i := range m{
    m = map[int]bool{}
}
```
