start work rewriting timeline cache type

This commit is contained in:
kim 2024-12-30 17:12:55 +00:00
commit f4b4a696f2
23 changed files with 1792 additions and 861 deletions

View file

@ -64,10 +64,11 @@ func (p *Page) GetOrder() Order {
if p == nil {
return 0
}
return p.order()
return p.Order()
}
func (p *Page) order() Order {
// Order is a small helper function to return page sort ordering.
func (p *Page) Order() Order {
switch {
case p.Min.Order != 0:
return p.Min.Order
@ -78,6 +79,27 @@ func (p *Page) order() Order {
}
}
// GetBounds is a small helper function to return low and high page bound ptrs (checking for nil page).
func (p *Page) GetBounds() (lo *Boundary, hi *Boundary) {
if p == nil {
return nil, nil
}
return p.Bounds()
}
// Bounds is a smaller helper function to return low and high page bound ptrs.
func (p *Page) Bounds() (lo *Boundary, hi *Boundary) {
switch p.Order() {
case OrderAscending:
lo = &p.Max
hi = &p.Min
case OrderDescending:
lo = &p.Min
hi = &p.Max
}
return
}
// Page will page the given slice of input according
// to the receiving Page's minimum, maximum and limit.
// NOTE: input slice MUST be sorted according to the order is
@ -90,7 +112,7 @@ func (p *Page) Page(in []string) []string {
return in
}
if p.order().Ascending() {
if p.Order().Ascending() {
// Sort type is ascending, input
// data is assumed to be ascending.
@ -150,7 +172,7 @@ func Page_PageFunc[WithID any](p *Page, in []WithID, get func(WithID) string) []
return in
}
if p.order().Ascending() {
if p.Order().Ascending() {
// Sort type is ascending, input
// data is assumed to be ascending.