Change queues and stacks
- Make chain element private - Remove JSON Marshaller from stack and queue - Remove access to top chain element
This commit is contained in:
parent
9870d87d41
commit
09de0a19e1
3 changed files with 18 additions and 52 deletions
|
@ -1,15 +1,15 @@
|
|||
package containers
|
||||
|
||||
type ChainElem[T any] struct {
|
||||
type chainElem[T any] struct {
|
||||
Elem *T
|
||||
Next *ChainElem[T]
|
||||
Next *chainElem[T]
|
||||
}
|
||||
|
||||
// reachable checks if you can reach elem l when starting from elem f.
|
||||
// It detects loops and returns false if it runs into one.
|
||||
func reachable[T any](f, l *ChainElem[T]) bool {
|
||||
func reachable[T any](f, l *chainElem[T]) bool {
|
||||
// Map to keep track of nodes already visited
|
||||
checks := make(map[*ChainElem[T]]bool)
|
||||
checks := make(map[*chainElem[T]]bool)
|
||||
for w := f; w != l; w = w.Next {
|
||||
if w == nil {
|
||||
return false
|
||||
|
@ -26,8 +26,8 @@ func reachable[T any](f, l *ChainElem[T]) bool {
|
|||
}
|
||||
|
||||
// emptyElem creates a new ChainElem[T] with empty values.
|
||||
func emptyElem[T any]() *ChainElem[T] {
|
||||
return &ChainElem[T]{
|
||||
func emptyElem[T any]() *chainElem[T] {
|
||||
return &chainElem[T]{
|
||||
Elem: nil,
|
||||
Next: nil,
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue