mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-29 22:29:56 +02:00
Create pages from _content.gotmpl
Closes #12427 Closes #12485 Closes #6310 Closes #5074
This commit is contained in:
@@ -15,18 +15,21 @@ package doctree
|
||||
|
||||
var _ Tree[string] = (*TreeShiftTree[string])(nil)
|
||||
|
||||
type TreeShiftTree[T any] struct {
|
||||
type TreeShiftTree[T comparable] struct {
|
||||
// This tree is shiftable in one dimension.
|
||||
d int
|
||||
|
||||
// The value of the current dimension.
|
||||
v int
|
||||
|
||||
// The zero value of T.
|
||||
zero T
|
||||
|
||||
// Will be of length equal to the length of the dimension.
|
||||
trees []*SimpleTree[T]
|
||||
}
|
||||
|
||||
func NewTreeShiftTree[T any](d, length int) *TreeShiftTree[T] {
|
||||
func NewTreeShiftTree[T comparable](d, length int) *TreeShiftTree[T] {
|
||||
if length <= 0 {
|
||||
panic("length must be > 0")
|
||||
}
|
||||
@@ -52,6 +55,17 @@ func (t *TreeShiftTree[T]) Get(s string) T {
|
||||
return t.trees[t.v].Get(s)
|
||||
}
|
||||
|
||||
func (t *TreeShiftTree[T]) DeleteAllFunc(s string, f func(s string, v T) bool) {
|
||||
for _, tt := range t.trees {
|
||||
if v := tt.Get(s); v != t.zero {
|
||||
if f(s, v) {
|
||||
// Delete.
|
||||
tt.tree.Delete(s)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (t *TreeShiftTree[T]) LongestPrefix(s string) (string, T) {
|
||||
return t.trees[t.v].LongestPrefix(s)
|
||||
}
|
||||
@@ -60,10 +74,31 @@ func (t *TreeShiftTree[T]) Insert(s string, v T) T {
|
||||
return t.trees[t.v].Insert(s, v)
|
||||
}
|
||||
|
||||
func (t *TreeShiftTree[T]) Lock(lockType LockType) func() {
|
||||
return t.trees[t.v].Lock(lockType)
|
||||
}
|
||||
|
||||
func (t *TreeShiftTree[T]) WalkPrefix(lockType LockType, s string, f func(s string, v T) (bool, error)) error {
|
||||
return t.trees[t.v].WalkPrefix(lockType, s, f)
|
||||
}
|
||||
|
||||
func (t *TreeShiftTree[T]) WalkPrefixRaw(lockType LockType, s string, f func(s string, v T) (bool, error)) error {
|
||||
for _, tt := range t.trees {
|
||||
if err := tt.WalkPrefix(lockType, s, f); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *TreeShiftTree[T]) LenRaw() int {
|
||||
var count int
|
||||
for _, tt := range t.trees {
|
||||
count += tt.tree.Len()
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
func (t *TreeShiftTree[T]) Delete(key string) {
|
||||
for _, tt := range t.trees {
|
||||
tt.tree.Delete(key)
|
||||
@@ -77,25 +112,3 @@ func (t *TreeShiftTree[T]) DeletePrefix(prefix string) int {
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
func (t *TreeShiftTree[T]) Lock(writable bool) (commit func()) {
|
||||
if writable {
|
||||
for _, tt := range t.trees {
|
||||
tt.mu.Lock()
|
||||
}
|
||||
return func() {
|
||||
for _, tt := range t.trees {
|
||||
tt.mu.Unlock()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for _, tt := range t.trees {
|
||||
tt.mu.RLock()
|
||||
}
|
||||
return func() {
|
||||
for _, tt := range t.trees {
|
||||
tt.mu.RUnlock()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user