Compare commits
No commits in common. "65a0ca94f64b93d10bc476ab52cc205bd800d718" and "dfe7bb31818d5833bafdfcf4308ec4870a5b869e" have entirely different histories.
65a0ca94f6
...
dfe7bb3181
@ -70,11 +70,15 @@ func PostPlugin(calls ...PostsPlugin) PostsPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func UsePostsPlugins() PostsPlugin {
|
func UsePostsPlugins() PostsPlugin {
|
||||||
|
p := config.GetConfig().ListPagePlugins
|
||||||
|
var pluginss []func(PostsPlugin, *Handle, *models.Posts)
|
||||||
m := pluginFns.Load()
|
m := pluginFns.Load()
|
||||||
pluginss := slice.FilterAndMap(config.GetConfig().ListPagePlugins, func(t string) (func(PostsPlugin, *Handle, *models.Posts), bool) {
|
for _, s := range p {
|
||||||
f, ok := m[t]
|
f, ok := m[s]
|
||||||
return f, ok
|
if ok {
|
||||||
})
|
pluginss = append(pluginss, f)
|
||||||
|
}
|
||||||
|
}
|
||||||
slice.Unshift(&pluginss, PasswordProject)
|
slice.Unshift(&pluginss, PasswordProject)
|
||||||
return PostsPlugins(PostPlugin(ordinaryPlugin.Load()...), pluginss...)
|
return PostsPlugins(PostPlugin(ordinaryPlugin.Load()...), pluginss...)
|
||||||
}
|
}
|
||||||
|
@ -34,14 +34,7 @@ func Sort[T any](arr []T, fn func(i, j T) bool) {
|
|||||||
fn: fn,
|
fn: fn,
|
||||||
}
|
}
|
||||||
sort.Sort(slice)
|
sort.Sort(slice)
|
||||||
}
|
return
|
||||||
|
|
||||||
func StableSort[T any](arr []T, fn func(i, j T) bool) {
|
|
||||||
slice := anyArr[T]{
|
|
||||||
data: arr,
|
|
||||||
fn: fn,
|
|
||||||
}
|
|
||||||
sort.Stable(slice)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func Sorts[T constraints.Ordered](a []T, order int) {
|
func Sorts[T constraints.Ordered](a []T, order int) {
|
||||||
|
@ -102,64 +102,3 @@ func TestSorts(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStableSort(t *testing.T) {
|
|
||||||
type xy struct {
|
|
||||||
x int
|
|
||||||
y int
|
|
||||||
}
|
|
||||||
type args[T any] struct {
|
|
||||||
arr []T
|
|
||||||
fn func(i, j T) bool
|
|
||||||
}
|
|
||||||
type testCase[T any] struct {
|
|
||||||
name string
|
|
||||||
args args[T]
|
|
||||||
wantR []T
|
|
||||||
}
|
|
||||||
tests := []testCase[xy]{
|
|
||||||
{
|
|
||||||
name: "t1",
|
|
||||||
args: args[xy]{
|
|
||||||
arr: []xy{
|
|
||||||
{1, 2},
|
|
||||||
{3, 4},
|
|
||||||
{1, 3},
|
|
||||||
{2, 1},
|
|
||||||
{1, 6},
|
|
||||||
},
|
|
||||||
fn: func(i, j xy) bool {
|
|
||||||
if i.x < j.x {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
if i.x == j.x && i.y > i.y {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
},
|
|
||||||
},
|
|
||||||
wantR: []xy{
|
|
||||||
{1, 2},
|
|
||||||
{1, 3},
|
|
||||||
{1, 6},
|
|
||||||
{2, 1},
|
|
||||||
{3, 4},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "t1",
|
|
||||||
args: args[xy]{
|
|
||||||
arr: []xy{{1, 2}, {1, 3}, {1, 6}},
|
|
||||||
fn: func(i, j xy) bool {
|
|
||||||
return i.x > j.x
|
|
||||||
},
|
|
||||||
},
|
|
||||||
wantR: []xy{{1, 2}, {1, 3}, {1, 6}},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
for _, tt := range tests {
|
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
|
||||||
StableSort(tt.args.arr, tt.args.fn)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user