mirror of
https://github.com/luxfi/consensus.git
synced 2026-09-24 00:26:58 +00:00
- Implement chain, DAG, and post-quantum consensus engines with full test coverage - Create IntegratedEngine in node package combining all three engines - Add production-ready cmd tools (params, checker, sim, zmq-bench) - Implement Acceptor interface for node consensus integration - Add WithBlockTime method to config Parameters - Ensure all tests pass across consensus and node packages - Remove stub implementations and add proper production code - Fix config validation with detailed error messages - Clean up duplicate files and unused code
38 lines
792 B
Go
38 lines
792 B
Go
package utils
|
|
|
|
import (
|
|
"sort"
|
|
)
|
|
|
|
// Sort sorts a slice
|
|
func Sort[T any](slice []T, less func(i, j int) bool) {
|
|
sort.Slice(slice, less)
|
|
}
|
|
|
|
// SortByID sorts by ID
|
|
func SortByID[T interface{ ID() string }](slice []T) {
|
|
sort.Slice(slice, func(i, j int) bool {
|
|
return slice[i].ID() < slice[j].ID()
|
|
})
|
|
}
|
|
|
|
// Contains checks if slice contains element
|
|
func Contains[T comparable](slice []T, elem T) bool {
|
|
for _, v := range slice {
|
|
if v == elem {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
// Filter filters a slice
|
|
func Filter[T any](slice []T, predicate func(T) bool) []T {
|
|
result := make([]T, 0, len(slice))
|
|
for _, v := range slice {
|
|
if predicate(v) {
|
|
result = append(result, v)
|
|
}
|
|
}
|
|
return result
|
|
} |