This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func TestTSetInt(t *testing.T) { | |
| set := NewTSet[int]() | |
| set.Add(100) | |
| set.Add(200) | |
| set.Add(300) | |
| set.Add(400) | |
| if !set.Has(400) { | |
| t.Error("set doesn't have 400") | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func TestTSet(t *testing.T) { | |
| set := NewTSet[string]() | |
| set.Add("the") | |
| set.Add("quick") | |
| set.Add("brown") | |
| set.Add("fox") | |
| set.Add("the") | |
| if !set.Has("quick") { | |
| t.Error("set doesn't have quick") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| type TSet[K comparable, V int] struct { | |
| items map[K]V | |
| } | |
| func NewTSet[K comparable, V int]() TSet[K, V] { | |
| return TSet[K, V]{items: make(map[K]V)} | |
| } | |
| func (s *TSet[K, V]) Add(item K) { | |
| s.items[item] = 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func TestSet(t *testing.T) { | |
| set := NewSet() | |
| set.Add("the") | |
| set.Add("quick") | |
| set.Add("brown") | |
| set.Add("fox") | |
| set.Add("the") | |
| if !set.Has("quick") { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| type StringSet struct { | |
| items map[string]int | |
| } | |
| func NewSet() StringSet { | |
| return StringSet{items: make(map[string]int)} | |
| } | |
| func (s *StringSet) Add(item string) { | |
| s.items[item] = 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func TestTStackInt(t *testing.T) { | |
| stack := &TStack[int]{} | |
| stack.Push(100) | |
| stack.Push(200) | |
| stack.Push(300) | |
| stack.Push(400) | |
| if stack.Peek() != 400 { | |
| t.Error(stack.Peek()) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func TestTStack(t *testing.T) { | |
| stack := &TStack[string]{} | |
| stack.Push("the") | |
| stack.Push("quick") | |
| stack.Push("brown") | |
| stack.Push("fox") | |
| if stack.Peek() != "fox" { | |
| t.Error(stack.Peek()) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| type TStack[T constraints.Ordered] struct { | |
| items []T | |
| } | |
| func (s *TStack[T]) Push(item T) { | |
| s.items = append(s.items, item) | |
| } | |
| func (s *TStack[T]) Pop() (item T) { | |
| if !s.IsEmpty() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func TestStringStack(t *testing.T) { | |
| stack := &StringStack{} | |
| stack.Push("the") | |
| stack.Push("quick") | |
| stack.Push("brown") | |
| stack.Push("fox") | |
| if stack.Peek() != "fox" { | |
| t.Error(stack.Peek()) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| type StringStack struct { | |
| items []string | |
| } | |
| func (s *StringStack) Push(item string) { | |
| s.items = append(s.items, item) | |
| } | |
| func (s *StringStack) Pop() (item string) { | |
| if !s.IsEmpty() { |