[#354] api/netmap: Return a slice of parameters directly

`IterateParameters` does a poor job:
- it doesn't encapsulate well, because it returns a pointer,
- it has a clunky interface, compared to range loop.

I have decided to return parameter slice and not `iter.Seq` for 2
reasons:
1. There already is `SetParameters`, so `NetworkConfig` struct is
   expected to be modified.
2. This iterator uses pointers, so even with this interface the slice
   can already be changed.

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
Evgenii Stratonikov 2025-04-05 08:22:49 +03:00 committed by Evgenii Stratonikov
parent 661adf17bb
commit 16fd3bafe0
3 changed files with 38 additions and 53 deletions

View file

@ -577,6 +577,8 @@ type NetworkConfig struct {
}
// NumberOfParameters returns number of network parameters.
//
// Deprecated: use [NetworkConfig.Parameters] instead.
func (x *NetworkConfig) NumberOfParameters() int {
if x != nil {
return len(x.ps)
@ -585,10 +587,20 @@ func (x *NetworkConfig) NumberOfParameters() int {
return 0
}
// Parameters returns an iterator over network parameters.
func (x *NetworkConfig) Parameters() []NetworkParameter {
if x != nil {
return x.ps
}
return nil
}
// IterateParameters iterates over network parameters.
// Breaks iteration on f's true return.
//
// Handler must not be nil.
//
// Deprecated: use [NetworkConfig.Parameters] instead.
func (x *NetworkConfig) IterateParameters(f func(*NetworkParameter) bool) {
if x != nil {
for i := range x.ps {