Compare commits

..

No commits in common. "65a0ca94f64b93d10bc476ab52cc205bd800d718" and "dfe7bb31818d5833bafdfcf4308ec4870a5b869e" have entirely different histories.

3 changed files with 9 additions and 73 deletions

View File

@ -70,11 +70,15 @@ func PostPlugin(calls ...PostsPlugin) PostsPlugin {
}
func UsePostsPlugins() PostsPlugin {
p := config.GetConfig().ListPagePlugins
var pluginss []func(PostsPlugin, *Handle, *models.Posts)
m := pluginFns.Load()
pluginss := slice.FilterAndMap(config.GetConfig().ListPagePlugins, func(t string) (func(PostsPlugin, *Handle, *models.Posts), bool) {
f, ok := m[t]
return f, ok
})
for _, s := range p {
f, ok := m[s]
if ok {
pluginss = append(pluginss, f)
}
}
slice.Unshift(&pluginss, PasswordProject)
return PostsPlugins(PostPlugin(ordinaryPlugin.Load()...), pluginss...)
}

View File

@ -34,14 +34,7 @@ func Sort[T any](arr []T, fn func(i, j T) bool) {
fn: fn,
}
sort.Sort(slice)
}
func StableSort[T any](arr []T, fn func(i, j T) bool) {
slice := anyArr[T]{
data: arr,
fn: fn,
}
sort.Stable(slice)
return
}
func Sorts[T constraints.Ordered](a []T, order int) {

View File

@ -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)
})
}
}