Package org.apache.cassandra.io.util
Class PageAware
- java.lang.Object
-
- org.apache.cassandra.io.util.PageAware
-
public final class PageAware extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description static int
PAGE_SIZE
static int
PAGE_SIZE_SHIFT
-
Constructor Summary
Constructors Constructor Description PageAware()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static int
bytesLeftInPage(long dstPos)
Calculate the number of bytes left in this page.static int
numPages(int size)
Calculate the number of pages that fit in the given size, rounded up to a page if the size is not an exact multiple.static void
pad(DataOutputPlus dest)
Pad the given output stream with zeroes until the next page boundary.static long
padded(long dstPos)
Calculate the earliest page boundary for the given position.static long
pageLimit(long dstPos)
Calculate the end of the page identified by the given position.static int
pageNum(long dstPos)
Given a position relative to the start of a number of pages, determine the exact page number this position falls into.static long
pageStart(long dstPos)
Calculate the start of the page that contains the given position.
-
-
-
Field Detail
-
PAGE_SIZE
public static final int PAGE_SIZE
- See Also:
- Constant Field Values
-
PAGE_SIZE_SHIFT
public static final int PAGE_SIZE_SHIFT
-
-
Method Detail
-
pageLimit
public static long pageLimit(long dstPos)
Calculate the end of the page identified by the given position. Equivalent to floor(dstPos / PAGE_SIZE + 1) * PAGE_SIZE.When the argument is equal to the page boundary, returns the next page boundary. E.g. pageLimit(0) == PAGE_SIZE.
-
pageStart
public static long pageStart(long dstPos)
Calculate the start of the page that contains the given position. Equivalent to floor(dstPos / PAGE_SIZE) * PAGE_SIZE.
-
padded
public static long padded(long dstPos)
Calculate the earliest page boundary for the given position. Equivalent to ceil(dstPos / PAGE_SIZE) * PAGE_SIZE.When the argument is equal to a page boundary, returns the argument.
-
bytesLeftInPage
public static int bytesLeftInPage(long dstPos)
Calculate the number of bytes left in this page. Equivalent to pageLimit(position) - position.When the argument is equal to a page boundary, returns PAGE_SIZE.
-
numPages
public static int numPages(int size)
Calculate the number of pages that fit in the given size, rounded up to a page if the size is not an exact multiple.- Parameters:
size
- the size that needs to cover a number of pages- Returns:
- the number of pages, rounded up
-
pageNum
public static int pageNum(long dstPos)
Given a position relative to the start of a number of pages, determine the exact page number this position falls into. For example, positions from 0 toPAGE_SIZE
-1 will fall into page zero and so forth.- Parameters:
dstPos
- the position- Returns:
- the page number, indexed at zero
-
pad
public static void pad(DataOutputPlus dest) throws java.io.IOException
Pad the given output stream with zeroes until the next page boundary. If the destination position is already at a page boundary, do not do anything.- Throws:
java.io.IOException
-
-