forked from okx/xlayer-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix trace, forced batches, decodeTxs overflow, grpc limit 0xPolygonHe…
- Loading branch information
Showing
27 changed files
with
1,745 additions
and
295 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package state | ||
|
||
import ( | ||
"errors" | ||
"sync" | ||
) | ||
|
||
// ErrStackEmpty returned when Pop is called and the stack is empty | ||
var ErrStackEmpty = errors.New("Empty Stack") | ||
|
||
// Stack is a thread safe stack data structure implementation implementing generics | ||
type Stack[T any] struct { | ||
lock sync.Mutex | ||
items []T | ||
} | ||
|
||
// NewStack creates a new stack | ||
func NewStack[T any]() *Stack[T] { | ||
return &Stack[T]{sync.Mutex{}, make([]T, 0)} | ||
} | ||
|
||
// Push adds an item to the stack | ||
func (s *Stack[T]) Push(v T) { | ||
s.lock.Lock() | ||
defer s.lock.Unlock() | ||
|
||
s.items = append(s.items, v) | ||
} | ||
|
||
// Pop removes and returns the last item added to the stack | ||
func (s *Stack[T]) Pop() (T, error) { | ||
s.lock.Lock() | ||
defer s.lock.Unlock() | ||
|
||
size := len(s.items) | ||
if size == 0 { | ||
var r T | ||
return r, ErrStackEmpty | ||
} | ||
|
||
res := s.items[size-1] | ||
s.items = s.items[:size-1] | ||
return res, nil | ||
} |
Oops, something went wrong.