MCPcopy
hub / github.com/dgraph-io/dgraph / PageRange

Function PageRange

x/x.go:738–767  ·  view source on GitHub ↗

PageRange returns start and end indices given pagination params. Note that n is the size of the input list.

(count, offset, n int)

Source from the content-addressed store, hash-verified

736// PageRange returns start and end indices given pagination params. Note that n
737// is the size of the input list.
738func PageRange(count, offset, n int) (int, int) {
739 if n == 0 {
740 return 0, 0
741 }
742 if count == 0 && offset == 0 {
743 return 0, n
744 }
745 if count < 0 {
746 // Items from the back of the array, like Python arrays. Do a positive mod n.
747 if count*-1 > n {
748 count = -n
749 }
750 return (((n + count) % n) + n) % n, n
751 }
752 start := offset
753 if start < 0 {
754 start = 0
755 }
756 if start > n {
757 return n, n
758 }
759 if count == 0 { // No count specified. Just take the offset parameter.
760 return start, n
761 }
762 end := start + count
763 if end > n {
764 end = n
765 }
766 return start, end
767}
768
769// ValidateAddress checks whether given address can be used with grpc dial function
770func ValidateAddress(addr string) error {

Callers 7

multiSortFunction · 0.92
paginateFunction · 0.92
populateVarMapMethod · 0.92
applyPaginationMethod · 0.92
ProcessQueryMethod · 0.92

Calls

no outgoing calls

Tested by

no test coverage detected