-
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.
add alternative reduction execution order
- Loading branch information
Showing
8 changed files
with
178 additions
and
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package collection | ||
|
||
func FilterSlice[T any](slice []T, predicate func(it T) bool) []T { | ||
var result []T | ||
for _, v := range slice { | ||
if predicate(v) { | ||
result = append(result, v) | ||
} | ||
} | ||
return result | ||
} |
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 |
---|---|---|
@@ -1,9 +1,21 @@ | ||
package candidate | ||
|
||
import "slices" | ||
import ( | ||
"github.com/mandoway/seru/collection" | ||
"slices" | ||
) | ||
|
||
func MinCandidate(candidates []CandidateWithSize) CandidateWithSize { | ||
return slices.MinFunc(candidates, func(a, b CandidateWithSize) int { | ||
return b.Size - a.Size | ||
}) | ||
} | ||
|
||
func MinCandidateP(candidates []*CandidateWithSize) *CandidateWithSize { | ||
nonNilCandidates := collection.FilterSlice(candidates, func(it *CandidateWithSize) bool { | ||
return it != nil | ||
}) | ||
return slices.MinFunc(nonNilCandidates, func(a, b *CandidateWithSize) int { | ||
return b.Size - a.Size | ||
}) | ||
} |
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,23 @@ | ||
package context | ||
|
||
type SemanticApplicationMethod string | ||
|
||
const ( | ||
ApplyFirstOnly SemanticApplicationMethod = "ApplyFirstOnly" | ||
ApplyAllCombined SemanticApplicationMethod = "ApplyAllCombined" | ||
) | ||
|
||
type AlgorithmContext struct { | ||
applicationMethod SemanticApplicationMethod | ||
} | ||
|
||
func NewAlgorithmContext(useIsolation bool) *AlgorithmContext { | ||
var application SemanticApplicationMethod | ||
if useIsolation { | ||
application = ApplyFirstOnly | ||
} else { | ||
application = ApplyAllCombined | ||
} | ||
|
||
return &AlgorithmContext{applicationMethod: application} | ||
} |
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